Esempio n. 1
0
        public static string AdminsIndex(this HtmlBuilder hb, Context context)
        {
            if (!Permissions.CanManageTenant(context: context))
            {
                return(HtmlTemplates.Error(
                           context: context,
                           errorData: new ErrorData(type: Error.Types.HasNotPermission)));
            }
            var ss = new SiteSettings();

            return(hb.Template(
                       context: context,
                       ss: ss,
                       view: null,
                       methodType: Pleasanter.Models.BaseModel.MethodTypes.NotSet,
                       title: Displays.Admin(context: context),
                       verType: Versions.VerTypes.Latest,
                       useNavigationMenu: false,
                       action: () => hb
                       .Nav(css: "cf", action: () => hb
                            .Ul(css: "nav-sites", action: () => hb
                                .Li(css: "nav-site", action: () => hb
                                    .A(
                                        attributes: new HtmlAttributes()
                                        .Href(Locations.Edit(
                                                  context: context,
                                                  controller: "Tenants")),
                                        action: () => hb
                                        .Div(action: () => hb
                                             .Text(Displays.Tenants(context: context)))))
                                .Li(css: "nav-site", action: () => hb
                                    .A(
                                        attributes: new HtmlAttributes()
                                        .Href(Locations.Index(
                                                  context: context,
                                                  controller: "Depts")),
                                        action: () => hb
                                        .Div(action: () => hb
                                             .Text(Displays.Depts(context: context)))
                                        .StackStyles()))
                                .Li(css: "nav-site", action: () => hb
                                    .A(
                                        attributes: new HtmlAttributes()
                                        .Href(Locations.Index(
                                                  context: context,
                                                  controller: "Groups")),
                                        action: () => hb
                                        .Div(action: () => hb
                                             .Text(Displays.Groups(context: context)))
                                        .StackStyles()))
                                .Li(
                                    css: "nav-site", action: () => hb
                                    .A(
                                        attributes: new HtmlAttributes()
                                        .Href(Locations.Index(
                                                  context: context,
                                                  controller: "Users")),
                                        action: () => hb
                                        .Div(action: () => hb
                                             .Text(Displays.Users(context: context)))
                                        .StackStyles()),
                                    _using: Permissions.CanManageUser(context: context))
                                .Li(
                                    css: "nav-site", action: () => hb
                                    .A(
                                        attributes: new HtmlAttributes()
                                        .Href(Locations.Index(
                                                  context: context,
                                                  controller: "Registrations")),
                                        action: () => hb
                                        .Div(action: () => hb
                                             .Text(Displays.Registrations(context: context)))
                                        .StackStyles()),
                                    _using: Parameters.Registration.Enabled)
                                ))
                       .MainCommands(
                           context: context,
                           ss: ss,
                           verType: Versions.VerTypes.Latest))
                   .ToString());
        }
        private static bool Using(
            Context context,
            SiteSettings ss,
            string referenceType,
            long siteId,
            NavigationMenu menu)
        {
            var canManageGroups = context.UserSettings?.AllowGroupAdministration(context: context) == true;
            var canCreateGroups = context.UserSettings?.AllowGroupCreation(context: context) == true;
            var canManageSite   = siteId != 0 && context.CanManageSite(
                ss: ss,
                site: true);
            var canManageDepts         = Permissions.CanManageTenant(context: context);
            var canManageUsers         = Permissions.CanManageUser(context: context);
            var canManageRegistrations = Permissions.CanManageRegistrations(context: context);
            var canManageTenants       = Permissions.CanManageTenant(context: context) ||
                                         context.UserSettings?.EnableManageTenant == true;
            var canManageTrashBox = CanManageTrashBox(
                context: context,
                ss: ss);
            var canUseApi     = context.UserSettings?.AllowApi(context: context) == true;
            var canUnlockSite = ss.LockedTable() &&
                                ss.LockedTableUser.Id == context.UserId;

            switch (menu.MenuId)
            {
            case "NewMenu":
                return(ss.ReferenceType == "Sites" && context.Action == "index"
                        ? context.CanManageSite(ss: ss)
                        : ss.ReferenceType == "Groups"
                            ? canCreateGroups
                            : context.CanCreate(ss: ss) &&
                       ss.ReferenceType != "Wikis" &&
                       context.Action != "trashbox");

            case "ViewModeMenu":
                return(Def.ViewModeDefinitionCollection
                       .Any(o => o.ReferenceType == referenceType));

            case "SettingsMenu":
                return(canManageSite ||
                       canManageDepts ||
                       canManageGroups ||
                       canManageUsers ||
                       canUnlockSite);

            case "SettingsMenu_SiteSettings":
                return(canManageSite);

            case "SettingsMenu_DeptAdmin":
                return(canManageDepts);

            case "SettingsMenu_GroupAdmin":
                return(canManageGroups);

            case "SettingsMenu_UserAdmin":
                return(canManageUsers);

            case "SettingsMenu_Registrations":
                return(canManageRegistrations);

            case "SettingsMenu_TrashBox":
                return(canManageTrashBox);

            case "SettingsMenu_TenantAdmin":
                return(canManageTenants);

            case "SettingsMenu_ImportSitePackage":
                return(Parameters.SitePackage.Import &&
                       canManageSite &&
                       ss.IsSite(context: context) &&
                       ss.ReferenceType == "Sites" ||
                       (context.Controller == "items" &&
                        ss.SiteId == 0 &&
                        context.UserSettings?.AllowCreationAtTopSite(context: context) == true));

            case "SettingsMenu_ExportSitePackage":
                return(Parameters.SitePackage.Export &&
                       canManageSite &&
                       ss.IsSite(context: context));

            case "AccountMenu_ShowStartGuide":
                return(context.UserSettings?.ShowStartGuideAvailable(context: context) == true);

            case "AccountMenu_EditProfile":
                return(Parameters.Service.ShowProfiles);

            case "AccountMenu_ChangePassword":
                return(Parameters.Service.ShowChangePassword);

            case "AccountMenu_ApiSettings":
                return(Parameters.Api.Enabled &&
                       context.ContractSettings.Api != false &&
                       canUseApi);

            case "LockTableMenu_LockTable":
            case "LockTableMenu_ForceUnlockTable":
                return(canManageSite &&
                       ss.AllowLockTable == true);

            case "LockTableMenu_UnlockTable":
                return(ss.AllowLockTable == true);

            case "AccountMenu_Responsive":
                return(context.Mobile);

            default:
                return(true);
            }
        }