cancel
Showing results for 
Search instead for 
Did you mean: 

Get the users from the subgroups of a group

andreim
Champ in-the-making
Champ in-the-making
Hi ,

Is there a way to customize the web scripts , so that when I request the users of a group , all the users , including the ones from the group's subgroups will be returned ?
For example , I have a group called G1 which has two subgroups , SG1 and SG2.
SG1 has the users User1 , User2 and User3.
SG1 has the users User4 , User5 and User6.

If I use the GET /alfresco/service/api/groups/G1/children api , Alfresco will return SG1 and SG2.
Is there a way to make a similar api that returns for the G1 group User1…User6 ?

Thanks in advance,
Andrei
4 REPLIES 4

mrogers
Star Contributor
Star Contributor
Yes the authority service can return all users rather than just the immediate users   There's a boolean flag to say whether it's just immediate children that are required.    I think this is already exposed on the Java Script API.

Its entirely possible to expose this via REST,  just be careful of how you handle large result sets which need to be paged before considering this change.

jayjayecl
Confirmed Champ
Confirmed Champ
Hi,

enhancing mrogers' answer :

- if you use a JS backed webscript, here you are :
http://wiki.alfresco.com/wiki/3.2_JavaScript_API#People_API

Array getMembers(ScriptNode group, boolean recurse)
    Returns an Array of people nodes belonging to the specified group. People of sub-groups are only returned if recurse is specified as true.

- if you use a Java backed webscript, here you are :

authorityService.getContainedAuthorities(AuthorityType authType, String authName, Boolean recursive);

andreim
Champ in-the-making
Champ in-the-making
Thank you for your replies.
I've tried to make a web script using the getMembers function , but I get the following error :
{
    "status" :
  {
    "code" : 500,
    "name" : "Internal Error",
    "description" : "An error inside the HTTP server which prevented it from fulfilling the request.
"
  }, 
 
  "message" : "06300044 Wrapped Exception (with status template): 06300043 Failed to execute script '
\/org\/alfresco\/repository\/person\/customGroupMembers.get.js (in classpath store file:C:\/Alfresco
\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts)': 06300042 Can't find
method org.alfresco.repo.jscript.People.getMembers(org.alfresco.repo.security.authority.script.ScriptGroup
,boolean). (file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts
\/org\/alfresco\/repository\/person\/customGroupMembers.get.js#10)", 
  "exception" : "org.alfresco.web.scripts.WebScriptException - 06300044 Wrapped Exception (with status
template): 06300043 Failed to execute script '\/org\/alfresco\/repository\/person\/customGroupMembers
.get.js (in classpath store file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco
\/templates\/webscripts)': 06300042 Can't find method org.alfresco.repo.jscript.People.getMembers(org
.alfresco.repo.security.authority.script.ScriptGroup,boolean). (file:C:\/Alfresco\/tomcat\/webapps\/alfresco
\/WEB-INF\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers
.get.js#10)",
 
  "callstack" :
  [
       ""      ,"org.mozilla.javascript.EvaluatorException: Can't find method org.alfresco.repo.jscript
.People.getMembers(org.alfresco.repo.security.authority.script.ScriptGroup,boolean). (file:C:\/Alfresco
\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository
\/person\/customGroupMembers.get.js#10)"
      ,"org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)"
      ,"org.mozilla.javascript.Context.reportRuntimeError(Context.java:1030)"
      ,"org.mozilla.javascript.Context.reportRuntimeError(Context.java:1086)"
      ,"org.mozilla.javascript.Context.reportRuntimeError1(Context.java:1049)"
      ,"org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:162)"
      ,"org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)"
      ,"org.mozilla.javascript.gen.c13._c0(file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes
\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers.get.js:10)"
      ,"org.mozilla.javascript.gen.c13.call(file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes
\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers.get.js)"
      ,"org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)"
      ,"org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)"
      ,"org.mozilla.javascript.gen.c13.call(file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes
\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers.get.js)"
      ,"org.mozilla.javascript.gen.c13.exec(file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes
\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers.get.js)"
      ,"org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:449
)"
      ,"org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:174)"
      ,"org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:274)"
      ,"org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor
.java:108)"
      ,"org.alfresco.web.scripts.AbstractWebScript.executeScript(AbstractWebScript.java:819)"
      ,"org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:90)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:357)"
      ,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper
