Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)

64416: Merged WAT1 (4.3/Cloud) to HEAD-BUG-FIX (4.3/Cloud)
      61735: ACE-493: Made Sites Public REST API Get method callable by Admins or by users that are made members of the new "Site Admin" group.
      ACE-503: Created a new PUT method in Sites Public REST API, such that it is possible to modify the visibility of a site.
      ACE-511: Created a new DELETE method in Sites Public REST API, such that it is possible to delete a site.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@64562 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2014-03-15 01:29:23 +00:00
parent 98992479a4
commit 25895187d8
4 changed files with 705 additions and 549 deletions

View File

@@ -16,6 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.alfresco.rest.api; package org.alfresco.rest.api;
import org.alfresco.query.PagingResults; import org.alfresco.query.PagingResults;
@@ -23,6 +24,7 @@ import org.alfresco.rest.api.model.FavouriteSite;
import org.alfresco.rest.api.model.MemberOfSite; import org.alfresco.rest.api.model.MemberOfSite;
import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.model.SiteContainer; import org.alfresco.rest.api.model.SiteContainer;
import org.alfresco.rest.api.model.SiteImpl;
import org.alfresco.rest.api.model.SiteMember; import org.alfresco.rest.api.model.SiteMember;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Paging;
@@ -34,10 +36,17 @@ import org.alfresco.service.cmr.site.SiteRole;
public interface Sites public interface Sites
{ {
SiteInfo validateSite(String siteShortName); SiteInfo validateSite(String siteShortName);
SiteInfo validateSite(NodeRef nodeRef); SiteInfo validateSite(NodeRef nodeRef);
CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteShortName, Parameters parameters); CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteShortName, Parameters parameters);
Site getSite(String siteId); Site getSite(String siteId);
SiteImpl updateSite(String siteShortName, SiteImpl site);
void deleteSite(String siteShortName);
/** /**
* people/<personId>/sites/<siteId> * people/<personId>/sites/<siteId>
* *
@@ -46,19 +55,32 @@ public interface Sites
* @return * @return
*/ */
MemberOfSite getMemberOfSite(String personId, String siteShortName); MemberOfSite getMemberOfSite(String personId, String siteShortName);
SiteMember getSiteMember(String personId, String siteShortName); SiteMember getSiteMember(String personId, String siteShortName);
SiteMember addSiteMember(String siteShortName, SiteMember siteMember); SiteMember addSiteMember(String siteShortName, SiteMember siteMember);
void removeSiteMember(String personId, String siteId); void removeSiteMember(String personId, String siteId);
SiteMember updateSiteMember(String siteShortName, SiteMember siteMember); SiteMember updateSiteMember(String siteShortName, SiteMember siteMember);
CollectionWithPagingInfo<MemberOfSite> getSites(String personId, Parameters parameters); CollectionWithPagingInfo<MemberOfSite> getSites(String personId, Parameters parameters);
SiteContainer getSiteContainer(String siteShortName, String containerId); SiteContainer getSiteContainer(String siteShortName, String containerId);
PagingResults<SiteContainer> getSiteContainers(String siteShortName, Paging paging); PagingResults<SiteContainer> getSiteContainers(String siteShortName, Paging paging);
CollectionWithPagingInfo<Site> getSites(Parameters parameters); CollectionWithPagingInfo<Site> getSites(Parameters parameters);
FavouriteSite getFavouriteSite(String personId, String siteShortName); FavouriteSite getFavouriteSite(String personId, String siteShortName);
void addFavouriteSite(String personId, FavouriteSite favouriteSite); void addFavouriteSite(String personId, FavouriteSite favouriteSite);
void removeFavouriteSite(String personId, String siteId); void removeFavouriteSite(String personId, String siteId);
CollectionWithPagingInfo<FavouriteSite> getFavouriteSites(String personId, Parameters parameters); CollectionWithPagingInfo<FavouriteSite> getFavouriteSites(String personId, Parameters parameters);
SiteRole getSiteRole(String siteId); SiteRole getSiteRole(String siteId);
SiteRole getSiteRole(String siteId, String personId); SiteRole getSiteRole(String siteId, String personId);
} }

View File

@@ -34,6 +34,7 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.alfresco.rest.api.impl; package org.alfresco.rest.api.impl;
import java.io.Serializable; import java.io.Serializable;
@@ -85,6 +86,7 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteRole; import org.alfresco.service.cmr.site.SiteRole;
import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
@@ -189,7 +191,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();
@@ -240,7 +243,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
SiteRole role = null; SiteRole role = null;
if (includeRole) if (includeRole)
@@ -268,7 +272,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new RelationshipResourceNotFoundException(personId, siteId); throw new RelationshipResourceNotFoundException(personId, siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
String roleStr = siteService.getMembersRole(siteInfo.getShortName(), personId); String roleStr = siteService.getMembersRole(siteInfo.getShortName(), personId);
@@ -321,7 +326,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
SiteRole siteRole = siteMember.getRole(); SiteRole siteRole = siteMember.getRole();
@@ -354,7 +360,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new RelationshipResourceNotFoundException(personId, siteId); throw new RelationshipResourceNotFoundException(personId, siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
boolean isMember = siteService.isMember(siteId, personId); boolean isMember = siteService.isMember(siteId, personId);
@@ -428,7 +435,8 @@ public class SitesImpl implements Sites
for (SiteMembership siteMember : siteMembers) for (SiteMembership siteMember : siteMembers)
{ {
SiteInfo siteInfo = siteMember.getSiteInfo(); SiteInfo siteInfo = siteMember.getSiteInfo();
MemberOfSite memberOfSite = new MemberOfSite(siteInfo.getShortName(), siteInfo.getNodeRef(), siteMember.getRole()); MemberOfSite memberOfSite = new MemberOfSite(siteInfo.getShortName(), siteInfo.getNodeRef(),
siteMember.getRole());
ret.add(memberOfSite); ret.add(memberOfSite);
} }
@@ -444,7 +452,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new RelationshipResourceNotFoundException(siteId, containerId); throw new RelationshipResourceNotFoundException(siteId, containerId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
NodeRef containerNodeRef = siteService.getContainer(siteId, containerId); NodeRef containerNodeRef = siteService.getContainer(siteId, containerId);
@@ -453,7 +462,8 @@ public class SitesImpl implements Sites
throw new RelationshipResourceNotFoundException(siteId, containerId); throw new RelationshipResourceNotFoundException(siteId, containerId);
} }
// check that the containerId is actually a container for the specified site // check that the containerId is actually a container for the specified
// site
SiteInfo testSiteInfo = siteService.getSite(containerNodeRef); SiteInfo testSiteInfo = siteService.getSite(containerNodeRef);
if (testSiteInfo == null) if (testSiteInfo == null)
{ {
@@ -482,7 +492,8 @@ public class SitesImpl implements Sites
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging)); final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(),
Util.getPagingRequest(paging));
List<FileInfo> containerFileInfos = pagingResults.getPage(); List<FileInfo> containerFileInfos = pagingResults.getPage();
final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size()); final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size());
for (FileInfo containerFileInfo : containerFileInfos) for (FileInfo containerFileInfo : containerFileInfos)
@@ -526,11 +537,28 @@ public class SitesImpl implements Sites
final BeanPropertiesFilter filter = parameters.getFilter(); final BeanPropertiesFilter filter = parameters.getFilter();
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging); final PagingRequest pagingRequest = Util.getPagingRequest(paging);
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax) // pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(); final List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, Boolean.TRUE)); sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, Boolean.TRUE));
final PagingResults<SiteInfo> pagingResult = siteService.listSites(null, sortProps, pagingRequest);
PagingResults<SiteInfo> pagingResult = null;
boolean withSiteAdminScope = Boolean.valueOf(parameters.getParameter("admin"));
if (withSiteAdminScope && siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser()))
{
pagingResult = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<PagingResults<SiteInfo>>()
{
public PagingResults<SiteInfo> doWork() throws Exception
{
return siteService.listSites(null, sortProps, pagingRequest);
}
}, AuthenticationUtil.getSystemUserName());
}
else
{
pagingResult = siteService.listSites(null, sortProps, pagingRequest);
}
final List<SiteInfo> sites = pagingResult.getPage(); final List<SiteInfo> sites = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst(); int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser(); final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
@@ -569,7 +597,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new RelationshipResourceNotFoundException(personId, siteId); throw new RelationshipResourceNotFoundException(personId, siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
NodeRef nodeRef = siteInfo.getNodeRef(); NodeRef nodeRef = siteInfo.getNodeRef();
@@ -594,7 +623,8 @@ public class SitesImpl implements Sites
// site does not exist // site does not exist
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url) // set the site id to the short name (to deal with case sensitivity
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
StringBuilder prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX); StringBuilder prefKey = new StringBuilder(FAVOURITE_SITES_PREFIX);
@@ -663,7 +693,8 @@ public class SitesImpl implements Sites
} }
if (isFavourite) if (isFavourite)
{ {
String siteShortName = entry.getKey().substring(FAVOURITE_SITES_PREFIX_LENGTH).replace(".favourited", ""); String siteShortName = entry.getKey().substring(FAVOURITE_SITES_PREFIX_LENGTH)
.replace(".favourited", "");
SiteInfo siteInfo = siteService.getSite(siteShortName); SiteInfo siteInfo = siteService.getSite(siteShortName);
if (siteInfo != null) if (siteInfo != null)
{ {
@@ -743,6 +774,80 @@ public class SitesImpl implements Sites
favourites.add(favourite); favourites.add(favourite);
} }
return CollectionWithPagingInfo.asPaged(paging, favourites, favouriteSites.hasMoreItems(), favouriteSites.getTotalResultCount().getFirst()); return CollectionWithPagingInfo.asPaged(paging, favourites, favouriteSites.hasMoreItems(), favouriteSites
.getTotalResultCount().getFirst());
}
@Override
public SiteImpl updateSite(final String siteShortName, final SiteImpl siteImpl)
{
if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser()))
{
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<SiteImpl>()
{
public SiteImpl doWork() throws Exception
{
// We have to wrap the whole method not just
// siteService.updateSite, as validateSite
// won't give us the private sites for site-admins
return updateSiteImpl(siteShortName, siteImpl);
}
}, AuthenticationUtil.getSystemUserName());
}
else
{
return updateSiteImpl(siteShortName, siteImpl);
}
}
private SiteImpl updateSiteImpl(String siteShortName, SiteImpl siteImpl)
{
SiteInfo siteInfo = validateSite(siteShortName);
if (siteInfo == null)
{
// site does not exist
throw new EntityNotFoundException(siteShortName);
}
// Set the site's visibility
SiteVisibility siteVisibility = siteImpl.getVisibility();
if (siteVisibility == null)
{
throw new InvalidArgumentException("Must provide visibility");
}
siteInfo.setVisibility(siteImpl.getVisibility());
siteService.updateSite(siteInfo);
return siteImpl;
}
@Override
public void deleteSite(final String siteShortName)
{
if (siteService.isSiteAdmin(AuthenticationUtil.getFullyAuthenticatedUser()))
{
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
{
public Void doWork() throws Exception
{
deleteSiteImpl(siteShortName);
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
else
{
deleteSiteImpl(siteShortName);
}
}
private void deleteSiteImpl(String siteShortName)
{
SiteInfo siteInfo = validateSite(siteShortName);
if (siteInfo == null)
{
// site does not exist
throw new EntityNotFoundException(siteShortName);
}
siteService.deleteSite(siteInfo.getShortName());
} }
} }

View File

@@ -16,11 +16,15 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.alfresco.rest.api.sites; package org.alfresco.rest.api.sites;
import org.alfresco.rest.api.Sites; import org.alfresco.rest.api.Sites;
import org.alfresco.rest.api.model.Site; import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.model.SiteImpl;
import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.WebApiParam;
import org.alfresco.rest.framework.core.ResourceParameter.KIND;
import org.alfresco.rest.framework.resource.EntityResource; import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
@@ -35,7 +39,8 @@ import org.springframework.beans.factory.InitializingBean;
* @author steveglover * @author steveglover
*/ */
@EntityResource(name = "sites", title = "Sites") @EntityResource(name = "sites", title = "Sites")
public class SiteEntityResource implements EntityResourceAction.Read<Site>, EntityResourceAction.ReadById<Site>, InitializingBean public class SiteEntityResource implements EntityResourceAction.Read<Site>, EntityResourceAction.ReadById<Site>,
EntityResourceAction.Delete, EntityResourceAction.Update<SiteImpl>, InitializingBean
{ {
private Sites sites; private Sites sites;
@@ -57,6 +62,7 @@ public class SiteEntityResource implements EntityResourceAction.Read<Site>, Enti
*/ */
@Override @Override
@WebApiDescription(title = "A paged list of visible sites in the network.", description = "A site is visible if it is public or if the person is a member") @WebApiDescription(title = "A paged list of visible sites in the network.", description = "A site is visible if it is public or if the person is a member")
@WebApiParam(name = "admin", title = "Admin", description = "An optional filter that when is set to true and the user has site-admin permission, a paged list of all sites in the network will be returned.", kind = KIND.QUERY_STRING)
public CollectionWithPagingInfo<Site> readAll(Parameters parameters) public CollectionWithPagingInfo<Site> readAll(Parameters parameters)
{ {
return sites.getSites(parameters); return sites.getSites(parameters);
@@ -64,7 +70,6 @@ public class SiteEntityResource implements EntityResourceAction.Read<Site>, Enti
/** /**
* Returns information regarding the site 'siteId'. * Returns information regarding the site 'siteId'.
*
*/ */
@Override @Override
@WebApiDescription(title = "Returns site information for site siteId.") @WebApiDescription(title = "Returns site information for site siteId.")
@@ -73,4 +78,27 @@ public class SiteEntityResource implements EntityResourceAction.Read<Site>, Enti
return sites.getSite(siteId); return sites.getSite(siteId);
} }
/**
* PUT sites/{@literal <siteId>}
* <p>
* Updates the <i>visibility</i> of the site.
*/
@Override
@WebApiDescription(title = "Updates the visibility of the site.")
public SiteImpl update(String siteId, SiteImpl entity, Parameters parameters)
{
return sites.updateSite(siteId, entity);
}
/**
* Delete sites/{@literal <siteId>}
* <p>
* Deletes the site.
*/
@Override
@WebApiDescription(title = "Deletes the site.")
public void delete(String siteId, Parameters parameters)
{
sites.deleteSite(siteId);
}
} }

View File

@@ -131,7 +131,8 @@ public class TestSites extends EnterpriseTestApi
} }
catch(PublicApiException e) catch(PublicApiException e)
{ {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // ACE-511: as we added Delete method, the status code needed to be changed from 405 (Method Not Allowed) to 404.
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} }
// invalid site // invalid site