protected void lnkBreakWithClear_Click(Object sender, EventArgs e) { // Check permission CheckModifyPermission(true); // Break permission inheritance and clear permissions AclProvider.BreakInherintance(Node, false); // Log staging task and flush cache DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.BreakACLInheritance, Node.TreeProvider, SynchronizationInfoProvider.ENABLED_SERVERS, null, Node.TreeProvider.AllowAsyncActions); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to event log. if (DocumentManager.Tree.LogEvents) { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", currentUser.UserID, currentUser.UserName, Node.NodeID, DocumentName, ipAddress, ResHelper.GetAPIString("security.documentpermissionsbreakclear", "Inheritance of the parent document permissions have been broken."), Node.NodeSiteID, eventUrl); } lblInheritanceInfo.Text = GetString("Security.InheritsInfo.DoesNotInherit"); SwitchBackToPermissionsMode(); // Clear and reload securityElem.InvalidateAcls(); securityElem.LoadOperators(true); }
/// <summary> /// Gets a specific news document. /// </summary> /// <param name="aliasPath">The alias path</param> private static TreeNode GetNewsDocument(string aliasPath) { if (string.IsNullOrEmpty(aliasPath)) { return(null); } // Try to get the data from cache var document = CacheHelper.Cache( cs => { // Get the news document var result = DocumentHelper.GetDocuments("CMS.News") .Path("/News/" + aliasPath) .OnCurrentSite() .Published() .TopN(1) .FirstObject; // Setup the cache dependencies only when caching is active if ((result != null) && cs.Cached) { // Set the cache dependencies var nodeDependencies = TreeProvider.GetDependencyCacheKeys(result, SiteContext.CurrentSiteName); cs.CacheDependency = CacheHelper.GetCacheDependency(nodeDependencies); } return(result); }, new CacheSettings(GetCacheMinutes(), GetCacheKey("newsdetail", aliasPath)) ); return(document); }
/// <summary> /// Removes selected operator from the ACL. /// </summary> protected void btnRemoveOperator_Click(Object sender, EventArgs e) { // Check permission CheckPermissions(true); if (lstOperators.SelectedItem == null) { return; } string operatorName = lstOperators.SelectedItem.Text; string message; string operatorID = lstOperators.SelectedValue; if (operatorID.StartsWithCSafe("U")) { int userId = int.Parse(operatorID.Substring(1)); UserInfo ui = UserInfoProvider.GetUserInfo(userId); AclItemInfoProvider.RemoveUser(Node.NodeID, ui); message = "security.documentuserpermissionremoved"; } else { RoleInfo ri = RoleInfoProvider.GetRoleInfo(int.Parse(operatorID.Substring(1))); AclItemInfoProvider.RemoveRole(Node.NodeID, ri); message = "security.documentrolepermissionremoved"; } // Log synchronization task and flush cache DocumentSynchronizationHelper.LogDocumentChange(TreeHelper.SelectSingleNode(Node.NodeID), TaskTypeEnum.UpdateDocument, Node.TreeProvider); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to eventlog. if (Tree.LogEvents) { EventLogProvider.LogEvent(EventType.INFORMATION, "Content", "DOCPERMISSIONSMODIFIED", string.Format(ResHelper.GetAPIString(message, "Operator '{0}' has been removed from the document permissions."), operatorName), eventUrl, Tree.UserInfo.UserID, Tree.UserInfo.UserName, Node.NodeID, DocumentName, ipAddress, Node.NodeSiteID); } dsAclItems = null; LoadOperators(true); CheckButtonsActiveState(); }
/// <summary> /// Gets the news list. /// </summary> private static InfoDataSet <News> GetNewsList() { // Try to get the data from cache var newsList = CacheHelper.Cache( cs => { // Define the news parent document string newsNodeAlias = "/News"; // Get the news documents var result = DocumentHelper.GetDocuments <News>() .Path(newsNodeAlias, PathTypeEnum.Children) .OnCurrentSite() .Published() .PublishedVersion() .TypedResult; // Setup the cache dependencies only when caching is active if (cs.Cached) { // Get the news parent document var rootDoc = DocumentHelper.GetDocuments("CMS.MenuItem") .Path(newsNodeAlias) .OnCurrentSite() .Published() .TopN(1) .FirstObject; if (rootDoc != null) { // Set the cache dependencies for the root news document. This will cover also all its child news documents by default. var nodeDependencies = TreeProvider.GetDependencyCacheKeys(rootDoc, SiteContext.CurrentSiteName); cs.CacheDependency = CacheHelper.GetCacheDependency(nodeDependencies); } } return(result); }, new CacheSettings(GetCacheMinutes(), GetCacheKey("newslist")) ); return(newsList); }
/// <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); }
public void Save() { CheckPermissions(true); int allowed = 0; int denied = 0; string operatorID = null; if (lstOperators.SelectedItem == null) { return; } else { operatorID = lstOperators.SelectedValue; allowed += GetCheckBoxValue(chkReadAllow, NodePermissionsEnum.Read); allowed += GetCheckBoxValue(chkModifyAllow, NodePermissionsEnum.Modify); allowed += GetCheckBoxValue(chkCreateAllow, NodePermissionsEnum.Create); allowed += GetCheckBoxValue(chkDeleteAllow, NodePermissionsEnum.Delete); allowed += GetCheckBoxValue(chkDestroyAllow, NodePermissionsEnum.Destroy); allowed += GetCheckBoxValue(chkExploreTreeAllow, NodePermissionsEnum.ExploreTree); allowed += GetCheckBoxValue(chkManagePermissionsAllow, NodePermissionsEnum.ModifyPermissions); denied += GetCheckBoxValue(chkReadDeny, NodePermissionsEnum.Read); denied += GetCheckBoxValue(chkModifyDeny, NodePermissionsEnum.Modify); denied += GetCheckBoxValue(chkCreateDeny, NodePermissionsEnum.Create); denied += GetCheckBoxValue(chkDeleteDeny, NodePermissionsEnum.Delete); denied += GetCheckBoxValue(chkDestroyDeny, NodePermissionsEnum.Destroy); denied += GetCheckBoxValue(chkExploreTreeDeny, NodePermissionsEnum.ExploreTree); denied += GetCheckBoxValue(chkManagePermissionsDeny, NodePermissionsEnum.ModifyPermissions); string message = null; string operatorName = lstOperators.SelectedItem.Text; if (operatorID.StartsWith("U")) { int userId = int.Parse(operatorID.Substring(1)); UserInfo ui = UserInfoProvider.GetUserInfo(userId); AclProvider.SetUserPermissions(Node, allowed, denied, ui); message = "security.documentuserpermissionschange"; } else { AclProvider.SetRolePermissions(Node, allowed, denied, int.Parse(operatorID.Substring(1))); message = "security.documentrolepermissionschange"; } lblInfo.Text = GetString("general.changessaved"); // Log synchronization task and flush cache DocumentSynchronizationHelper.LogDocumentChange(Node, TaskTypeEnum.UpdateDocument, Node.TreeProvider); CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(Node, Node.NodeSiteName)); // Insert information about this event to eventlog. if (Tree.LogEvents) { EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DOCPERMISSIONSMODIFIED", Tree.UserInfo.UserID, Tree.UserInfo.UserName, Node.NodeID, DocumentName, ipAddress, string.Format(ResHelper.GetAPIString(message, "Permissions of the operator '{0}' have been modified for the document."), operatorName), Node.NodeSiteID, eventUrl); } } if (Node != null) { // Invalidate permission data in current request TreeSecurityProvider.InvalidateTreeNodeAuthorizationResults(CMSContext.CurrentUser, NodeID, Node.DocumentCulture); AclProvider.InvalidateACLItems(CMSContext.CurrentUser.UserID, Node); } CheckPermissions(false, true); pnlUpdate.Update(); }
/// <summary> /// Handles reset button click. Resets zones of specified type to default settings. /// </summary> protected void btnReset_Click(object sender, EventArgs e) { // Disable the reset action when document editing is not allowed (i.e. non-editable workflow step) if (!WidgetActionsEnabled) { resetAllowed = false; } // Security check if (!DisplayResetButton || !resetAllowed) { return; } PageInfo pi = CurrentPageInfo; if (pi == null) { return; } if ((zoneType == WidgetZoneTypeEnum.Editor) || (zoneType == WidgetZoneTypeEnum.Group)) { // Clear document webparts/group webparts TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { bool updateDocument = true; if (zoneType == WidgetZoneTypeEnum.Editor) { if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Do not save the document to the database, keep it in only in the memory updateDocument = false; // Get the default template widgets PortalContext.SaveEditorWidgets(pi.DocumentID, pi.UsedPageTemplateInfo.TemplateInstance.GetZonesXML(WidgetZoneTypeEnum.Editor)); } else { node.SetValue("DocumentWebParts", String.Empty); } ClearEditorWidgetsContent(node, pi.UsedPageTemplateInfo.TemplateInstance, updateDocument); // Delete all variants if (pi.UsedPageTemplateInfo != null) { foreach (WebPartZoneInstance zoneInstance in zoneInstances) { if (zoneInstance.WebPartsContainVariants) { VariantHelper.DeleteWidgetVariants(zoneInstance.ZoneID, pi.UsedPageTemplateInfo.PageTemplateId, node.DocumentID); } } } } else if (zoneType == WidgetZoneTypeEnum.Group) { node.SetValue("DocumentGroupWebParts", String.Empty); } if (updateDocument) { // Save the document DocumentHelper.UpdateDocument(node, TreeProvider); } } } else if (zoneType == WidgetZoneTypeEnum.User) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetUserPersonalization(MembershipContext.AuthenticatedUser.UserID, pi.DocumentID); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached values TreeNode node = DocumentHelper.GetDocument(pi.DocumentID, TreeProvider); if (node != null) { CacheHelper.TouchKeys(TreeProvider.GetDependencyCacheKeys(node, SiteContext.CurrentSiteName)); } } else if (zoneType == WidgetZoneTypeEnum.Dashboard) { // Delete user personalization info PersonalizationInfo up = PersonalizationInfoProvider.GetDashBoardPersonalization(MembershipContext.AuthenticatedUser.UserID, PortalContext.DashboardName, PortalContext.DashboardSiteName); PersonalizationInfoProvider.DeletePersonalizationInfo(up); // Clear cached page template if (pi.UsedPageTemplateInfo != null) { CacheHelper.TouchKey("cms.pagetemplate|byid|" + pi.UsedPageTemplateInfo.PageTemplateId); } } // Make redirect to see changes after load string url = RequestContext.CurrentURL; if (ViewMode.IsEdit(true) || ViewMode.IsEditLive()) { // Ensure that the widgets will be loaded from the session layer (not from database) url = URLHelper.UpdateParameterInUrl(url, "cmscontentchanged", "true"); } URLHelper.Redirect(url); }