From 6b580c7cc4fb702157281c0e957251549418530e Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Thu, 2 Apr 2009 16:35:31 +0000 Subject: [PATCH] Build fix for breaking test case. Bug fix invitation service was approving too many invitations! Implemented security rules for who is allowed to cancel a moderated invitation. Continuing implementation of group authority scripts. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13815 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/groups/authority.lib.ftl | 2 +- .../repository/groups/rootgroups.get.desc.xml | 9 +- .../repository/groups/rootgroups.get.js | 26 ++- .../repository/groups/rootgroups.get.json.ftl | 11 ++ .../invitation/invitation.delete.desc.xml | 4 +- .../repo/web/scripts/groups/GroupsTest.java | 166 ++++++++++++++++++ .../scripts/invitation/InvitationTest.java | 2 +- 7 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl index c284191f19..6e514848a6 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/authority.lib.ftl @@ -1,5 +1,5 @@ <#-- renders an authority object which can be either a GROUP or USER (and possibly ROLE in future)--> -<#macro formJSON authority> +<#macro authorityJSON authority> <#escape x as jsonUtils.encodeJSONString(x)> { "authorityType" : "${authority.authorityType}", diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.desc.xml index a27d4840e4..fcd5d7fea2 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.desc.xml @@ -2,9 +2,12 @@ List all root groups + If the optional includeInternal parameter is set to 'true' then will include internal groups, if ommitted or 'false' + internal groups will not be returned. +
+ If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName. + The shortname filter can contain the wild card characters * and ? but these must be url encoded for this script. ]]>
/api/rootgroups?shortNameFilter={shortNameFilter?}&includeInternal={includeInternal?} diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.js index bbb4436636..edbead269e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.js @@ -1 +1,25 @@ -// get rootgroups \ No newline at end of file +/** + * List/Search root groups + */ + +function main () +{ + // Get the args + var shortNameFilter = args["shortNameFilter"]; + var includeInternalStr = args["includeInternal"]; + + if(shortNameFilter == null) + { + shortNameFilter = ""; + } + + var includeInternal = includeInternalStr == "true" ? true : false; + + // Do the search + model.groups = groups.searchRootGroups(shortNameFilter, includeInternal); +} + +main(); + + + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.json.ftl index e69de29bb2..6bf003d94e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/groups/rootgroups.get.json.ftl @@ -0,0 +1,11 @@ +<#-- list / search / rootgroups --> + +<#import "authority.lib.ftl" as authorityLib/> +{ + "data": [ + <#list groups as group> + <@authorityLib.authorityJSON authority=group /> + <#if group_has_next>, + + ] +} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.desc.xml index 372b7e3278..442f8777a3 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/site/invitation/invitation.delete.desc.xml @@ -7,7 +7,9 @@ invitation which will result in the invitation workflow continuing to a normal but rejected conclusion. In particular the approver or invitee are not notified if an invitation is canceled.
- Only a site manager may cancel an invitation. + Only a site manager may cancel an nominated invitation. +
+ A site manager or the invitee may cancel a moderated invitation.
Returns 200, STATUS_OK on success. ]]> diff --git a/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java new file mode 100644 index 0000000000..4217649bff --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2005-2009 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.groups; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.site.SiteModel; +import org.alfresco.repo.web.scripts.BaseWebScriptTest; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.GUID; +import org.alfresco.util.PropertyMap; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.TestWebScriptServer.DeleteRequest; +import org.alfresco.web.scripts.TestWebScriptServer.GetRequest; +import org.alfresco.web.scripts.TestWebScriptServer.PostRequest; +import org.alfresco.web.scripts.TestWebScriptServer.PutRequest; +import org.alfresco.web.scripts.TestWebScriptServer.Response; +import org.json.JSONArray; +import org.json.JSONObject; + +/** + * Unit test of Groups REST APIs. + * + * @author Mark Rogers + */ +public class GroupsTest extends BaseWebScriptTest +{ + private AuthenticationService authenticationService; + private AuthenticationComponent authenticationComponent; + private PersonService personService; + private NodeService nodeService; + + private static final String USER_ONE = "GroupTestOne"; + private static final String USER_TWO = "GroupTestTwo"; + private static final String USER_THREE = "GroupTestThree"; + + private static final String URL_GROUPS = "/api/groups"; + private static final String URL_ROOTGROUPS = "/api/rootgroups"; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + + this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); + this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); + this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); + this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService"); + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + // Create users + createUser(USER_ONE); + createUser(USER_TWO); + createUser(USER_THREE); + + // Do tests as user one + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + private void createUser(String userName) + { + if (this.authenticationService.authenticationExists(userName) == false) + { + this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); + + PropertyMap ppOne = new PropertyMap(4); + ppOne.put(ContentModel.PROP_USERNAME, userName); + ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); + ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); + ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); + ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + this.personService.createPerson(ppOne); + } + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + + } + + /** + * Detailed test of get root groups + */ + public void testGetRootGroup() throws Exception + { + /** + * Get all root groups + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + } + + } + + /** + * Detailed test of get group + */ + public void testGetGroup() + { + + } + + /** + * Detailed test of create group + */ + public void testCreateGroup() + { + + } + + /** + * Detailed test of search groups + */ + public void testSearchGroups() + { + + } + + +} diff --git a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java index 4e508eeabd..0c3dfe85ea 100644 --- a/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java +++ b/source/java/org/alfresco/repo/web/scripts/invitation/InvitationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2009 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License