AnsweredAssumed Answered

isAdmin in java files?

Question asked by jriker1 on Sep 27, 2009
Latest reply on Sep 27, 2009 by jriker1
This is related to my other thread on JS files, however now that with the help of Mike I have overcome that, have possibly one more hurdle to tackle.  I need to check if someone is an admin in Java files.  One of which is specifically  If I comment out a bit of code like the below:

   private void checkManagerRole(String userId, Invitation.ResourceType resourceType, String siteShortName)
      // if inviter is not the site manager then throw web script exception
      String inviterRole = this.siteService.getMembersRole(siteShortName,
/*      if ((inviterRole == null)
            || (inviterRole.equals(SiteModel.SITE_MANAGER) == false)
            || !(authorityService.hasAdminAuthority())  )
         Object objs[] = { userId, siteShortName };
         throw new InvitationExceptionForbidden(
               "invitation.invite.not_site_manager", objs);
      } */

I can execute site manager activities.  I however have not been able to get the above block to work specifically with checking if they are an admin and then allowing them to execute the activity.  I have imported:


and added:

private AuthorityService authorityService;

also added:

     * @param authorityService  authorityService
    public void setAuthorityService(AuthorityService authorityService)
        this.authorityService = authorityService;

and as you can see from the original code block added:

|| !(authorityService.hasAdminAuthority())

to the original code block.  It errors and I get a NULL in the logs.  All I did above was mostly from looking at other similar code.  Any help in how to check if the current  user is an admin in the checkManagerRole and make the system assume they are a site manager would be appreciated.