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

Forums / Developing with Sitefinity / How to get all users who can approve an event?

How to get all users who can approve an event?

7 posts, 1 answered
  1. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    21 Oct 2009
    Link to this post
    Hi,

    I want to send an e-mail to all users who can approve an event, without regards to which role they belong to.

    Thanks,
    Michael
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Oct 2009
    Link to this post
    Hi Michael Chan Fong,

    Below is a sample code that illustrates how to get the workflow permissions and check them.

    // GET THE MODULE
        ISecuredModule module = ModuleManager.WebModules["events"] as ISecuredModule;
        if (module != null)
        {
            // GET THE APPLICATION PERMISSIONS
            IDictionary<string, ApplicationPermission> permissions;
            ISecured secObj = module.SecurityRoot;
            if (secObj is ISecuredBase)
                permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
            else
                permissions = secObj.Permissions;
             
            // WE WILL MAKE IT ONLY FOR ONE ROLE FOR DEMONSTRATIVE PURPOSES
            string roleName = "restrictedrole";
            bool hasApprovePermission = false;
     
            ApplicationPermission perm;
            if (permissions.TryGetValue(roleName, out perm))
            {
                hasApprovePermission = HasPermission(perm, WorkflowRights.Approve);
                 //IF TRUE SEND YOUR EMAIL
            }
        }
    }
         
        // CREATE A HELPER METHOD
        private bool HasPermission(ApplicationPermission perm, int right)
        {
            return ((perm.Grant & right) == right) && ((perm.Deny & right) == 0);
        }

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    21 Oct 2009
    Link to this post
    Hi Ivan,

    Thanks for the quick reply.

    I am getting an exception at:
    ISecured secObj = module.SecurityRoot;

    'module.SecurityRoot' threw an exception of type 'System.Collections.Generic.KeyNotFoundException'

    Thanks,
    Michael
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Oct 2009
    Link to this post
    Hello Michael Chan Fong,

    Add the highlighted attribute to the line shown below

    web.config file

    <events defaultGenericProvider="Events" defaultProvider="Events" googleMapsAPIKey="" googleMapsAPIUrl="http://maps.google.com/maps?file=api&;v=2.x&key=" yahooMapsAPIKey="" yahooMapsAPIUrl="http://api.maps.yahoo.com/ajaxymap?v=3.7&;appid=" liveSearchMapsAPIUrl="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2">
            <genericContentProviders>
                <add providerName="Events" publicationDateField="Publication_Date" expirationDateField="Expiration_Date" eventStartField="Event_Start" eventEndField="Event_End" streetField="Street" cityField="City" countryField="Country" stateField="State" geomappingDataField="Geomapping_Data" urlRewriteFormat="[Publication_Date]/[Title].aspx" urlDateTimeFormat="yy-MM-dd" urlWhitespaceChar="_"/>
            </genericContentProviders>
        </events>


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    21 Oct 2009
    Link to this post
    Hi Ivan,

    I already had defaultGenericProvider="Events", but I did have to add defaultProvider="Events"; after which I did not get the exception anymore.

    There are two things that are not quite right:

    1. I get my role name through the API, like
    UserManager.Default.GetRolesForUser(user.UserName);
    The roles that come back have the correct casing, e.g. "Role 1".
    But this code
    permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
    will return "role 1" (all lower case).
    I modified the if statement to:
    if (permissions.TryGetValue(roleName.ToLower(), out perm))

    2. I suppose the "administrator" role is special because this code
    permissions = ((ISecuredBase)secObj).GetPermissions("Sitefinity");
    does not return "administrator" even though the latter has approval rights. I may be able to live with this, after all I may not want to always e-mail the administrators when there is an event to approve. Or I can add a special check for "administrator" role.

    Thanks a lot.
    Michael
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Oct 2009
    Link to this post
    Hi Michael Chan Fong,

    Administrators role is "special" - it is unrestricted role. So when you are sending email you can do it also for all unrestricted users from this role

    foreach (string role in UserManager.GetRolesForUser(user))
    if (Telerik.Security.Configuration.ConfigHelper.IsRoleUnrestricted(roleName))
    {
     // do something here
    }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  7. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    21 Oct 2009
    Link to this post
    Thanks Ivan.

    Regards,
    Michael

Register for webinar
7 posts, 1 answered