.java:326)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java
:407)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer
.java:424)"
      ,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:288
)"
      ,"org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:262)"
      ,"org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)"
      ,"org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122)"
      ,"javax.servlet.http.HttpServlet.service(HttpServlet.java:717)"
      ,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java
:290)"
      ,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)"
      ,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)"
      ,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)"
      ,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)"
      ,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)"
      ,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)"
      ,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)"
      ,"org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)"
      ,"org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583
)"
      ,"org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)"
      ,"java.lang.Thread.run(Thread.java:619)"
      ,"org.alfresco.error.AlfrescoRuntimeException: 06300042 Can't find method org.alfresco.repo.jscript
.People.getMembers(org.alfresco.repo.security.authority.script.ScriptGroup,boolean). (file:C:\/Alfresco
\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository
\/person\/customGroupMembers.get.js#10)"
      ,"org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:465
)"
      ,"org.alfresco.scripts.ScriptException: 06300043 Failed to execute script '\/org\/alfresco\/repository
\/person\/customGroupMembers.get.js (in classpath store file:C:\/Alfresco\/tomcat\/webapps\/alfresco
\/WEB-INF\/classes\/alfresco\/templates\/webscripts)': 06300042 Can't find method org.alfresco.repo.jscript
.People.getMembers(org.alfresco.repo.security.authority.script.ScriptGroup,boolean). (file:C:\/Alfresco
\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository
\/person\/customGroupMembers.get.js#10)"
      ,"org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:178)"
      ,"org.alfresco.web.scripts.WebScriptException: 06300044 Wrapped Exception (with status template
😞 06300043 Failed to execute script '\/org\/alfresco\/repository\/person\/customGroupMembers.get.js
(in classpath store file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF\/classes\/alfresco\/templates
\/webscripts)': 06300042 Can't find method org.alfresco.repo.jscript.People.getMembers(org.alfresco.repo
.security.authority.script.ScriptGroup,boolean). (file:C:\/Alfresco\/tomcat\/webapps\/alfresco\/WEB-INF
\/classes\/alfresco\/templates\/webscripts\/org\/alfresco\/repository\/person\/customGroupMembers.get
.js#10)"
      ,"org.alfresco.web.scripts.AbstractWebScript.createStatusException(AbstractWebScript.java:613)
"

  ],
 
  "server" : "Alfresco Community v3.2.0 (2039) schema 2,019",
  "time" : "Jul 30, 2009 4:06:00 PM"
}


The code of my js file , customGroupMembers.get.js is as follows :
var urlElements = url.extension.split("/");
var shortName = urlElements[0];
var theGroup = groups.getGroup(shortName); 

if (theGroup == null)
{
    // Group cannot be found
    status.setCode(status.STATUS_NOT_FOUND, "The group :" + shortName + ", does not exist.");
} else {  
    var peopleCollection = people.getMembers(theGroup, true);
    model.peoplelist = peopleCollection;
}

The code of my decription file is :
<webscript>
   <shortname>Get the list of all the people of a group.</shortname>
   <description><![CDATA[
   Get the list of all the people of a group.
   <BR />
   ]]>
   </description>
   <url>/api/person/{shortName}/customGroupMembers</url>
   <format default="json">argument</format>
   <authentication>user</authentication>
   <transaction allow="readonly">required</transaction>
   <lifecycle>draft_public_api</lifecycle>
</webscript>
The shortName parameter is supposed to be the name of the group.

The code of my ftl file :
<#import "person.lib.ftl" as personLib/>
{
"people" : [
   <#list peoplelist as person>
      <@personLib.personJSON person=person/>
      <#if person_has_next>,</#if>
   </#list>
]
}

Could you please tell me where am I making a mistake ?

Thanks
Andrei

andreim
Champ in-the-making
Champ in-the-making
I've found a workaround this issue by using the following code in the js file:

function main()
{
    var groupName = url.extension;
    var theGroup = groups.getGroup(groupName);
    var theUsers = theGroup.getAllUsers();
    var personsArray = [];
   
    for (var j = 0; j < theUsers.length; j++) {
        var userName = theUsers[j].shortName;
        var person = people.getPerson(userName);
        personsArray.push(person);
    }

    model.peoplelist = personsArray;
}

main();

For some reason , the people.getMembers(groupNode) and people.getGroup(groupName) methods do not work , and I get error messages if I use them.