/// <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 ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings) { if (RecycleBinId.ToInvariantString() == id) { // get the default assigned permissions for this user var deleteAllowed = false; var deleteAction = _actionCollection.FirstOrDefault(y => y.Letter == ActionDelete.ActionLetter); if (deleteAction != null) { var perms = _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.GetPermissions(Constants.System.RecycleBinContentString, _userService); deleteAllowed = perms?.FirstOrDefault(x => x.Contains(deleteAction.Letter)) != null; } var menu = MenuItemCollectionFactory.Create(); // only add empty recycle bin if the current user is allowed to delete by default if (deleteAllowed) { menu.Items.Add(new MenuItem("emptyrecyclebin", LocalizedTextService) { Icon = "icon-trash", OpensDialog = true, UseLegacyIcon = false, }); menu.Items.Add(new RefreshNode(LocalizedTextService, true)); } return(menu); } return(PerformGetMenuForNode(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 deleteAllowed = false; var deleteAction = Current.Actions.FirstOrDefault(y => y.Letter == ActionDelete.ActionLetter); if (deleteAction != null) { var perms = Security.CurrentUser.GetPermissions(Constants.System.RecycleBinContentString, Services.UserService); deleteAllowed = perms.FirstOrDefault(x => x.Contains(deleteAction.Letter)) != null; } var menu = new MenuItemCollection(); // only add empty recycle bin if the current user is allowed to delete by default if (deleteAllowed) { menu.Items.Add(new MenuItem("emptyRecycleBin", Services.TextService) { Icon = "trash", OpensDialog = true }); menu.Items.Add(new RefreshNode(Services.TextService, true)); } return(menu); } return(PerformGetMenuForNode(id, queryStrings)); }
/// <summary> /// Adds menu items to each node /// </summary> /// <param name="n"></param> /// <param name="queryStrings"></param> protected override void AddMenuItemsToNode(TreeNode n, FormCollection queryStrings) { if (!queryStrings.GetValue <bool>(TreeQueryStringParameters.DialogMode)) { //add the menu items n.AddEditorMenuItem <CreateItem>(this, "createUrl", "CreateNew"); //we need to add the recycle bin Id to the metadata so that the UI knows to refresh the bin on delete n.AddEditorMenuItem <Delete>(this, "deleteUrl", "Delete", new Dictionary <string, object> { { "recycleBinId", RecycleBinId.ToJsonObject() } }); n.AddEditorMenuItem <Move>(this, "moveUrl", "Move"); n.AddEditorMenuItem <Copy>(this, "copyUrl", "Copy"); n.AddEditorMenuItem <Sort>(this, "sortUrl", "Sort"); n.AddEditorMenuItem <Rollback>(this, "rollbackUrl", "Rollback"); n.AddEditorMenuItem <Publish>(this, "publishUrl", "Publish"); n.AddEditorMenuItem <Permissions>(this, "permissionsUrl", "Permissions"); //n.AddMenuItem<Protect>(); //n.AddMenuItem<Audit>(); //n.AddMenuItem<Notify>(); //nodeData.treeNode.AddMenuItem<SendTranslate>(MenuItems); n.AddEditorMenuItem <Hostname>(this, "hostnameUrl", "Hostname"); n.AddEditorMenuItem <Language>(this, "languageUrl", "Language"); n.AddMenuItem <Reload>(); } }
/// <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) { var menu = new MenuItemCollection(); 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> /// 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) { var menu = new MenuItemCollection(); menu.Items.Add(new MenuItem("emptyRecycleBin", Services.TextService) { Icon = "trash", OpensDialog = true }); menu.Items.Add(new RefreshNode(Services.TextService, 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 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)); }
public override JsonResult Delete(HiveId?id) { //TODO: When deleting an item, do we remove any domains assigned to it ? Mandate.ParameterNotEmpty(id, "id"); using (var uow = Hive.Create <IContentStore>()) { //get the entity and we need to change the content tree relation type to the deleted relation type var entity = uow.Repositories.Get(id.Value); var ancestors = uow.Repositories.GetAncestorRelations(entity, FixedRelationTypes.DefaultRelationType); //check if this node is in the recycle bin, if so just delete it if (RecycleBinId.IsNullValueOrEmpty() || ancestors.Select(x => x.SourceId).Contains(RecycleBinId, new HiveIdComparer(true))) { // Delete hostnames var hostnameRelations = entity.RelationProxies.GetChildRelations(FixedRelationTypes.HostnameRelationType); foreach (var hostnameRelation in hostnameRelations) { uow.Repositories.Delete <TypedEntity>(hostnameRelation.Item.DestinationId); } uow.Repositories.Delete <TypedEntity>(entity.Id); } else { //var contentParents = entity.RelationProxies.GetParentRelations(FixedRelationTypes.ContentTreeRelationType); var contentParents = ancestors.Where(x => x.DestinationId == entity.Id); foreach (var c in contentParents) { //change original relation type to RecycledTreeRelation uow.Repositories.ChangeRelationType(c, FixedRelationTypes.RecycledRelationType); //add new content relation type to exist under the recycle bin uow.Repositories.AddRelation(RecycleBinId, entity.Id, FixedRelationTypes.DefaultRelationType, 0); } uow.Repositories.AddOrUpdate(entity); } uow.Complete(); } //clears the domain cache BackOfficeRequestContext.RoutingEngine.ClearCache(clearDomains: true, clearGeneratedUrls: true); //return a successful JSON response return(Json(new { message = "Success" })); }
/// <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); }