mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Implementing Web Site Group Membership.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14342 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Membership</shortname>
|
<shortname>Delete Web Site Membership</shortname>
|
||||||
<description>Get the membership details for a user</description>
|
<description> <![CDATA[
|
||||||
<url>/api/sites/{shortname}/memberships/{username}</url>
|
Delete membership from a web site.
|
||||||
|
<br />
|
||||||
|
'shortname' is the shortname of the web site, 'authorityname' is the full authority name for the membership.
|
||||||
|
]]></description>
|
||||||
|
<url>/api/sites/{shortname}/memberships/{authorityname}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
</webscript>
|
</webscript>
|
@@ -1,8 +1,16 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Membership</shortname>
|
<shortname>Get Web Site Membership</shortname>
|
||||||
<description>Get the membership details for a user</description>
|
<description> <![CDATA[
|
||||||
<url>/api/sites/{shortname}/memberships/{username}</url>
|
Get the membership details for a user or group
|
||||||
|
<br />
|
||||||
|
'shortname' is the shortname of the web site, 'authorityname' is the full authority name for the membership.
|
||||||
|
<br />
|
||||||
|
Returns a membership or Status.NOT_FOUND(404)
|
||||||
|
|
||||||
|
]]></description>
|
||||||
|
<url>/api/sites/{shortname}/memberships/{authorityname}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
</webscript>
|
</webscript>
|
@@ -14,14 +14,28 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var person = people.getPerson(userName);
|
var authority
|
||||||
if (person == null)
|
if(userName.match("^GROUP_"))
|
||||||
{
|
{
|
||||||
// Person cannot be found
|
authority = groups.getGroupForFullAuthorityName(userName);
|
||||||
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " does not exist.");
|
if (authority == null)
|
||||||
return;
|
{
|
||||||
}
|
// Person cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The group with full name " + userName + " does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
authority = people.getPerson(userName);
|
||||||
|
if (authority == null)
|
||||||
|
{
|
||||||
|
// Person cannot be found
|
||||||
|
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the role of the user
|
// Get the role of the user
|
||||||
var role = site.getMembersRole(userName);
|
var role = site.getMembersRole(userName);
|
||||||
if (role == null)
|
if (role == null)
|
||||||
@@ -33,7 +47,7 @@ function main()
|
|||||||
|
|
||||||
// Pass the values to the template
|
// Pass the values to the template
|
||||||
model.site = site;
|
model.site = site;
|
||||||
model.person = person;
|
model.authority = authority;
|
||||||
model.role = role;
|
model.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
<#import "membership.lib.ftl" as membershipLib/>
|
<#import "membership.lib.ftl" as membershipLib/>
|
||||||
<@membershipLib.membershipJSON site=site role=role person=person/>
|
<@membershipLib.membershipJSON site=site role=role authority=authority />
|
@@ -1,24 +1,50 @@
|
|||||||
<#macro membershipJSON site role person>
|
<#-- Web Site Membership renders an authority object which can be either a Java Script person or a Java Script group -->
|
||||||
|
|
||||||
|
|
||||||
|
<#macro membershipJSON site role authority>
|
||||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
{
|
{
|
||||||
"role" : "${role}",
|
"role" : "${role}",
|
||||||
"person":
|
|
||||||
|
<#if authority.authorityType?? && authority.authorityType = "GROUP" >
|
||||||
|
<#-- this is a group authority type -->
|
||||||
|
|
||||||
|
"authority":
|
||||||
{
|
{
|
||||||
"userName" : "${person.properties.userName}",
|
"authorityType" : "${authority.authorityType}",
|
||||||
"firstName" : "${person.properties.firstName}",
|
"shortName" : "${authority.shortName}",
|
||||||
"lastName" : "${person.properties.lastName}",
|
"fullName" : "${authority.fullName}",
|
||||||
<#if person.assocs["cm:avatar"]??>
|
"displayName" : "${authority.displayName}",
|
||||||
"avatar" : "${"api/node/" + person.assocs["cm:avatar"][0].nodeRef?string?replace('://','/') + "/content/thumbnails/avatar"}",
|
"url" : "${url.serviceContext + "/api/groups/" + authority.shortName }"
|
||||||
</#if>
|
|
||||||
<#if person.properties.jobtitle??>
|
|
||||||
"jobtitle" : "${person.properties.jobtitle}",
|
|
||||||
</#if>
|
|
||||||
<#if person.properties.organization??>
|
|
||||||
"organization" : "${person.properties.organization}",
|
|
||||||
</#if>
|
|
||||||
"url" : "${url.serviceContext + "/api/people/" + person.properties.userName}"
|
|
||||||
},
|
},
|
||||||
"url" : "${url.serviceContext + "/api/sites/" + site.shortName + "/memberships/" + person.properties.userName}"
|
"url" : "${url.serviceContext + "/api/sites/" + site.shortName + "/memberships/" + authority.fullName}"
|
||||||
|
|
||||||
|
|
||||||
|
<#else >
|
||||||
|
<#-- this is a person authority type -->
|
||||||
|
|
||||||
|
"authority":
|
||||||
|
{
|
||||||
|
"authorityType" : "USER",
|
||||||
|
"fullName" : "${authority.properties.userName}",
|
||||||
|
"userName" : "${authority.properties.userName}",
|
||||||
|
"firstName" : "${authority.properties.firstName}",
|
||||||
|
"lastName" : "${authority.properties.lastName}",
|
||||||
|
<#if authority.assocs["cm:avatar"]??>
|
||||||
|
"avatar" : "${"api/node/" + authority.assocs["cm:avatar"][0].nodeRef?string?replace('://','/') + "/content/thumbnails/avatar"}",
|
||||||
|
</#if>
|
||||||
|
<#if authority.properties.jobtitle??>
|
||||||
|
"jobtitle" : "${authority.properties.jobtitle}",
|
||||||
|
</#if>
|
||||||
|
<#if authority.properties.organization??>
|
||||||
|
"organization" : "${authority.properties.organization}",
|
||||||
|
</#if>
|
||||||
|
"url" : "${url.serviceContext + "/api/people/" + authority.properties.userName}"
|
||||||
|
},
|
||||||
|
"url" : "${url.serviceContext + "/api/sites/" + site.shortName + "/memberships/" + authority.properties.userName}"
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
}
|
}
|
||||||
</#escape>
|
</#escape>
|
||||||
</#macro>
|
</#macro>
|
@@ -1,8 +1,31 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Membership</shortname>
|
<shortname>Update Web Site Membership</shortname>
|
||||||
<description>Get the membership details for a user</description>
|
<description> <![CDATA[
|
||||||
<url>/api/sites/{shortname}/memberships/{username}</url>
|
Update the membership role for a user or group
|
||||||
|
|
||||||
|
<br />
|
||||||
|
'shortname' is the shortname of the web site, 'authorityname' is the full authority name for the membership.
|
||||||
|
<br />
|
||||||
|
Required parameters,
|
||||||
|
<br />
|
||||||
|
role, mandatory String, the new role name for this membership.
|
||||||
|
<br />
|
||||||
|
person object, with userName property
|
||||||
|
<br>
|
||||||
|
OR
|
||||||
|
group object, with fullName property
|
||||||
|
<br />
|
||||||
|
OR
|
||||||
|
authority object, with fullName property
|
||||||
|
<br />
|
||||||
|
|
||||||
|
Returns: The new authority.
|
||||||
|
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/sites/{shortname}/memberships/{authorityname}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
</webscript>
|
</webscript>
|
@@ -1,2 +1,2 @@
|
|||||||
<#import "membership.lib.ftl" as membershipLib/>
|
<#import "membership.lib.ftl" as membershipLib/>
|
||||||
<@membershipLib.membershipJSON site=site role=role person=person/>
|
<@membershipLib.membershipJSON site=site role=role authority=authority/>
|
@@ -18,27 +18,109 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the user name
|
// Are we adding a person ?
|
||||||
var userName = json.getJSONObject("person").get("userName");
|
if (json.has("person"))
|
||||||
if (userName == null)
|
|
||||||
{
|
{
|
||||||
status.setCode(status.STATUS_BAD_REQUEST, "The user name has not been set.");
|
// Get the user name
|
||||||
return;
|
var userName = json.getJSONObject("person").get("userName");
|
||||||
}
|
if (userName == null)
|
||||||
var person = people.getPerson(userName);
|
{
|
||||||
if (person == null)
|
status.setCode(status.STATUS_BAD_REQUEST, "The user name has not been set.");
|
||||||
{
|
return;
|
||||||
status.setCode(status.STATUS_BAD_REQUEST, "The person with user name " + userName + " could not be found.");
|
}
|
||||||
|
var person = people.getPerson(userName);
|
||||||
|
if (person == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The person with user name " + userName + " could not be found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the membership details
|
||||||
|
site.setMembership(userName, role);
|
||||||
|
// Pass the details to the template
|
||||||
|
model.site = site;
|
||||||
|
model.role = role;
|
||||||
|
model.authority = person;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the membership details
|
// Are we adding a group ?
|
||||||
site.setMembership(userName, role);
|
if (json.has("group"))
|
||||||
|
{
|
||||||
|
// Get the user name
|
||||||
|
var groupName = json.getJSONObject("group").get("fullName");
|
||||||
|
if (groupName == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The fullName for the group has not been set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(groupName.match("^GROUP_") == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "Group Authority names should begin with 'GROUP_'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var group = groups.getGroupForFullAuthorityName(groupName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The group with group name " + groupName + " could not be found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Pass the details to the template
|
// Set the membership details
|
||||||
model.site = site;
|
site.setMembership(groupName, role);
|
||||||
model.role = role;
|
// Pass the details to the template
|
||||||
model.person = person;
|
model.site = site;
|
||||||
|
model.role = role;
|
||||||
|
model.authority = group;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json.has("authority"))
|
||||||
|
{
|
||||||
|
// Get the user name
|
||||||
|
var authorityName = json.getJSONObject("authority").get("fullName");
|
||||||
|
if (authorityName == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The fullName for the authority has not been set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var authority;
|
||||||
|
if(authorityName.match("^GROUP_") != null)
|
||||||
|
{
|
||||||
|
// authority is a group
|
||||||
|
authority = groups.getGroupForFullAuthorityName(authorityName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// assume a person
|
||||||
|
authority = people.getPerson(authorityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (authority == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The authority with name " + authorityName + " could not be found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the membership details
|
||||||
|
site.setMembership(authorityName, role);
|
||||||
|
// Pass the details to the template
|
||||||
|
model.site = site;
|
||||||
|
model.role = role;
|
||||||
|
model.authority = authority;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Neither person or group specified.
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "person or group has not been set.");
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
@@ -1,8 +1,21 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Memberships</shortname>
|
<shortname>List Web Site Memberships</shortname>
|
||||||
<description>Get a colleciton of a sites memberships.</description>
|
<description> <![CDATA[
|
||||||
<url>/api/sites/{shortname}/memberships?nf={namefilter?}&rf={rolefilter?}&size={pagesize?}&pos={position?}</url>
|
Get a colleciton of a Web Site memberships.
|
||||||
|
<br />
|
||||||
|
'shortname' is the shortname of the web site
|
||||||
|
<br />
|
||||||
|
Parameters:
|
||||||
|
<ul>
|
||||||
|
<li>nf, Optional, namefilter</li>
|
||||||
|
<li>rf, Optional, rolefilter</li>
|
||||||
|
<li>size, Optional, page size</li>
|
||||||
|
<li>authorityType, Optional, returns either GROUP or USER authorities. If not specified returns all authorities.</li>
|
||||||
|
</ul>
|
||||||
|
]]></description>
|
||||||
|
<url>/api/sites/{shortname}/memberships?nf={namefilter?}&rf={rolefilter?}&size={pagesize?}&pos={position?}&authorityType={authorityType?}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
</webscript>
|
</webscript>
|
@@ -1,34 +1,66 @@
|
|||||||
// Get the site id
|
/**
|
||||||
var shortName = url.extension.split("/")[0];
|
* Implementation of list memberships
|
||||||
var site = siteService.getSite(shortName);
|
*/
|
||||||
|
|
||||||
// get the filters
|
function main()
|
||||||
var nameFilter = args["nf"];
|
|
||||||
var roleFilter = args["rf"];
|
|
||||||
var sizeString = args["size"];
|
|
||||||
|
|
||||||
// Get the filtered memeberships
|
|
||||||
var memberships = site.listMembers(nameFilter, roleFilter, sizeString != null ? parseInt(sizeString) : 0);
|
|
||||||
|
|
||||||
// Get a list of all the users resolved to person nodes
|
|
||||||
var peopleList = Array(memberships.length);
|
|
||||||
for (userName in memberships)
|
|
||||||
{
|
{
|
||||||
var person = people.getPerson(userName);
|
// Get the site id
|
||||||
// make sure the keys are strings - as usernames may be all numbers!
|
var shortName = url.extension.split("/")[0];
|
||||||
peopleList['_' + userName] = person;
|
var site = siteService.getSite(shortName);
|
||||||
|
|
||||||
|
// get the filters
|
||||||
|
var nameFilter = args["nf"];
|
||||||
|
var roleFilter = args["rf"];
|
||||||
|
var authorityType = args["authorityType"];
|
||||||
|
var sizeString = args["size"];
|
||||||
|
|
||||||
|
if(authorityType != null )
|
||||||
|
{
|
||||||
|
authorityType.match("[USER|GROUP]" != null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The authorityType must be either USER or GROUP.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the filtered memberships
|
||||||
|
// Comes back as a Map<String, String> containing the full authority name
|
||||||
|
// and role
|
||||||
|
var memberships = site.listMembers(nameFilter, roleFilter, sizeString != null ? parseInt(sizeString) : 0);
|
||||||
|
|
||||||
|
// Get a list of all the users resolved to person nodes
|
||||||
|
var authorities = Array(memberships.length);
|
||||||
|
var roles = {};
|
||||||
|
|
||||||
|
for (userName in memberships)
|
||||||
|
{
|
||||||
|
var membershipRole = memberships[userName];
|
||||||
|
if(userName.match("^GROUP_"))
|
||||||
|
{
|
||||||
|
if(authorityType == null || authorityType == "GROUP")
|
||||||
|
{
|
||||||
|
// make sure the keys are strings - as usernames may be all
|
||||||
|
// numbers!
|
||||||
|
authorities['_' + userName] = groups.getGroupForFullAuthorityName(userName);
|
||||||
|
roles['_' + userName] = membershipRole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(authorityType == null || authorityType == "USER")
|
||||||
|
{
|
||||||
|
// make sure the keys are strings - as usernames may be all
|
||||||
|
// numbers!
|
||||||
|
authorities['_' + userName] = people.getPerson(userName);
|
||||||
|
roles['_' + userName] = membershipRole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass the information to the template
|
||||||
|
model.site = site;
|
||||||
|
model.roles = roles;
|
||||||
|
model.authorities = authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// also copy over the memberships.
|
main();
|
||||||
var mems = {};
|
|
||||||
for (userName in memberships)
|
|
||||||
{
|
|
||||||
var membershipType = memberships[userName];
|
|
||||||
// make sure the keys are strings - as usernames may be all numbers!
|
|
||||||
mems['_' + userName] = membershipType;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass the information to the template
|
|
||||||
model.site = site;
|
|
||||||
model.memberships = mems;
|
|
||||||
model.peoplelist = peopleList;
|
|
@@ -1,8 +1,10 @@
|
|||||||
|
<#-- List memberships Implementation-->
|
||||||
<#import "membership.lib.ftl" as membershipLib />
|
<#import "membership.lib.ftl" as membershipLib />
|
||||||
<#assign userNames = memberships?keys />
|
|
||||||
|
<#assign userNames = roles?keys />
|
||||||
[
|
[
|
||||||
<#list userNames as userName>
|
<#list userNames as userName>
|
||||||
<@membershipLib.membershipJSON site=site role=memberships[userName] person=peoplelist[userName] />
|
<@membershipLib.membershipJSON site=site role=roles[userName] authority=authorities[userName] />
|
||||||
<#if userName_has_next>,</#if>
|
<#if userName_has_next>,</#if>
|
||||||
</#list>
|
</#list>
|
||||||
]
|
]
|
@@ -1,8 +1,25 @@
|
|||||||
<webscript>
|
<webscript>
|
||||||
<shortname>Memberships</shortname>
|
<shortname>Add Web Site Membership</shortname>
|
||||||
<description>Adds a new membership to the site</description>
|
<description> <![CDATA[
|
||||||
|
Adds a new membership to the web site
|
||||||
|
<br />
|
||||||
|
'shortname' is the shortname of the web site, 'authorityname' is the full authority name for the membership.
|
||||||
|
Required parameters,
|
||||||
|
<br />
|
||||||
|
role, mandatory String, the new role name for this membership.
|
||||||
|
<br />
|
||||||
|
person object, with userName property
|
||||||
|
<br>
|
||||||
|
OR
|
||||||
|
group object, with fullName property
|
||||||
|
<br />
|
||||||
|
OR
|
||||||
|
authority object, with fullName property
|
||||||
|
<br />
|
||||||
|
]]></description>
|
||||||
<url>/api/sites/{shortname}/memberships</url>
|
<url>/api/sites/{shortname}/memberships</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>user</authentication>
|
<authentication>user</authentication>
|
||||||
<transaction>required</transaction>
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>draft_public_api</lifecycle>
|
||||||
</webscript>
|
</webscript>
|
@@ -1,2 +1,2 @@
|
|||||||
<#import "membership.lib.ftl" as membershipLib/>
|
<#import "membership.lib.ftl" as membershipLib/>
|
||||||
<@membershipLib.membershipJSON site=site role=role person=person/>
|
<@membershipLib.membershipJSON site=site role=role authority=authority/>
|
@@ -18,27 +18,69 @@ function main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the user name
|
// Are we adding a person ?
|
||||||
var userName = json.getJSONObject("person").get("userName");
|
if (json.has("person"))
|
||||||
if (userName == null)
|
|
||||||
{
|
{
|
||||||
status.setCode(status.STATUS_BAD_REQUEST, "The user name has not been set.");
|
// Get the user name
|
||||||
return;
|
var userName = json.getJSONObject("person").get("userName");
|
||||||
}
|
if (userName == null)
|
||||||
var person = people.getPerson(userName);
|
{
|
||||||
if (person == null)
|
status.setCode(status.STATUS_BAD_REQUEST, "The user name has not been set.");
|
||||||
{
|
return;
|
||||||
status.setCode(status.STATUS_BAD_REQUEST, "The person with user name " + userName + " could not be found.");
|
}
|
||||||
|
var person = people.getPerson(userName);
|
||||||
|
if (person == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The person with user name " + userName + " could not be found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the membership details
|
||||||
|
site.setMembership(userName, role);
|
||||||
|
// Pass the details to the template
|
||||||
|
model.site = site;
|
||||||
|
model.role = role;
|
||||||
|
model.authority = person;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the membership details
|
// Are we adding a group ?
|
||||||
site.setMembership(userName, role);
|
if (json.has("group"))
|
||||||
|
{
|
||||||
|
// Get the user name
|
||||||
|
var groupName = json.getJSONObject("group").get("fullName");
|
||||||
|
if (groupName == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The fullName for the group has not been set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(groupName.match("^GROUP_") == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "Group Authority names should begin with 'GROUP_'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var group = groups.getGroupForFullAuthorityName(groupName);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "The group with group name " + groupName + " could not be found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Pass the details to the template
|
// Set the membership details
|
||||||
model.site = site;
|
site.setMembership(groupName, role);
|
||||||
model.role = role;
|
// Pass the details to the template
|
||||||
model.person = person;
|
model.site = site;
|
||||||
|
model.role = role;
|
||||||
|
model.authority = group;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neither person or group specified.
|
||||||
|
status.setCode(status.STATUS_BAD_REQUEST, "person or group has not been set.");
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
@@ -40,6 +40,8 @@ import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.alfresco.service.cmr.site.SiteService;
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
@@ -68,6 +70,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private SiteService siteService;
|
private SiteService siteService;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
private AuthorityService authorityService;
|
||||||
|
|
||||||
private static final String USER_ONE = "SiteTestOne";
|
private static final String USER_ONE = "SiteTestOne";
|
||||||
private static final String USER_TWO = "SiteTestTwo";
|
private static final String USER_TWO = "SiteTestTwo";
|
||||||
@@ -89,6 +92,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
||||||
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
|
||||||
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
||||||
|
this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
|
||||||
|
|
||||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
@@ -309,7 +313,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
|
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMemeberships() throws Exception
|
public void testGetMemberships() throws Exception
|
||||||
{
|
{
|
||||||
// Create a site
|
// Create a site
|
||||||
String shortName = GUID.generate();
|
String shortName = GUID.generate();
|
||||||
@@ -322,7 +326,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
assertEquals(1, result.length());
|
assertEquals(1, result.length());
|
||||||
JSONObject membership = result.getJSONObject(0);
|
JSONObject membership = result.getJSONObject(0);
|
||||||
assertEquals(SiteModel.SITE_MANAGER, membership.get("role"));
|
assertEquals(SiteModel.SITE_MANAGER, membership.get("role"));
|
||||||
assertEquals(USER_ONE, membership.getJSONObject("person").get("userName"));
|
assertEquals(USER_ONE, membership.getJSONObject("authority").get("userName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPostMemberships() throws Exception
|
public void testPostMemberships() throws Exception
|
||||||
@@ -369,7 +373,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
|
|
||||||
// Check the result
|
// Check the result
|
||||||
assertEquals(SiteModel.SITE_MANAGER, result.get("role"));
|
assertEquals(SiteModel.SITE_MANAGER, result.get("role"));
|
||||||
assertEquals(USER_ONE, result.getJSONObject("person").get("userName"));
|
assertEquals(USER_ONE, result.getJSONObject("authority").get("userName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutMembership() throws Exception
|
public void testPutMembership() throws Exception
|
||||||
@@ -377,10 +381,7 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
// Create a site
|
// Create a site
|
||||||
String shortName = GUID.generate();
|
String shortName = GUID.generate();
|
||||||
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
|
||||||
// Test error conditions
|
|
||||||
// TODO
|
|
||||||
|
|
||||||
// Build the JSON membership object
|
// Build the JSON membership object
|
||||||
JSONObject membership = new JSONObject();
|
JSONObject membership = new JSONObject();
|
||||||
membership.put("role", SiteModel.SITE_CONSUMER);
|
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||||
@@ -392,20 +393,104 @@ public class SiteServiceTest extends BaseWebScriptTest
|
|||||||
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
||||||
JSONObject newMember = new JSONObject(response.getContentAsString());
|
JSONObject newMember = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
// Update the role
|
// Update the role by returning the data.
|
||||||
newMember.put("role", SiteModel.SITE_COLLABORATOR);
|
newMember.put("role", SiteModel.SITE_COLLABORATOR);
|
||||||
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO, newMember.toString(), "application/json"), 200);
|
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO, newMember.toString(), "application/json"), 200);
|
||||||
JSONObject result = new JSONObject(response.getContentAsString());
|
JSONObject result = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
// Check the result
|
// Check the result
|
||||||
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
|
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
|
||||||
assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
|
assertEquals(USER_TWO, result.getJSONObject("authority").get("userName"));
|
||||||
|
|
||||||
// Double check and get the membership for user two
|
// Double check and get the membership for user two
|
||||||
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
|
response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO), 200);
|
||||||
result = new JSONObject(response.getContentAsString());
|
result = new JSONObject(response.getContentAsString());
|
||||||
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
|
assertEquals(SiteModel.SITE_COLLABORATOR, result.get("role"));
|
||||||
assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
|
assertEquals(USER_TWO, result.getJSONObject("authority").get("userName"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGroupMembership() throws Exception
|
||||||
|
{
|
||||||
|
String testGroup = "SiteServiceTestGroupA";
|
||||||
|
String testGroupName = "GROUP_" + testGroup;
|
||||||
|
|
||||||
|
if(!authorityService.authorityExists(testGroup))
|
||||||
|
{
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
testGroupName = authorityService.createAuthority(AuthorityType.GROUP, null, testGroup, testGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.authenticationComponent.setCurrentUser(USER_ONE);
|
||||||
|
|
||||||
|
// CRUD a membership group for a web site
|
||||||
|
// Create a site
|
||||||
|
String shortName = GUID.generate();
|
||||||
|
createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
|
||||||
|
|
||||||
|
// Build the JSON membership object
|
||||||
|
JSONObject membership = new JSONObject();
|
||||||
|
membership.put("role", SiteModel.SITE_CONSUMER);
|
||||||
|
JSONObject group = new JSONObject();
|
||||||
|
group.put("fullName", testGroupName);
|
||||||
|
membership.put("group", group);
|
||||||
|
|
||||||
|
// Create a new group membership
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new PostRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS, membership.toString(), "application/json"), 200);
|
||||||
|
JSONObject newMember = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
|
// Validate the return value
|
||||||
|
assertEquals("role not correct", SiteModel.SITE_CONSUMER, newMember.getString("role"));
|
||||||
|
JSONObject newGroup = newMember.getJSONObject("authority");
|
||||||
|
assertNotNull("newGroup");
|
||||||
|
assertEquals("full name not correct", testGroupName, newGroup.getString("fullName"));
|
||||||
|
assertEquals("authorityType not correct", "GROUP", newGroup.getString("authorityType"));
|
||||||
|
|
||||||
|
|
||||||
|
// Now send the returned value back with a new role (COLLABORATOR)
|
||||||
|
newMember.put("role", SiteModel.SITE_COLLABORATOR);
|
||||||
|
response = sendRequest(new PutRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + USER_TWO, newMember.toString(), "application/json"), 200);
|
||||||
|
JSONObject updateResult = new JSONObject(response.getContentAsString());
|
||||||
|
assertEquals("role not correct", SiteModel.SITE_COLLABORATOR, updateResult.getString("role"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now List membership to show the group from above.
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS), 200);
|
||||||
|
JSONArray listResult = new JSONArray(response.getContentAsString());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result should have at least 2 elements, 1 for the user who created and 1 for the group added above
|
||||||
|
*/
|
||||||
|
assertTrue("result too small", listResult.length() >= 2);
|
||||||
|
for(int i = 0; i < listResult.length(); i++)
|
||||||
|
{
|
||||||
|
JSONObject obj = listResult.getJSONObject(i);
|
||||||
|
JSONObject authority = obj.getJSONObject("authority");
|
||||||
|
if(authority.getString("authorityType").equals("GROUP"))
|
||||||
|
{
|
||||||
|
assertEquals("full name not correct", testGroupName, authority.getString("fullName"));
|
||||||
|
|
||||||
|
}
|
||||||
|
if(authority.getString("authorityType").equals("USER"))
|
||||||
|
{
|
||||||
|
assertEquals("full name not correct", USER_ONE, authority.getString("fullName"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now get the group membership from above
|
||||||
|
// Now List membership to show the group from above.
|
||||||
|
{
|
||||||
|
Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS + '/' + testGroupName), 200);
|
||||||
|
JSONObject getResult = new JSONObject(response.getContentAsString());
|
||||||
|
System.out.println(response.getContentAsString());
|
||||||
|
JSONObject grp = getResult.getJSONObject("authority");
|
||||||
|
assertEquals("full name not correct", testGroupName, grp.getString("fullName"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteMembership() throws Exception
|
public void testDeleteMembership() throws Exception
|
||||||
|
Reference in New Issue
Block a user