Copied to clipboard

Flag this post as spam?

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


  • Stefano Beretta 102 posts 247 karma points
    Mar 08, 2019 @ 14:00
    Stefano Beretta
    0

    User permission: show only "Created by ME" nodes

    Hi everyone!

    I've this scenario and I don't know if it's achievable:

    I should ensure some users (U1, U2, U3...) can create/edit nodes under a "News" parent node, but I don't want U1 to see/edit the nodes created by other users.

    Every user should see/edit the nodes he has created himself. Is this behaviour achievable?

    Thank you

    S

  • suman 30 posts 101 karma points
    Jul 29, 2019 @ 17:18
    suman
    0

    @Stefano Beretta,

    Did u solve this puzzle. As we have same requirement. If you solved this, Can you please help me.

    Thank you.

  • Stefano Beretta 102 posts 247 karma points
    Jul 30, 2019 @ 07:18
    Stefano Beretta
    0

    Hi Suman!

    Yes, I did it! :D

    In the ApplicationStarted you can register a specific event TreeControllerBase.TreeNodesRendering and then manipulate the event args (the nodes).

    Here's the topic where I found the code

    and here's my code (tested on Umbraco 7.14+):

     public class UmbracoBootstrapper : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication,
                ApplicationContext applicationContext)
            {
                // register the event listener:
                TreeControllerBase.TreeNodesRendering += TreeControllerBase_TreeNodesRendering;
            }
    
            void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
            {
                var cs = ApplicationContext.Current.Services.ContentService;
                //filter by tree type and by user type
                if (sender.TreeAlias == "content" && sender.Security.CurrentUser.UserType.Alias != "admin")
                {
                    //remove all nodes not created by the current user
                    e.Nodes
                        .RemoveAll(x =>
                        cs.GetById(int.Parse(x.Id.ToString()))?.CreatorId != sender.Security.CurrentUser.Id
                        &&
                        x.AdditionalData.Select(y => y.Key).Contains("contentType")
                        &&
                        x.AdditionalData["contentType"].ToString() == "page"
                        );
                }
            }
        }
    

    I hope that's what you need :D

    S

  • suman 30 posts 101 karma points
    Jul 30, 2019 @ 08:09
    suman
    1

    Hi Stefano Beretta,

    Good Afternoon...!

    Thank you very much for your reply. It worked for me also.

    You saved a lot of time.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies