Пример #1
0
        private object GetAccessList(Guid uId, bool fullAccess)
        {
            var res = new List <object>
            {
                new
                {
                    pId      = Guid.Empty,
                    pName    = "full",
                    pAccess  = fullAccess,
                    disabled = LdapRights.Contains(uId.ToString()) || uId == SecurityContext.CurrentAccount.ID
                }
            };

            foreach (var p in Products)
            {
                res.Add(new
                {
                    pId      = p.ID,
                    pName    = p.GetSysName(),
                    pAccess  = fullAccess || WebItemSecurity.IsProductAdministrator(p.ID, uId),
                    disabled = LdapRights.Contains(uId.ToString()) || fullAccess
                });
            }

            return(res);
        }
Пример #2
0
        private void RegisterClientScript()
        {
            var isRetina = TenantLogoManager.IsRetina(HttpContext.Current.Request);

            Page.RegisterBodyScripts("~/UserControls/Management/AccessRights/js/accessrights.js")
            .RegisterStyle("~/UserControls/Management/AccessRights/css/accessrights.less");

            var curTenant    = CoreContext.TenantManager.GetCurrentTenant();
            var currentOwner = CoreContext.UserManager.GetUsers(curTenant.OwnerId);

            var admins = WebItemSecurity.GetProductAdministrators(Guid.Empty).ToList();

            admins = admins
                     .GroupBy(admin => admin.ID)
                     .Select(group => group.First())
                     .Where(admin => admin.ID != currentOwner.ID)
                     .SortByUserName();

            InitLdapRights();

            var sb = new StringBuilder();

            sb.AppendFormat("ownerId = \"{0}\";", curTenant.OwnerId);

            sb.AppendFormat("adminList = {0};", JsonConvert.SerializeObject(admins.ConvertAll(u => new
            {
                id           = u.ID,
                smallFotoUrl = u.GetSmallPhotoURL(),
                bigFotoUrl   = isRetina ? u.GetBigPhotoURL() : "",
                displayName  = u.DisplayUserName(),
                title        = u.Title.HtmlEncode(),
                userUrl      = CommonLinkUtility.GetUserProfile(u.ID),
                accessList   = GetAccessList(u.ID, WebItemSecurity.IsProductAdministrator(Guid.Empty, u.ID)),
                ldap         = LdapRights.Contains(u.ID.ToString())
            })));

            sb.AppendFormat("imageHelper = {0};", JsonConvert.SerializeObject(new
            {
                PeopleImgSrc  = WebImageSupplier.GetAbsoluteWebPath("user_12.png"),
                GroupImgSrc   = WebImageSupplier.GetAbsoluteWebPath("group_12.png"),
                TrashImgSrc   = WebImageSupplier.GetAbsoluteWebPath("trash_12.png"),
                TrashImgTitle = Resource.DeleteButton
            }));

            var managementPage = Page as Studio.Management;
            var tenantAccess   = managementPage != null ? managementPage.TenantAccess : TenantAccessSettings.Load();

            if (!tenantAccess.Anyone)
            {
                var productItemList = GetProductItemListForSerialization();

                foreach (var productItem in productItemList.Where(productItem => !productItem.CanNotBeDisabled))
                {
                    sb.AppendFormat("ASC.Settings.AccessRights.initProduct('{0}');", Convert.ToBase64String(
                                        Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(productItem))));
                }
            }

            sb.AppendFormat("ASC.Settings.AccessRights.init({0});",
                            JsonConvert.SerializeObject(Products.Select(p => p.GetSysName()).ToArray()));

            Page.RegisterInlineScript(sb.ToString());
        }