private void ApplyPermissionsToDirectChildren(File file, List<Permission> filePermissions) { FileController fileCtrl = new FileController(); PermissionController permCtrl = new PermissionController(); //List<File> childFiles = fileCtrl.GetItemsByParent(file.ID, UserId, PortalId, PortalSettings.AdministratorRoleId, ""); List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>; foreach (File childFile in childFiles) { //check edit permission if (childFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, false)) { //delete existing permissions List<Permission> deletePermissions = permCtrl.GetItems(childFile.ID) as List<Permission>; foreach (Permission deletePermission in deletePermissions) { Permission permissionToDelete = permCtrl.Get(deletePermission.ID, childFile.ID); permCtrl.Delete(permissionToDelete); } //add file permissions foreach (Permission filePermission in filePermissions) { Permission newPermission = new Permission(); newPermission.ID = filePermission.ID; newPermission.ModuleID = filePermission.ModuleID; newPermission.PortalID = filePermission.PortalID; newPermission.CanSee = filePermission.CanSee; newPermission.CanModify = filePermission.CanModify; newPermission.CanAddFiles = filePermission.CanAddFiles; newPermission.CanAddFolders = filePermission.CanAddFolders; newPermission.CanDelete = filePermission.CanDelete; newPermission.CanModifyPermission = filePermission.CanModifyPermission; newPermission.IsOwner = filePermission.IsOwner; newPermission.RoleID = filePermission.RoleID; newPermission.RoleName = filePermission.RoleName; newPermission.UserID = filePermission.UserID; newPermission.UserName = filePermission.UserName; //assign new permission to child item newPermission.FileID = childFile.ID; permCtrl.Create(newPermission); } //report updated file _updatedPermissionFiles.Add(childFile); } else { //report non-updated file _notUpdatedPermissionFiles.Add(childFile); } //do child files ApplyPermissionsToDirectChildren(childFile, filePermissions); } }
private void DeleteChildren(File file) { //delete ALL children items where user has delete permission FileController fileCtrl = new FileController(); List<File> files = fileCtrl.GetItems(file.ID) as List<File>; foreach (File childFile in files) { if (file.ItemType == 0) { DeleteChildren(childFile); } } //send to trash if not folder if (file.ItemType != 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false)) { //send to trash if not there already if (!file.IsInTrash) { file.IsInTrash = true; fileCtrl.Update(file); #region "Audit" //Audit: Create Item AuditController ctrlAudit = new AuditController(); Audit deleteAudit = new Audit() { EventDate = file.LastModifiedDate, EventDetails = "", EventName = "Deleted", FileID = file.ID, UserID = UserId }; ctrlAudit.Create(deleteAudit); #endregion _deletedFilesCount++; return; } //if file is in trash, delete permissions and file if (file.IsInTrash) { PermissionController permCtrl = new PermissionController(); //delete versions and version permissions List<File> versions = fileCtrl.GetItems(file.ID) as List<File>; foreach (File version in versions) { List<Permission> versionPermissions = permCtrl.GetItems(version.ID) as List<Permission>; for (int i = 0; versionPermissions.Count - 1 > i; i++) { permCtrl.Delete(versionPermissions[i]); } fileCtrl.Delete(version); } //delete file permissions List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>; for (int i = 0; folderPermissions.Count - 1 >= i; i++) { permCtrl.Delete(folderPermissions[i]); } //delete file instead of sending to trash _filesToDelete.Add(file); //fileCtrl.Delete(file); _permanentlyDeletedFilesCount++; return; } } //check if any items exist under folder and delete permission before deleting if (file.ItemType == 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false)) { //get current child count List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>; int childFilesCount = 0; //count child items not in trash foreach (File childFileCount in childFiles) { if (!childFileCount.IsInTrash) { childFilesCount++; } } //no child items, permanently delete folder if (childFilesCount == 0) { //delete folder permissions PermissionController permCtrl = new PermissionController(); List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>; for (int i = 0; folderPermissions.Count - 1 >= i; i++) { permCtrl.Delete(folderPermissions[i]); } //delete folder instead of sending to trash _filesToDelete.Add(file); //fileCtrl.Delete(file); _deletedFilesCount++; return; } else { _notDeletedFilesCount++; return; } } _notDeletedFilesCount++; }
protected void lbnOK_Click(object sender, EventArgs e) { try { ParentID = -1; if (this.Request.QueryString["Parent"] != null) { ParentID = Int32.Parse(this.Request.QueryString["Parent"]); } if (this.Request.QueryString["View"] != null) { _sourceView = this.Request.QueryString["View"]; } if (this.Request.QueryString["ID"] != null) { this.ItemID = Int32.Parse(this.Request.QueryString["ID"]); } else { this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Warning=Could not save updates. File not found."), true); } //get file DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController(); DNNQuickApps.Modules.QuickDocsPro.File objFile = objQuickFiles.Get(ItemID); objFile.ModuleID = ModuleId; objFile.LastModifiedDate = System.DateTime.Now; objFile.Name = txtName.Text; objFile.Description = txtDescription.Text; objFile.LastModifiedByUserID = UserId; //update link url if (objFile.ItemType == 2) //link { objFile.LinkURL = txtHyperlink.Text; } if (UserId != -1) { objFile.LastModifiedByUserName = UserInfo.DisplayName; } else { objFile.LastModifiedByUserName = "******"; } try { objFile.VersionsToKeep = Int32.Parse(txtVersionsToKeep.Text); } catch { } if (objFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, true)) { //delete existing permissions PermissionController permCtrl = new PermissionController(); List<Permission> permissionsToDelete = permCtrl.GetItems(objFile.ID) as List<Permission>; for (int i = 0; i < permissionsToDelete.Count; i++) { permCtrl.Delete(permissionsToDelete[i]); } //create updated permissions PermissionController objQuickPermissions = new PermissionController(); foreach (GridViewRow row in gridPermissions.Rows) { if ((((CheckBox)row.FindControl("chkCanSee")).Checked)) { Permission perm = new Permission(); perm.CanSee = true; perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddItems")).Checked; perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked; perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked; perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked; perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked; perm.FileID = objFile.ID; int userID = Int32.Parse(row.Cells[8].Text); int roleID = Int32.Parse(row.Cells[10].Text); string userName = row.Cells[9].Text; string roleName = row.Cells[11].Text; if (userID > 0) { perm.UserID = userID; perm.UserName = userName; } if (roleID > 0) { perm.RoleID = roleID; perm.RoleName = roleName; } objQuickPermissions.Create(perm); } } } objQuickFiles.Update(objFile); #region "Audit" //Audit: Updated Item AuditController ctrlAudit = new AuditController(); Audit updatedAudit = new Audit() { EventDate = objFile.LastModifiedDate, EventDetails = "", EventName = "Updated", FileID = objFile.ID, UserID = UserId }; ctrlAudit.Create(updatedAudit); #endregion //refresh cache SynchronizeModule(); if (chkApplyToSubItems.Checked) { //apply permissions to sub-items ApplyPermissionsToSubItems(objFile); return; } //Redirect back to the portal home page this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "View=" + _sourceView, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Success=Changes saved."), true); } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }