mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Workflow (server-side) groups support
- assignment of groups to pooled tasks - retrieve group members added to javascript git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4805 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,8 +16,14 @@
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authority.AuthorityDAO;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
@@ -30,6 +36,7 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
private AuthorityDAO authorityDAO;
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
@@ -44,6 +51,16 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
this.services = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authority DAO
|
||||
*
|
||||
* @param authorityDAO authority dao
|
||||
*/
|
||||
public void setAuthorityDAO(AuthorityDAO authorityDAO)
|
||||
{
|
||||
this.authorityDAO = authorityDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@@ -55,6 +72,7 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
/**
|
||||
* Gets the Person given the username
|
||||
*
|
||||
* @param username the username of the person to get
|
||||
* @return the person node (type cm:person) or null if no such person exists
|
||||
*/
|
||||
public Node getPerson(String username)
|
||||
@@ -68,5 +86,88 @@ public final class People extends BaseScriptImplementation implements Scopeable
|
||||
}
|
||||
return person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Group given the group name
|
||||
*
|
||||
* @param groupName name of group to get
|
||||
* @return the group node (type usr:authorityContainer) or null if no such group exists
|
||||
*/
|
||||
public Node getGroup(String groupName)
|
||||
{
|
||||
Node group = null;
|
||||
NodeRef groupRef = authorityDAO.getAuthorityNodeRefOrNull(groupName);
|
||||
if (groupRef != null)
|
||||
{
|
||||
group = new Node(groupRef, services, scope);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the members (people) of a group (including all sub-groups)
|
||||
*
|
||||
* @param group the group to retrieve members for
|
||||
* @param recurse recurse into sub-groups
|
||||
* @return the members of the group
|
||||
*/
|
||||
public Node[] getMembers(Node group)
|
||||
{
|
||||
return getContainedAuthorities(group, AuthorityType.USER, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the members (people) of a group
|
||||
*
|
||||
* @param group the group to retrieve members for
|
||||
* @param recurse recurse into sub-groups
|
||||
* @return the members of the group
|
||||
*/
|
||||
public Node[] getMembers(Node group, boolean recurse)
|
||||
{
|
||||
return getContainedAuthorities(group, AuthorityType.USER, recurse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Contained Authorities
|
||||
*
|
||||
* @param container authority containers
|
||||
* @param type authority type to filter by
|
||||
* @param recurse recurse into sub-containers
|
||||
* @return contained authorities
|
||||
*/
|
||||
private Node[] getContainedAuthorities(Node container, AuthorityType type, boolean recurse)
|
||||
{
|
||||
Node[] members = null;
|
||||
if (container.getType().equals(ContentModel.TYPE_AUTHORITY_CONTAINER))
|
||||
{
|
||||
AuthorityService authorityService = services.getAuthorityService();
|
||||
String groupName = (String)container.getProperties().get(ContentModel.PROP_AUTHORITY_NAME);
|
||||
Set<String> authorities = authorityService.getContainedAuthorities(type, groupName, !recurse);
|
||||
members = new Node[authorities.size()];
|
||||
int i = 0;
|
||||
for (String authority : authorities)
|
||||
{
|
||||
AuthorityType authorityType = AuthorityType.getAuthorityType(authority);
|
||||
if (authorityType.equals(AuthorityType.GROUP))
|
||||
{
|
||||
Node group = getGroup(authority);
|
||||
if (group != null)
|
||||
{
|
||||
members[i++] = group;
|
||||
}
|
||||
}
|
||||
else if (authorityType.equals(AuthorityType.USER))
|
||||
{
|
||||
Node person = getPerson(authority);
|
||||
if (person != null)
|
||||
{
|
||||
members[i++] = person;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user