public void RemoveAce(List <FileEntry <T> > entries) { var fileSecurity = FileSecurity; entries.ForEach( entry => { if (entry.RootFolderType != FolderType.USER && entry.RootFolderType != FolderType.Privacy || Equals(entry.RootFolderId, GlobalFolderHelper.FolderMy) || Equals(entry.RootFolderId, GlobalFolderHelper.FolderPrivacy)) { return; } var entryType = entry.FileEntryType; fileSecurity.Share(entry.ID, entryType, AuthContext.CurrentAccount.ID, entry.RootFolderType == FolderType.USER ? fileSecurity.DefaultMyShare : fileSecurity.DefaultPrivacyShare); if (entryType == FileEntryType.File) { DocumentServiceHelper.CheckUsersForDrop((File <T>)entry); } FileMarker.RemoveMarkAsNew(entry); }); }
public static void RemoveAce(List <FileEntry> entries) { var fileSecurity = Global.GetFilesSecurity(); entries.ForEach( entry => { if (entry.RootFolderType != FolderType.USER || Equals(entry.RootFolderId, Global.FolderMy)) { return; } var entryType = entry.FileEntryType; fileSecurity.Share(entry.ID, entryType, SecurityContext.CurrentAccount.ID, fileSecurity.DefaultMyShare); if (entryType == FileEntryType.File) { DocumentServiceHelper.CheckUsersForDrop((File)entry); } FileMarker.RemoveMarkAsNew(entry); }); }
public static bool SetAceObject(List <AceWrapper> aceWrappers, FileEntry entry, bool notify, string message) { if (entry == null) { throw new ArgumentNullException(FilesCommonResource.ErrorMassage_BadRequest); } if (!CanSetAccess(entry)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } var fileSecurity = Global.GetFilesSecurity(); var entryType = entry.FileEntryType; var recipients = new Dictionary <Guid, FileShare>(); var usersWithoutRight = new List <Guid>(); var changed = false; foreach (var w in aceWrappers.OrderByDescending(ace => ace.SubjectGroup)) { var subjects = fileSecurity.GetUserSubjects(w.SubjectId); var ownerId = entry.RootFolderType == FolderType.USER ? entry.RootFolderCreator : entry.CreateBy; if (entry.RootFolderType == FolderType.COMMON && subjects.Contains(Constants.GroupAdmin.ID) || ownerId == w.SubjectId) { continue; } var share = w.Share; if (w.SubjectId == FileConstant.ShareLinkId) { if (w.Share == FileShare.ReadWrite && CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor()) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } share = w.Share == FileShare.Restrict ? FileShare.None : w.Share; } fileSecurity.Share(entry.ID, entryType, w.SubjectId, share); changed = true; if (w.SubjectId == FileConstant.ShareLinkId) { continue; } entry.Access = share; var listUsersId = new List <Guid>(); if (w.SubjectGroup) { listUsersId = CoreContext.UserManager.GetUsersByGroup(w.SubjectId).Select(ui => ui.ID).ToList(); } else { listUsersId.Add(w.SubjectId); } listUsersId.Remove(SecurityContext.CurrentAccount.ID); if (entryType == FileEntryType.File) { listUsersId.ForEach(uid => FileTracker.ChangeRight(entry.ID, uid, true)); } var addRecipient = share == FileShare.Read || share == FileShare.ReadWrite || share == FileShare.Review || share == FileShare.FillForms || share == FileShare.Comment || share == FileShare.None && entry.RootFolderType == FolderType.COMMON; var removeNew = share == FileShare.None && entry.RootFolderType == FolderType.USER || share == FileShare.Restrict; listUsersId.ForEach(id => { recipients.Remove(id); if (addRecipient) { recipients.Add(id, share); } else if (removeNew) { usersWithoutRight.Add(id); } }); } if (entryType == FileEntryType.File) { DocumentServiceHelper.CheckUsersForDrop((File)entry); } if (recipients.Any()) { if (entryType == FileEntryType.File || ((Folder)entry).TotalSubFolders + ((Folder)entry).TotalFiles > 0 || entry.ProviderEntry) { FileMarker.MarkAsNew(entry, recipients.Keys.ToList()); } if (entry.RootFolderType == FolderType.USER && notify) { NotifyClient.SendShareNotice(entry, recipients, message); } } usersWithoutRight.ForEach(userId => FileMarker.RemoveMarkAsNew(entry, userId)); return(changed); }
public static bool SetAceObject(List <AceWrapper> aceWrappers, FileEntry entry, bool notify, string message, AceAdvancedSettingsWrapper advancedSettings) { if (entry == null) { throw new ArgumentNullException(FilesCommonResource.ErrorMassage_BadRequest); } if (!CanSetAccess(entry)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } var fileSecurity = Global.GetFilesSecurity(); var ownerId = entry.RootFolderType == FolderType.USER ? entry.RootFolderCreator : entry.CreateBy; var entryType = entry.FileEntryType; var recipients = new Dictionary <Guid, FileShare>(); var usersWithoutRight = new List <Guid>(); var changed = false; foreach (var w in aceWrappers.OrderByDescending(ace => ace.SubjectGroup)) { var subjects = fileSecurity.GetUserSubjects(w.SubjectId); if (entry.RootFolderType == FolderType.COMMON && subjects.Contains(Constants.GroupAdmin.ID) || ownerId == w.SubjectId) { continue; } var share = w.Share; if (w.SubjectId == FileConstant.ShareLinkId) { if (w.Share == FileShare.ReadWrite && CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor()) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } // only editable format on personal if (CoreContext.Configuration.Personal && !FileUtility.CanWebView(entry.Title) && w.Share != FileShare.Restrict) { throw new SecurityException(FilesCommonResource.ErrorMassage_BadRequest); } // only editable format on SaaS trial if (w.Share != FileShare.Restrict && !CoreContext.Configuration.Standalone && TenantExtra.GetTenantQuota().Trial&& !FileUtility.CanWebView(entry.Title)) { throw new SecurityException(FilesCommonResource.ErrorMassage_BadRequest); } share = w.Share == FileShare.Restrict || !FilesSettings.ExternalShare ? FileShare.None : w.Share; } fileSecurity.Share(entry.ID, entryType, w.SubjectId, share); changed = true; if (w.SubjectId == FileConstant.ShareLinkId) { continue; } entry.Access = share; var listUsersId = new List <Guid>(); if (w.SubjectGroup) { listUsersId = CoreContext.UserManager.GetUsersByGroup(w.SubjectId).Select(ui => ui.ID).ToList(); } else { listUsersId.Add(w.SubjectId); } listUsersId.Remove(SecurityContext.CurrentAccount.ID); if (entryType == FileEntryType.File) { listUsersId.ForEach(uid => FileTracker.ChangeRight(entry.ID, uid, true)); } var addRecipient = share == FileShare.Read || share == FileShare.CustomFilter || share == FileShare.ReadWrite || share == FileShare.Review || share == FileShare.FillForms || share == FileShare.Comment || share == FileShare.None && entry.RootFolderType == FolderType.COMMON; var removeNew = share == FileShare.None && entry.RootFolderType == FolderType.USER || share == FileShare.Restrict; listUsersId.ForEach(id => { recipients.Remove(id); if (addRecipient) { recipients.Add(id, share); } else if (removeNew) { usersWithoutRight.Add(id); } }); } if (entryType == FileEntryType.File) { DocumentServiceHelper.CheckUsersForDrop((File)entry); } if (recipients.Any()) { if (entryType == FileEntryType.File || ((Folder)entry).TotalSubFolders + ((Folder)entry).TotalFiles > 0 || entry.ProviderEntry) { FileMarker.MarkAsNew(entry, recipients.Keys.ToList()); } if ((entry.RootFolderType == FolderType.USER || entry.RootFolderType == FolderType.Privacy) && notify) { NotifyClient.SendShareNotice(entry, recipients, message); } } if (advancedSettings != null && entryType == FileEntryType.File && ownerId == SecurityContext.CurrentAccount.ID && FileUtility.CanWebView(entry.Title) && !entry.ProviderEntry) { fileSecurity.Share(entry.ID, entryType, FileConstant.DenyDownloadId, advancedSettings.DenyDownload ? FileShare.Restrict : FileShare.None); fileSecurity.Share(entry.ID, entryType, FileConstant.DenySharingId, advancedSettings.DenySharing ? FileShare.Restrict : FileShare.None); } usersWithoutRight.ForEach(userId => FileMarker.RemoveMarkAsNew(entry, userId)); return(changed); }
public static void SetAceObject(List <AceWrapper> aceWrappers, FileEntry entry, bool notify, string message) { if (entry == null) { throw new ArgumentNullException(FilesCommonResource.ErrorMassage_BadRequest); } if (!CanSetAccess(entry)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } var fileSecurity = Global.GetFilesSecurity(); var defaultShare = entry.RootFolderType == FolderType.COMMON ? fileSecurity.DefaultCommonShare : fileSecurity.DefaultMyShare; var entryType = entry is File ? FileEntryType.File : FileEntryType.Folder; var recipients = new Dictionary <Guid, FileShare>(); foreach (var w in aceWrappers.OrderByDescending(ace => ace.SubjectGroup)) { var subjects = fileSecurity.GetUserSubjects(w.SubjectId); if (entry.RootFolderType == FolderType.COMMON && subjects.Contains(Constants.GroupAdmin.ID)) { continue; } var ace = fileSecurity.GetShares(entry) .Where(r => subjects.Contains(r.Subject)) .OrderBy(r => subjects.IndexOf(r.Subject)) .ThenBy(r => r.Level) .ThenByDescending(r => r.Share) .FirstOrDefault(); var parentShare = ace != null && !(ace.Subject == w.SubjectId && ace.Share == w.Share) ? ace.Share : defaultShare; var share = parentShare == w.Share ? FileShare.None : w.Share; if (w.SubjectId == FileConstant.ShareLinkId) { if (w.Share == FileShare.ReadWrite && CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor()) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } share = w.Share == FileShare.Restrict ? FileShare.None : w.Share; } fileSecurity.Share(entry.ID, entryType, w.SubjectId, share); if (entryType == FileEntryType.File && share != FileShare.ReadWrite) { DocumentServiceHelper.CheckUsersForDrop((File)entry, !w.SubjectGroup ? w.SubjectId : Guid.Empty); } if (w.SubjectId == FileConstant.ShareLinkId) { continue; } entry.Access = share; var listUsersId = new List <Guid>(); if (w.SubjectGroup) { listUsersId = CoreContext.UserManager.GetUsersByGroup(w.SubjectId).Select(ui => ui.ID).ToList(); } else { listUsersId.Add(w.SubjectId); } listUsersId.Remove(SecurityContext.CurrentAccount.ID); if (entryType == FileEntryType.File) { listUsersId.ForEach(uid => FileTracker.ChangeRight(entry.ID, uid, true)); } var addRecipient = share == FileShare.Read || share == FileShare.ReadWrite || share == FileShare.Review || share == FileShare.None && entry.RootFolderType == FolderType.COMMON; listUsersId.ForEach(id => { recipients.Remove(id); if (addRecipient) { recipients.Add(id, share); } }); } if (recipients.Any()) { if (entryType == FileEntryType.File || ((Folder)entry).TotalSubFolders + ((Folder)entry).TotalFiles > 0 || entry.ProviderEntry) { FileMarker.MarkAsNew(entry, recipients.Keys.ToList()); } if (entry.RootFolderType == FolderType.USER && notify) { NotifyClient.SendShareNotice(entry, recipients, message); } } }