+1-888-365-2779
Try Now
More in this section

Forums / Security / Get permissions for Role 3.7

Get permissions for Role 3.7

7 posts, 2 answered
  1. Stuart
    Stuart avatar
    9 posts
    Registered:
    18 Jul 2007
    06 May 2010
    Link to this post
    I am trying to finish coding my email notification system.

    I have a list of roles (string[]) and I want to know how to find out if role[] has edit, approve and/or publish permission.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 May 2010
    Link to this post
    Hi Greg,

    I have a list of roles (string[]) and I want to know how to find out if role[] has edit, approve and/or publish permission.

    For which object you want to check the permissions? Is it of type Page, ContentItem or?

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Stuart
    Stuart avatar
    9 posts
    Registered:
    18 Jul 2007
    10 May 2010
    Link to this post
    On the news module, I wanted to see if a role (ex. "abc role") has edit, approve and/or publish.

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 May 2010
    Link to this post
    Hello Greg,

    Here is a sample code that you can use to check whether a given role has a View rights for the News module

    ISecuredModule module = ModuleManager.WebModules["news"] as ISecuredModule;
           if (module != null)
           {
               IDictionary<string, ApplicationPermission> permissions;
               ISecured secObj = module.SecurityRoot;
               if (secObj is ISecuredBase)
                   permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
               else
                   permissions = secObj.Permissions;
     
     
               string roleName = "test";
               bool hasApprovePermission = false;
               ApplicationPermission perm;
               if (permissions.TryGetValue(roleName, out perm))
               {
                   hasApprovePermission = HasPermission(perm, CrudRights.View);
                   if (hasApprovePermission)
                   {
                       Response.Write(roleName + "   has View permissions");
                   }
               }
           }
     
       }
       private bool HasPermission(ApplicationPermission perm, int right)
       {
           return ((perm.Grant & right) == right) && ((perm.Deny & right) == 0);
       }


    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  5. Stuart
    Stuart avatar
    9 posts
    Registered:
    18 Jul 2007
    10 May 2010
    Link to this post
    Thanks for the quick response.

    I am getting this error.  I am running this on my local machine and not on the production unit.  Not sure if that is because the license file is set up for our external domain.


    The given key was not present in the dictionary. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
      
    Exception Details: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
      
    Source Error: 
      
      
    Line 211:        {
    Line 212:            IDictionary<string, ApplicationPermission> permissions;
    Line 213:            ISecured secObj = module.SecurityRoot;
    Line 214:            if (secObj is ISecuredBase)
    Line 215:                permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
       
      
    Source File: c:\InMotion\Sitefinity\Admin\ControlTemplates\News\NewsItemPreview.ascx.cs    Line: 213
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 May 2010
    Link to this post
    Hello Greg,

    Add the defaultProvider property for news attribute

    <news defaultGenericProvider="News" defaultProvider="News">
     
     ....
             ...


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
    Answered
  7. Stuart
    Stuart avatar
    9 posts
    Registered:
    18 Jul 2007
    10 May 2010
    Link to this post
    You guys are making me look like great at work.  ;) , thanks for your help!
Register for webinar
7 posts, 2 answered