Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Colin Anderson 16 posts 107 karma points
    Feb 13, 2020 @ 11:35
    Colin Anderson
    0

    Adding custom context menu items to Umbraco 8

    I have managed to create a custom context menu item in Umbraco 8 using a Component and a Composer.

    The problem I have is that the new context menu item is available on every node (including Content and recycle bin) and for every user.

    Is it possible to restrict it to specific users/groups and to only show for a specific tree level?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 13, 2020 @ 12:01
    Kevin Jump
    100

    Hi Colin,

    Yes, you can get the current users assigned permissions within your MenuRendering method

    var permissions = sender.Services.UserService.GetPermissions(sender.Security.CurrentUser, nodeId);
    

    you can then check these either against inbuild permission actions or your own custom ones (implement IAction to make custom ones) for example

    if (permissions.Any(x => x.AssignedPermissions.Contains(ActionPublish.ActionLetter))) {
       /// user has publish permissions 
    }
    

    you can restrict by node based on the ID the recylce bin has a special ID.

    so you can check if the node id passed matches that and ignore it.

    if (nodeId.Equals(Constants.System.RecycleBinContentString)) {
         // in the bin
    }
    

    see https://github.com/umbraco/Umbraco-CMS/tree/v8/contrib/src/Umbraco.Web/Actions for the inbuilt action classes

  • Colin Anderson 16 posts 107 karma points
    Feb 13, 2020 @ 12:20
    Colin Anderson
    0

    Thanks Kevin, that did the trick.

Please Sign in or register to post replies

Write your reply to:

Draft