Copied to clipboard

Flag this post as spam?

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


  • iNETZO 93 posts 412 karma points
    Mar 11, 2018 @ 20:29
    iNETZO
    0

    GetPermissions always returns "Create"-permission

    Hi everybody,

    I've a problem with checking permissions on a node. I've made a custom documentcontroller for a newsitem. When the backoffice user is logged in, i would like to show a button at the frontend to edit the message. When i login at the backoffice with a useraccount which doesn't show the node in contenttree, the "permission.AssignedPermissions" in the code below always contains "C" (and F,D,U,O,M and S). It doesn't matter which nodeId i'm using, it always returns these permissions.

    I've uses this documentation https://our.umbraco.org/documentation/extending/section-trees/tree-actions#tree-actions

       public class NewsitemController : Umbraco.Web.Mvc.RenderMvcController
    {
        public ActionResult Edit(RenderModel model)
        {
            bool canCreateNode = false;
            var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
            if (userTicket != null)
            {
                var us = Services.UserService;
                var user = us.GetByUsername(userTicket.Name);
                if (user != null)
                {
                    var userPermissions = us.GetPermissions(user, new Int32[]{model.Content.Id});
    
                    foreach (var permission in userPermissions)
                    {
                        if (permission.AssignedPermissions.Contains("C"))
                        {
                            canCreateNode = true;
                        }
    
                    }
    
                    if (canCreateNode == true)
                    {
                        .....
                    }
    
                }
            }
    
            return Redirect(model.Content.Url);
        }
    

    The user is assigned to 1 group which has permission to 1 node which is not a newsitem. What can be the reason that GetPermissions returns the same permissions for every node?

    iNETZO

Please Sign in or register to post replies

Write your reply to:

Draft