/// <summary> /// Resets permission inheritance of node and its children. /// </summary> /// <param name="siteName">Name of site</param> /// <param name="nodeAliasPath">Alias path</param> /// <param name="recursive">Indicates whether to recursively reset all nodes below the current node</param> /// <param name="user">Current user</param> /// <param name="tr">Tree provider</param> /// <returns>Whether TRUE if no permission conflict has occurred</returns> private bool ResetNodePermission(string siteName, string nodeAliasPath, bool recursive, CurrentUserInfo user, TreeProvider tr) { // Check permissions bool permissionsResult = false; try { if (tr == null) { tr = new TreeProvider(user); } // Get node by alias path TreeNode treeNode = tr.SelectSingleNode(siteName, nodeAliasPath, null, true, null, false); permissionsResult = CanModifyPermission(!recursive, treeNode, user); if (treeNode != null) { // If user has permissions if (permissionsResult) { // Break inheritance of a node if (!AclProvider.DoesNodeInheritPermissions(treeNode.NodeID)) { // Restore inheritance of a node AclProvider.RestoreInheritance(treeNode); // Log current encoded alias path AddLog(HTMLHelper.HTMLEncode(nodeAliasPath)); // Log staging task and flush cache DocumentSynchronizationHelper.LogDocumentChange(treeNode, TaskTypeEnum.RestoreACLInheritance, treeNode.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, null, treeNode.TreeProvider.AllowAsyncActions); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { if (recursive) { LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, string.Format(ResHelper.GetAPIString("security.documentpermissionsrestoredfordoc", "Permissions of document '{0}' have been restored to the parent document permissions."), nodeAliasPath), Node.NodeSiteID, null, null, null, null); } else { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", user.UserID, user.UserName, treeNode.NodeID, treeNode.GetDocumentName(), ipAddress, ResHelper.GetAPIString("security.documentpermissionsrestored", "Permissions have been restored to the parent document permissions."), Node.NodeSiteID, eventUrl); } } } else { AddLog(string.Format(ResHelper.GetString("cmsdesk.skippingrestoring"), HTMLHelper.HTMLEncode(nodeAliasPath))); } } // Recursively reset node inheritance if (recursive) { // Get child nodes of current node DataSet ds = DocumentManager.Tree.SelectNodes(siteName, treeNode.NodeAliasPath.TrimEnd('/') + "/%", TreeProvider.ALL_CULTURES, true, null, null, null, 1, false, -1, TreeProvider.SELECTNODES_REQUIRED_COLUMNS + ",NodeAliasPath"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { string childNodeAliasPath = ValidationHelper.GetString(dr["NodeAliasPath"], string.Empty); if (!string.IsNullOrEmpty(childNodeAliasPath)) { bool tempPermissionsResult = ResetNodePermission(siteName, childNodeAliasPath, true, user, tr); permissionsResult = tempPermissionsResult && permissionsResult; } } } } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state == CMSThread.ABORT_REASON_STOP) { // When canceled CurrentInfo = ResHelper.GetString("cmsdesk.restoringcanceled"); AddLog(CurrentInfo); } else { // Log error CurrentError = ResHelper.GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } } catch (Exception ex) { // Log error CurrentError = ResHelper.GetString("cmsdesk.restoringfailed") + ": " + ex.Message; AddLog(CurrentError); } return(permissionsResult); }
protected void Page_Load(Object sender, EventArgs e) { currentSite = CMSContext.CurrentSite; currentUser = CMSContext.CurrentUser; ipAddress = HTTPHelper.UserHostAddress; eventUrl = HTTPHelper.GetAbsoluteUri(); if (!RequestHelper.IsCallback()) { btnCancel.Attributes.Add("onclick", ctlAsync.GetCancelScript(true) + "return false;"); btnCancel.Text = GetString("General.Cancel"); pnlLog.Visible = false; pnlPageContent.Visible = true; // Gets the node if (Node != null) { UIContext.PropertyTab = PropertyTabEnum.Security; // Check license if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), string.Empty) != string.Empty) { if (!LicenseKeyInfoProvider.IsFeatureAvailable(URLHelper.GetCurrentDomain(), FeatureEnum.DocumentLevelPermissions)) { if (UIHelper.IsUnavailableUIHidden()) { plcContainer.Visible = false; } else { pnlPermissions.Visible = false; lblLicenseInfo.Visible = true; lblLicenseInfo.Text = GetString("Security.NotAvailableInThisEdition"); } } } // Initialize controls SetupControls(); // Register scripts ScriptHelper.RegisterDialogScript(this); // Check if document inherits permissions and display info inheritsPermissions = AclProvider.DoesNodeInheritPermissions(Node.NodeID); lblInheritanceInfo.Text = inheritsPermissions ? GetString("Security.InheritsInfo.Inherits") : GetString("Security.InheritsInfo.DoesNotInherit"); if (!RequestHelper.IsPostBack()) { // Set secured radio buttons switch (Node.IsSecuredNode) { case 0: radNo.Checked = true; break; case 1: radYes.Checked = true; break; default: if (Node.NodeParentID == 0) { radNo.Checked = true; } else { radParent.Checked = true; } break; } // Set secured radio buttons switch (Node.RequiresSSL) { case 0: radNoSSL.Checked = true; break; case 1: radYesSSL.Checked = true; break; case 2: radNeverSSL.Checked = true; break; default: if (Node.NodeParentID == 0) { radNoSSL.Checked = true; } else { radParentSSL.Checked = true; } break; } } // Hide link to the inheritance settings if this is the root node if (Node.NodeParentID == 0) { plcAuthParent.Visible = false; plcSSLParent.Visible = false; lnkInheritance.Visible = false; } } else { pnlPageContent.Visible = false; } } ctlAsync.OnFinished += ctlAsync_OnFinished; ctlAsync.OnError += ctlAsync_OnError; ctlAsync.OnRequestLog += ctlAsync_OnRequestLog; ctlAsync.OnCancel += ctlAsync_OnCancel; pnlPageContent.Enabled = !DocumentManager.ProcessingAction; }