cancel
Showing results for 
Search instead for 
Did you mean: 

collaboration-title.get.js accessing people object

jriker1
Champ in-the-making
Champ in-the-making
I want to check if an individual is an admin in a js file.  I have seen a reference to people.isAdmin(person) == true however I get a

08210000 ReferenceError: "people" is not defined. (file:/srv/tomcat6/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/title/collaboration-title.get.js#25

Message.  How do I make the people object available to the JS file so it can check if the current user is an admin.

Thanks.

JR
8 REPLIES 8

mrogers
Star Contributor
Star Contributor
Your problem is that your script is in the "share" webapp.   And that does not have access to the local alfresco Java Script objects such as people.

One way of solving this is to use a webscript that pulls data from the repo, where it can run your java script.

jriker1
Champ in-the-making
Champ in-the-making
Your problem is that your script is in the "share" webapp.   And that does not have access to the local alfresco Java Script objects such as people.

One way of solving this is to use a webscript that pulls data from the repo, where it can run your java script.

Thanks for the reply.  As you can imagine my next inquiry.  Since I am still learning the framework do you have an example in my situation on how to accomplish this?  Or perhaps an example where this is used actively in the current code?

Thanks.

JR

mikeh
Star Contributor
Star Contributor
header.get.html.ftl in Share: user.isAdmin

Mike

jriker1
Champ in-the-making
Champ in-the-making
header.get.html.ftl in Share: user.isAdmin

Mike

Thanks for the reply Mike.  Per original request I am looking for where this is used in the JS file.  I need to make the system feel that anyone who is an adminstrator is also a site manager for a site so they can manage users when needed, or when the sync job blows an admin away without checking that there is at least one admin left on the site before doing so.  I am trying to do it in this block of code:

// if (json.status == 200 || people.isAdmin(person) == true)
if (json.status == 200)
{
   var obj = eval('(' + json + ')');
   userIsMember = true;
   userIsSiteManager = obj.role == "SiteManager";
  
   // Stse the memberships into the request context, it is used
   // downstream by other components - saves making same call many times
   context.setValue("memberships", obj);
}

The commented out line above is what I'm trying to make work.  Any thoughts?

JR

mikeh
Star Contributor
Star Contributor
header.get.html.ftl in Share: user.isAdmin

Mike

The commented out line above is what I'm trying to make work.  Any thoughts?

JR

Did you try user.isAdmin..?

Mike

jriker1
Champ in-the-making
Champ in-the-making
Did you try user.isAdmin..?

Mike

Didn't expect this would work, got:

08250000 TypeError: isAdmin is not a function, it is java.lang.Boolean. (file:/srv/tomcat6/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/title/collaboration-title.get.js#29)

Remember I am trying to find out if a user is an admin in the collaboration-title.get.js file.  Not in one of the ftl files.

Thanks.

JR

mikeh
Star Contributor
Star Contributor
The error describes the problem: you're trying user.isAdmin() instead of user.isAdmin

Mike

jriker1
Champ in-the-making
Champ in-the-making
The error describes the problem: you're trying user.isAdmin() instead of user.isAdmin

Mike

Bingo.  That worked.  Thanks a bunch.

I can now see the same buttons in the rooms as the site managers can being an admin.  Of course you all have code a bit deeper to check again on site manager status before allowing someone to add someone as a member of the site so looks like I have to now drill down a bit deeper in the code to assign a site manager OR a admin the ability to add users to sites.  I'm thinking from the logs invitation.post.json.js might be a good place to start looking.

Thanks.

JR