The containing groups for a user can now be optionally returned via the Person REST API.

Some cleanup to Person REST API templates scripts and tests.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13829 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2009-04-03 16:02:55 +00:00
parent 0e7976880c
commit 697f6da71b
7 changed files with 27 additions and 40 deletions

View File

@@ -2,11 +2,6 @@
var filter = args["filter"];
var maxResults = args["maxResults"];
if (filter)
{
filter = filter.replace('"', '');
}
// Get the collection of people
var peopleCollection = people.getPeople(filter, maxResults != null ? parseInt(maxResults) : 0);

View File

@@ -7,31 +7,11 @@ function main()
var person = people.getPerson(userName);
// if person is found matching the given user name
// then get that person's details to pass through
// to the template and then delete that person
// then delete that person
if (person != null)
{
// Get the person's details
var personDetails =
{
properties: []
}
personDetails.properties["userName"] = userName;
personDetails.properties["title"] = person.properties["title"];
personDetails.properties["firstName"] = person.properties["firstName"];
personDetails.properties["lastName"] = person.properties["lastName"];
personDetails.properties["organization"] = person.properties["organization"];
personDetails.properties["jobtitle"] = person.properties["jobtitle"];
personDetails.properties["email"] = person.properties["email"];
personDetails.assocs = {}; // fake the assocs object
// delete the person
people.deletePerson(userName);
// Put the person's details on the model to pass to the template
model.personDetails = personDetails;
}
// else if no person was found matching the given user name,
// then return HTTP error status "not found"

View File

@@ -1,2 +1 @@
<#import "person.lib.ftl" as personLib/>
<@personLib.personJSON person=personDetails/>
{}

View File

@@ -3,11 +3,15 @@ function main()
// Get the user name of the person to get
var userName = url.extension;
// Do we want to return containing groups?
var groups = (args["groups"] == "true");
// Get the person who has that user name
var person = people.getPerson(userName);
if (person != null)
{
model.person = person;
model.groups = groups ? people.getContainerGroups(person) : null;
}
else
{

View File

@@ -1,2 +1,6 @@
<#import "person.lib.ftl" as personLib/>
<#if groups??>
<@personLib.personGroupsJSON person=person groups=groups/>
<#else>
<@personLib.personJSON person=person/>
</#if>

View File

@@ -1,6 +1,5 @@
<#macro personJSON person>
<#macro personJSONinner person>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"url" : "${url.serviceContext + "/api/person/" + person.properties.userName}",
"userName" : "${person.properties.userName}",
<#if person.assocs["cm:avatar"]??>
@@ -26,10 +25,23 @@
"quota" : <#if person.properties.sizeQuota??>${person.properties.sizeQuota?c}<#else>0</#if>,
"sizeCurrent" : <#if person.properties.sizeCurrent??>${person.properties.sizeCurrent?c}<#else>0</#if>,
"persondescription" : <#if person.properties.persondescription??>"${person.properties.persondescription.content}"<#else>null</#if>
}
</#escape>
</#macro>
<#macro personJSON person>
{
<@personJSONinner person=person/>
}
</#macro>
<#macro personGroupsJSON person groups>
{
<@personJSONinner person=person/>
,
"groups" : [<#list groups as g>"${jsonUtils.encodeJSONString(g.properties["usr:authorityName"])}"<#if g_has_next>, </#if></#list>]
}
</#macro>
<#macro personSummaryJSON person>
<#escape x as jsonUtils.encodeJSONString(x)>
{

View File

@@ -253,14 +253,7 @@ public class PersonServiceTest extends BaseWebScriptTest
Status.STATUS_OK);
// Delete the person
JSONObject result = deletePerson(userName, Status.STATUS_OK);
assertEquals(userName, result.get("userName"));
assertEquals("myFirstName", result.get("firstName"));
assertEquals("myLastName", result.get("lastName"));
assertEquals("myOrganisation", result.get("organisation"));
assertEquals("myJobTitle", result.get("jobtitle"));
assertEquals("firstName.lastName@email.com", result.get("email"));
deletePerson(userName, Status.STATUS_OK);
// Make sure that the person has been deleted and no longer exists
deletePerson(userName, Status.STATUS_NOT_FOUND);