cancel
Showing results for 
Search instead for 
Did you mean: 

Checking group membership in JavaScript

dpatri
Champ in-the-making
Champ in-the-making
Is there a way to check group membership of the current logged in user using JavaScript? Based on if a user is part of a group I want to display different information (and want to do it within a freemarker template and not directly in the JSP).

Thanks.
7 REPLIES 7

dpatri
Champ in-the-making
Champ in-the-making
Also, I am using alfresco version 1.4.2.. Do I have to upgrade to 2.0?

kevinr
Star Contributor
Star Contributor
Yes i'm afraid it's only available in 2.0:
http://wiki.alfresco.com/wiki/JavaScript_API#People_API

dpatri
Champ in-the-making
Champ in-the-making
So if I upgraded to 2.0 and tried:

<#assign myGroup = people.getGroup("myGroup")><#if (myGroup.hasPermission("Read")) etc…‍‍‍‍

Should something like the above work?

kevinr
Star Contributor
Star Contributor
The first line would work yes, and you can then extract the members (people) of the group and manipulate them. The second line you post does would not work - the hasPermission() check currently only checks for permissions of the current user.

Thanks,

Kevin

dpatri
Champ in-the-making
Champ in-the-making
I have upgraded to 2.0.1 enterprise edition, and when I try to use
<#assign taxGroup = people.getGroup("GROUP_grpOBITax")>‍
I get:
freemarker.core.InvalidReferenceException: Expression people is undefined on line 137, column 37
What am I doing wrong?

Thanks for your help.

kevinr
Star Contributor
Star Contributor
Sorry that should be:
var taxGroup = people.getGroup("GROUP_grpOBITax");

as the People object is part of the JavaScript API - not the freemarker templating API.

Thanks,

Kevin

dpatri
Champ in-the-making
Champ in-the-making
Thanks for that. I am a bit confused, perhaps I am not understanding everything. What I have done is customized a JSP, and within the JSP I have inserted some freemarker templates (using the <r:template….). This way I have it spaced out exactly as I need.

I have created these freemarker templates, because I want them to be located within the repository and be able to be edited, without having to change the JSP and rebuild the war file. (similar to how I created custom dashlets for the dashboard).

That being said, one of the templates shows different text (in fact, it uses the workflow command processor to approve/reject). Therefore I need to limit it based on group membership.

I had attempted to do it with freemarker, but in light of the people object only being available in the JavaScript API, how would you suggest I go about changing how I have developed this to work. Maybe I went about this the wrong way. Is there even a way to use the server-side JavaScript API within freemarker?

Thanks for your help.