/// <summary> /// PreRender action on which security settings are set. /// </summary> private void Page_PreRender(object sender, EventArgs e) { if ((Form == null) || !mDocumentSaved) { return; } TreeNode editedNode = Form.EditedObject as TreeNode; // Create or rebuild department content index CreateDepartmentContentSearchIndex(editedNode); if ((editedNode == null) || !editedNode.NodeIsACLOwner) { return; } ForumInfo fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID); MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName); // Check if forum of media library exists if ((fi == null) && (mi == null)) { return; } // Get allowed roles ID int aclID = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0); DataSet listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID"); IList <int> roleIds = null; if (!DataHelper.DataSourceIsEmpty(listRoles)) { roleIds = DataHelper.GetIntegerValues(listRoles.Tables[0], "RoleID") as List <int>; } // Set permissions for forum if (fi != null) { // Get resource object ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums"); // Get permissions IDs var forumPermissions = PermissionNameInfoProvider.GetPermissionNames() .Column("PermissionID") .WhereEquals("ResourceID", resForums.ResourceID) .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_READ) .WhereNotEquals("PermissionName", CMSAdminControl.PERMISSION_MODIFY); // Delete old permissions apart attach file permission ForumRoleInfoProvider.DeleteAllRoles(new WhereCondition().WhereEquals("ForumID", fi.ForumID).WhereIn("PermissionID", forumPermissions)); // Set forum permissions ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIds, forumPermissions.Select(p => p.PermissionId).ToArray()); // Log staging task SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject); } // Set permissions for media library if (mi == null) { return; } // Get resource object ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary"); // Get permissions IDs var where = new WhereCondition() .WhereEquals("ResourceID", resMediaLibs.ResourceID) .And() .Where(new WhereCondition() .WhereEquals("PermissionName", "LibraryAccess") .Or() .WhereEquals("PermissionName", "FileCreate")); DataSet dsMediaLibPerm = PermissionNameInfoProvider.GetPermissionNames().Where(where).Column("PermissionID"); IList <int> mediaLibPermissionsIds = null; if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm)) { mediaLibPermissionsIds = DataHelper.GetIntegerValues(dsMediaLibPerm.Tables[0], "PermissionID"); } var deleteWhere = new WhereCondition() .WhereEquals("LibraryID", mi.LibraryID) .WhereIn("PermissionID", mediaLibPermissionsIds); // Delete old permissions only for Create file and See library content permissions MediaLibraryRolePermissionInfoProvider.DeleteAllRoles(deleteWhere.ToString(true)); MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIds, mediaLibPermissionsIds); // Log staging task; SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject); }
/// <summary> /// PreRender action on which security settings are set. /// </summary> private void Page_PreRender(object sender, EventArgs e) { if ((Form == null) || !mDocumentSaved) { return; } TreeNode editedNode = Form.EditedObject as TreeNode; // Create or rebuild department content index CreateDepartmentContentSearchIndex(editedNode); if ((editedNode == null) || !editedNode.NodeIsACLOwner) { return; } ForumInfo fi = ForumInfoProvider.GetForumInfo("Default_department_" + editedNode.NodeGUID, SiteContext.CurrentSiteID); MediaLibraryInfo mi = MediaLibraryInfoProvider.GetMediaLibraryInfo("Department_" + editedNode.NodeGUID, SiteContext.CurrentSiteName); // Check if forum of media library exists if ((fi == null) && (mi == null)) { return; } // Get allowed roles ID int aclID = ValidationHelper.GetInteger(editedNode.GetValue("NodeACLID"), 0); DataSet listRoles = AclItemInfoProvider.GetAllowedRoles(aclID, NodePermissionsEnum.Read, "RoleID"); string roleIDs = null; if (!DataHelper.DataSourceIsEmpty(listRoles)) { IList <string> roles = DataHelper.GetStringValues(listRoles.Tables[0], "RoleID"); roleIDs = TextHelper.Join(";", roles); } // Set permissions for forum if (fi != null) { // Get resource object ResourceInfo resForums = ResourceInfoProvider.GetResourceInfo("CMS.Forums"); // Get permissions IDs DataSet dsForumPerm = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resForums.ResourceID + " AND (PermissionName != '" + CMSAdminControl.PERMISSION_READ + "' AND PermissionName != '" + CMSAdminControl.PERMISSION_MODIFY + "')", null, 0, "PermissionID"); string forumPermissions = null; if (!DataHelper.DataSourceIsEmpty(dsForumPerm)) { foreach (DataRow drForumPerm in dsForumPerm.Tables[0].Rows) { forumPermissions += drForumPerm["PermissionID"] + ";"; } forumPermissions = forumPermissions.TrimEnd(';'); } // Delete old permissions apart attach file permission ForumRoleInfoProvider.DeleteAllRoles("ForumID = " + fi.ForumID + " AND PermissionID IN (" + forumPermissions.Replace(";", ", ") + ")"); // Set forum permissions ForumRoleInfoProvider.SetPermissions(fi.ForumID, roleIDs, forumPermissions); // Log staging task SynchronizationHelper.LogObjectChange(fi, TaskTypeEnum.UpdateObject); } // Set permissions for media library if (mi == null) { return; } // Get resource object ResourceInfo resMediaLibs = ResourceInfoProvider.GetResourceInfo("CMS.MediaLibrary"); // Get permissions IDs DataSet dsMediaLibPerm = PermissionNameInfoProvider.GetPermissionNames("ResourceID = " + resMediaLibs.ResourceID + " AND (PermissionName = 'LibraryAccess' OR PermissionName = 'FileCreate')", null, 0, "PermissionID"); string mediaLibPermissions = null; if (!DataHelper.DataSourceIsEmpty(dsMediaLibPerm)) { foreach (DataRow drMediaLibPerm in dsMediaLibPerm.Tables[0].Rows) { mediaLibPermissions += drMediaLibPerm["PermissionID"] + ";"; } mediaLibPermissions = mediaLibPermissions.TrimEnd(';'); } // Delete old permissions only for Create file and See library content permissions MediaLibraryRolePermissionInfoProvider.DeleteAllRoles("LibraryID = " + mi.LibraryID + " AND PermissionID IN (" + mediaLibPermissions.Replace(";", ", ") + ")"); // Set media library permissions MediaLibraryRolePermissionInfoProvider.SetPermissions(mi.LibraryID, roleIDs, mediaLibPermissions); // Log staging task SynchronizationHelper.LogObjectChange(mi, TaskTypeEnum.UpdateObject); }