public ISecurityObjectId InheritFrom(ISecurityObjectId objectId) { if (objectId is WebItemSecurityObject s) { return(Create(WebItemManager.GetParentItemID(s.WebItemId).ToString("N"), WebItemManager) is WebItemSecurityObject parent && parent.WebItemId != s.WebItemId && parent.WebItemId != Guid.Empty ? parent : null); } return(null); }
public WebItemSecurityInfo GetSecurityInfo(string id) { var info = GetSecurity(id).ToList(); var module = WebItemManager.GetParentItemID(new Guid(id)) != Guid.Empty; return new WebItemSecurityInfo { WebItemId = id, Enabled = !info.Any() || (!module && info.Any(i => i.Item2)) || (module && info.All(i => i.Item2)), Users = info .Select(i => UserManager.GetUsers(i.Item1)) .Where(u => u.ID != ASC.Core.Users.Constants.LostUser.ID), Groups = info .Select(i => UserManager.GetGroupInfo(i.Item1)) .Where(g => g.ID != ASC.Core.Users.Constants.LostGroupInfo.ID && g.CategoryID != ASC.Core.Users.Constants.SysGroupCategoryId) }; }
public bool IsAvailableForUser(Guid itemId, Guid @for) { var id = itemId.ToString(); var result = false; var tenant = TenantManager.GetCurrentTenant(); var dic = WebItemSecurityCache.GetOrInsert(tenant.TenantId); if (dic != null) { lock (dic) { if (dic.ContainsKey(id + @for)) { return(dic[id + @for]); } } } // can read or administrator var securityObj = WebItemSecurityObject.Create(id, WebItemManager); if (CoreBaseSettings.Personal && securityObj.WebItemId != WebItemManager.DocumentsProductID) { // only files visible in your-docs portal result = false; } else { var webitem = WebItemManager[securityObj.WebItemId]; if (webitem != null) { if ((webitem.ID == WebItemManager.CRMProductID || webitem.ID == WebItemManager.PeopleProductID || webitem.ID == WebItemManager.BirthdaysProductID || webitem.ID == WebItemManager.MailProductID) && UserManager.GetUsers(@for).IsVisitor(UserManager)) { // hack: crm, people, birtthday and mail products not visible for collaborators result = false; } else if ((webitem.ID == WebItemManager.CalendarProductID || webitem.ID == WebItemManager.TalkProductID) && UserManager.GetUsers(@for).IsOutsider(UserManager)) { // hack: calendar and talk products not visible for outsider result = false; } else if (webitem is IModule) { result = PermissionContext.PermissionResolver.Check(Authentication.GetAccountByID(tenant.TenantId, @for), securityObj, null, Read) && IsAvailableForUser(WebItemManager.GetParentItemID(webitem.ID), @for); } else { var hasUsers = AuthorizationManager.GetAces(Guid.Empty, Read.ID, securityObj).Any(a => a.SubjectId != ASC.Core.Users.Constants.GroupEveryone.ID); result = PermissionContext.PermissionResolver.Check(Authentication.GetAccountByID(tenant.TenantId, @for), securityObj, null, Read) || (hasUsers && IsProductAdministrator(securityObj.WebItemId, @for)); } } else { result = false; } } dic = WebItemSecurityCache.Get(tenant.TenantId); if (dic != null) { lock (dic) { dic[id + @for] = result; } } return(result); }