mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Site Service: expose methods to get group names and available site roles
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10479 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -154,6 +154,13 @@ public interface SiteService
|
||||
*/
|
||||
boolean hasContainer(String shortName, String componentId);
|
||||
|
||||
/**
|
||||
* Gets a list of all the currently available roles that a user can perform on a site
|
||||
*
|
||||
* @return List<String> list of availble roles
|
||||
*/
|
||||
List<String> getSiteRoles();
|
||||
|
||||
/**
|
||||
* Gets the sites group. All members of the site are contained within this group.
|
||||
*
|
||||
|
@@ -604,6 +604,15 @@ public class SiteServiceImpl implements SiteService, SiteModel
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.site.SiteService#getSiteRoles()
|
||||
*/
|
||||
public List<String> getSiteRoles()
|
||||
{
|
||||
Set<String> permissions = permissionService.getSettablePermissions(SiteModel.TYPE_SITE);
|
||||
return new ArrayList<String>(permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.site.SiteService#isMember(java.lang.String, java.lang.String)
|
||||
|
@@ -566,6 +566,18 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
||||
assertEquals(ForumModel.TYPE_FORUM, nodeService.getType(container8));
|
||||
}
|
||||
|
||||
public void testSiteGetRoles()
|
||||
{
|
||||
List<String> roles = this.siteService.getSiteRoles();
|
||||
assertNotNull(roles);
|
||||
assertFalse(roles.isEmpty());
|
||||
|
||||
// for (String role : roles)
|
||||
// {
|
||||
// System.out.println("Role: " + role);
|
||||
// }
|
||||
}
|
||||
|
||||
// == Test the JavaScript API ==
|
||||
|
||||
public void testJSAPI() throws Exception
|
||||
|
@@ -140,4 +140,15 @@ public class ScriptSiteService extends BaseScopableProcessorExtension
|
||||
}
|
||||
return site;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the roles that can be assigned to a memeber of a site.
|
||||
*
|
||||
* @return String[] roles available to assign to a member of a site
|
||||
*/
|
||||
public String[] listSiteRoles()
|
||||
{
|
||||
List<String> roles = this.siteService.getSiteRoles();
|
||||
return (String[])roles.toArray(new String[roles.size()]);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
package org.alfresco.repo.site.script;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -56,6 +57,10 @@ public class Site implements Serializable
|
||||
/** Site information */
|
||||
private SiteInfo siteInfo;
|
||||
|
||||
/** Site group information */
|
||||
private String siteGroup;
|
||||
private ScriptableHashMap<String, String> siteRoleGroups;
|
||||
|
||||
/** Services Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@@ -180,6 +185,41 @@ public class Site implements Serializable
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the site group name
|
||||
*
|
||||
* @return String site group name
|
||||
*/
|
||||
public String getSiteGroup()
|
||||
{
|
||||
if (this.siteGroup == null)
|
||||
{
|
||||
this.siteGroup = this.siteService.getSiteGroup(this.siteInfo.getShortName());
|
||||
}
|
||||
return this.siteGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a map of role name mapping to associated group name.
|
||||
*
|
||||
* @return ScriptableMap<String, String> map of role to group name
|
||||
*/
|
||||
public ScriptableHashMap<String, String> getSitePermissionGroups()
|
||||
{
|
||||
if (this.siteRoleGroups == null)
|
||||
{
|
||||
List<String> roles = this.siteService.getSiteRoles();
|
||||
this.siteRoleGroups = new ScriptableHashMap<String, String>();
|
||||
for (String role : roles)
|
||||
{
|
||||
this.siteRoleGroups.put(
|
||||
role,
|
||||
this.siteService.getSiteRoleGroup(this.siteInfo.getShortName(), role));
|
||||
}
|
||||
}
|
||||
return this.siteRoleGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves any outstanding updates to the site details.
|
||||
* <p>
|
||||
|
@@ -196,9 +196,29 @@ function testPermissions()
|
||||
site.resetAllPermissions(container);
|
||||
}
|
||||
|
||||
function testRolesAndGroups()
|
||||
{
|
||||
var roles = siteService.listSiteRoles();
|
||||
test.assertNotNull(roles);
|
||||
test.assertFalse(roles.length == 0);
|
||||
|
||||
var site = siteService.createSite("sitePreset", "sn", "siteTitle", "siteDescription", false);
|
||||
var siteGroup = site.siteGroup;
|
||||
test.assertNotNull(siteGroup);
|
||||
test.assertEquals("GROUP_site_sn", siteGroup);
|
||||
|
||||
var groups = site.sitePermissionGroups;
|
||||
test.assertNotNull(groups);
|
||||
test.assertEquals("GROUP_site_sn_SiteManager", groups.SiteManager);
|
||||
test.assertEquals("GROUP_site_sn_SiteConsumer", groups.SiteConsumer);
|
||||
test.assertEquals("GROUP_site_sn_SiteCollaborator", groups.SiteCollaborator);
|
||||
|
||||
}
|
||||
|
||||
// Execute test's
|
||||
testCRUD();
|
||||
testListSites();
|
||||
testMembership();
|
||||
testContainer();
|
||||
testPermissions();
|
||||
testPermissions();
|
||||
testRolesAndGroups();
|
Reference in New Issue
Block a user