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

64426: Merged WAT1 (4.3/Cloud) to HEAD-BUG-FIX (4.3/Cloud)
      62536: Reverted Sites Public REST API changes, committed in r61735 and r62502. Also updated CloudSiteServiceImpl overlay to override isSiteAdmin method.


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

View File

@@ -16,7 +16,6 @@
* 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;
@@ -24,7 +23,6 @@ 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;
@@ -36,17 +34,10 @@ 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>
* *
@@ -55,32 +46,19 @@ 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,7 +34,6 @@
* 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;
@@ -86,7 +85,6 @@ 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;
@@ -191,8 +189,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();
@@ -243,8 +240,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
SiteRole role = null; SiteRole role = null;
if(includeRole) if(includeRole)
@@ -272,8 +268,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// 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);
@@ -326,8 +321,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
SiteRole siteRole = siteMember.getRole(); SiteRole siteRole = siteMember.getRole();
@@ -360,8 +354,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// 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);
@@ -435,8 +428,7 @@ 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(), MemberOfSite memberOfSite = new MemberOfSite(siteInfo.getShortName(), siteInfo.getNodeRef(), siteMember.getRole());
siteMember.getRole());
ret.add(memberOfSite); ret.add(memberOfSite);
} }
@@ -452,8 +444,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// 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);
@@ -462,8 +453,7 @@ 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 // check that the containerId is actually a container for the specified site
// site
SiteInfo testSiteInfo = siteService.getSite(containerNodeRef); SiteInfo testSiteInfo = siteService.getSite(containerNodeRef);
if(testSiteInfo == null) if(testSiteInfo == null)
{ {
@@ -492,8 +482,7 @@ public class SitesImpl implements Sites
throw new EntityNotFoundException(siteId); throw new EntityNotFoundException(siteId);
} }
final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging));
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)
@@ -537,28 +526,11 @@ public class SitesImpl implements Sites
final BeanPropertiesFilter filter = parameters.getFilter(); final BeanPropertiesFilter filter = parameters.getFilter();
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();
final PagingRequest pagingRequest = Util.getPagingRequest(paging); PagingRequest pagingRequest = Util.getPagingRequest(paging);
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax) // pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
final List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(); 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();
@@ -597,8 +569,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// issues with using the siteId from the url)
siteId = siteInfo.getShortName(); siteId = siteInfo.getShortName();
NodeRef nodeRef = siteInfo.getNodeRef(); NodeRef nodeRef = siteInfo.getNodeRef();
@@ -623,8 +594,7 @@ 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 // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
// 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);
@@ -693,8 +663,7 @@ public class SitesImpl implements Sites
} }
if(isFavourite) if(isFavourite)
{ {
String siteShortName = entry.getKey().substring(FAVOURITE_SITES_PREFIX_LENGTH) String siteShortName = entry.getKey().substring(FAVOURITE_SITES_PREFIX_LENGTH).replace(".favourited", "");
.replace(".favourited", "");
SiteInfo siteInfo = siteService.getSite(siteShortName); SiteInfo siteInfo = siteService.getSite(siteShortName);
if(siteInfo != null) if(siteInfo != null)
{ {
@@ -774,80 +743,6 @@ public class SitesImpl implements Sites
favourites.add(favourite); favourites.add(favourite);
} }
return CollectionWithPagingInfo.asPaged(paging, favourites, favouriteSites.hasMoreItems(), favouriteSites return CollectionWithPagingInfo.asPaged(paging, favourites, favouriteSites.hasMoreItems(), favouriteSites.getTotalResultCount().getFirst());
.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,15 +16,11 @@
* 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;
@@ -39,8 +35,7 @@ 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>, public class SiteEntityResource implements EntityResourceAction.Read<Site>, EntityResourceAction.ReadById<Site>, InitializingBean
EntityResourceAction.Delete, EntityResourceAction.Update<SiteImpl>, InitializingBean
{ {
private Sites sites; private Sites sites;
@@ -62,7 +57,6 @@ 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);
@@ -70,6 +64,7 @@ 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.")
@@ -78,27 +73,4 @@ 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,8 +131,7 @@ public class TestSites extends EnterpriseTestApi
} }
catch(PublicApiException e) catch(PublicApiException e)
{ {
// ACE-511: as we added Delete method, the status code needed to be changed from 405 (Method Not Allowed) to 404. assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
} }
// invalid site // invalid site