/// <summary> /// Ensures the recycle bin is appended when required (i.e. user has access to the root and it's not in dialog mode) /// </summary> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> /// <remarks> /// This method is overwritten strictly to render the recycle bin, it should serve no other purpose /// </remarks> protected sealed override ActionResult <TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings) { //check if we're rendering the root if (id == Constants.System.RootString && UserStartNodes.Contains(Constants.System.Root)) { var altStartId = string.Empty; if (queryStrings.HasKey(TreeQueryStringParameters.StartNodeId)) { altStartId = queryStrings.GetValue <string>(TreeQueryStringParameters.StartNodeId); } //check if a request has been made to render from a specific start node if (string.IsNullOrEmpty(altStartId) == false && altStartId != "undefined" && altStartId != Constants.System.RootString) { id = altStartId; } var nodesResult = GetTreeNodesInternal(id, queryStrings); if (!(nodesResult.Result is null)) { return(nodesResult.Result); } var nodes = nodesResult.Value; //only render the recycle bin if we are not in dialog and the start id is still the root //we need to check for the "application" key in the queryString because its value is required here, //and for some reason when there are no dashboards, this parameter is missing if (IsDialog(queryStrings) == false && id == Constants.System.RootString && queryStrings.HasKey("application")) { nodes.Add(CreateTreeNode( RecycleBinId.ToInvariantString(), id, queryStrings, LocalizedTextService.Localize("general", "recycleBin"), "icon-trash", RecycleBinSmells, queryStrings.GetRequiredValue <string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin")); } return(nodes); } return(GetTreeNodesInternal(id, queryStrings)); }
/// <summary> /// Checks if the menu requested is for the recycle bin and renders that, otherwise renders the result of PerformGetMenuForNode /// </summary> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> protected sealed override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) { if (RecycleBinId.ToInvariantString() == id) { // get the default assigned permissions for this user var actions = ActionsResolver.Current.FromActionSymbols(Security.CurrentUser.GetPermissions(Constants.System.RecycleBinContentString, Services.UserService)).ToList(); var menu = new MenuItemCollection(); // only add empty recycle bin if the current user is allowed to delete by default if (actions.Contains(ActionDelete.Instance)) { menu.Items.Add <ActionEmptyTranscan>(ui.Text("actions", "emptyTrashcan")); } menu.Items.Add <ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); return(menu); } return(PerformGetMenuForNode(id, queryStrings)); }
/// <summary> /// Ensures the recycle bin is appended when required (i.e. user has access to the root and it's not in dialog mode) /// </summary> /// <param name="id"></param> /// <param name="queryStrings"></param> /// <returns></returns> /// <remarks> /// This method is overwritten strictly to render the recycle bin, it should serve no other purpose /// </remarks> protected sealed override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { var ignoreUserStartNodes = queryStrings.GetValue <bool>(TreeQueryStringParameters.IgnoreUserStartNodes); //check if we're rendering the root if (id == Constants.System.RootString && UserStartNodes.Contains(Constants.System.Root) || ignoreUserStartNodes) { var altStartId = string.Empty; if (queryStrings.HasKey(TreeQueryStringParameters.StartNodeId)) { altStartId = queryStrings.GetValue <string>(TreeQueryStringParameters.StartNodeId); } //check if a request has been made to render from a specific start node if (string.IsNullOrEmpty(altStartId) == false && altStartId != "undefined" && altStartId != Constants.System.RootString) { id = altStartId; } var nodes = GetTreeNodesInternal(id, queryStrings); //only render the recycle bin if we are not in dialog and the start id id still the root if (IsDialog(queryStrings) == false && id == Constants.System.RootString) { nodes.Add(CreateTreeNode( RecycleBinId.ToInvariantString(), id, queryStrings, Services.TextService.Localize("general/recycleBin"), "icon-trash", RecycleBinSmells, queryStrings.GetRequiredValue <string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin")); } return(nodes); } return(GetTreeNodesInternal(id, queryStrings)); }
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings) { if (id == Constants.System.Root.ToInvariantString()) { var menu = new MenuItemCollection(); // if the user's start node is not the root then the only menu item to display is refresh if (UserStartNodes.Contains(Constants.System.Root) == false) { menu.Items.Add <RefreshNode, ActionRefresh>( Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)), true); return(menu); } //set the default to create menu.DefaultMenuAlias = ActionNew.Instance.Alias; // we need to get the default permissions as you can't set permissions on the very root node //TODO: Use the new services to get permissions var nodeActions = global::umbraco.BusinessLogic.Actions.Action.FromString( UmbracoUser.GetPermissions(Constants.System.Root.ToInvariantString())) .Select(x => new MenuItem(x)); //these two are the standard items menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias)); menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(null, "content", "content"); //filter the standard items FilterUserAllowedMenuItems(menu, nodeActions); if (menu.Items.Any()) { menu.Items.Last().SeperatorBefore = true; } // add default actions for *all* users menu.Items.Add <ActionRePublish>(ui.Text("actions", ActionRePublish.Instance.Alias)).ConvertLegacyMenuItem(null, "content", "content"); menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); return(menu); } //return a normal node menu: int iid; if (int.TryParse(id, out iid) == false) { throw new HttpResponseException(HttpStatusCode.NotFound); } var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Document); if (item == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //if the user has no path access for this node, all they can do is refresh if (Security.CurrentUser.HasPathAccess(item, Services.EntityService, RecycleBinId) == false) { var menu = new MenuItemCollection(); menu.Items.Add <RefreshNode, ActionRefresh>( Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)), true); return(menu); } var nodeMenu = GetAllNodeMenuItems(item); //if the content node is in the recycle bin, don't have a default menu, just show the regular menu if (item.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString())) { nodeMenu.DefaultMenuAlias = null; nodeMenu = GetNodeMenuItemsForDeletedContent(item); } else { //set the default to create nodeMenu.DefaultMenuAlias = ActionNew.Instance.Alias; } var allowedMenuItems = GetAllowedUserMenuItemsForNode(item); FilterUserAllowedMenuItems(nodeMenu, allowedMenuItems); return(nodeMenu); }
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings) { var menu = new MenuItemCollection(); //set the default menu.DefaultMenuAlias = ActionNew.Instance.Alias; if (id == Constants.System.Root.ToInvariantString()) { //if the user's start node is not the root then ensure the root menu is empty/doesn't exist if (Security.CurrentUser.StartMediaId != Constants.System.Root) { return(menu); } // root actions menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias)); menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(null, "media", "media"); menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); return(menu); } int iid; if (int.TryParse(id, out iid) == false) { throw new HttpResponseException(HttpStatusCode.NotFound); } var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Media); if (item == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //return a normal node menu: menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias)); menu.Items.Add <ActionMove>(ui.Text("actions", ActionMove.Instance.Alias)); menu.Items.Add <ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias)); menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias)).ConvertLegacyMenuItem(item, "media", "media"); menu.Items.Add <ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); //if the media item is in the recycle bin, don't have a default menu, just show the regular menu if (item.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString())) { menu.DefaultMenuAlias = null; } return(menu); }
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings) { var menu = new MenuItemCollection(); //set the default menu.DefaultMenuAlias = ActionNew.Instance.Alias; if (id == Constants.System.Root.ToInvariantString()) { // if the user's start node is not the root then the only menu item to display is refresh if (UserStartNodes.Contains(Constants.System.Root) == false) { menu.Items.Add <RefreshNode, ActionRefresh>( Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)), true); return(menu); } // root actions menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias)); menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(null, "media", "media"); menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); return(menu); } int iid; if (int.TryParse(id, out iid) == false) { throw new HttpResponseException(HttpStatusCode.NotFound); } var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Media); if (item == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //if the user has no path access for this node, all they can do is refresh if (Security.CurrentUser.HasPathAccess(item, Services.EntityService, RecycleBinId) == false) { menu.Items.Add <RefreshNode, ActionRefresh>( Services.TextService.Localize(string.Concat("actions/", ActionRefresh.Instance.Alias)), true); return(menu); } //if the media item is in the recycle bin, we don't have a default menu and we need to show a limited menu if (item.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString())) { menu.Items.Add <ActionRestore>(ui.Text("actions", ActionRestore.Instance.Alias)); menu.Items.Add <ActionMove>(ui.Text("actions", ActionMove.Instance.Alias)); menu.Items.Add <ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias)); menu.Items.Add <RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); menu.DefaultMenuAlias = null; } else { //return a normal node menu: menu.Items.Add <ActionNew>(ui.Text("actions", ActionNew.Instance.Alias)); menu.Items.Add <ActionMove>(ui.Text("actions", ActionMove.Instance.Alias)); menu.Items.Add <ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias)); menu.Items.Add <ActionSort>(ui.Text("actions", ActionSort.Instance.Alias)).ConvertLegacyMenuItem(item, "media", "media"); menu.Items.Add <ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true); //set the default to create menu.DefaultMenuAlias = ActionNew.Instance.Alias; } return(menu); }