mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge pull request #54 from Alfresco/feature/REPO-2093
REPO-2093: Allow site managers to accept and reject site invitations
This commit is contained in:
@@ -25,9 +25,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.rest.api;
|
package org.alfresco.rest.api;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipApproval;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipRejection;
|
||||||
import org.alfresco.rest.api.model.SiteMembershipRequest;
|
import org.alfresco.rest.api.model.SiteMembershipRequest;
|
||||||
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;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public REST API: centralises access to site membership requests and maps between representations.
|
* Public REST API: centralises access to site membership requests and maps between representations.
|
||||||
@@ -37,6 +40,9 @@ import org.alfresco.rest.framework.resource.parameters.Paging;
|
|||||||
*/
|
*/
|
||||||
public interface SiteMembershipRequests
|
public interface SiteMembershipRequests
|
||||||
{
|
{
|
||||||
|
String PARAM_SITE_ID = "siteId";
|
||||||
|
String PARAM_PERSON_ID = "personId";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a site membership request for the user 'inviteeId'
|
* Create a site membership request for the user 'inviteeId'
|
||||||
* @param inviteeId the site inviteee id
|
* @param inviteeId the site inviteee id
|
||||||
@@ -78,4 +84,10 @@ public interface SiteMembershipRequests
|
|||||||
* @return a paged list of site membership requests
|
* @return a paged list of site membership requests
|
||||||
*/
|
*/
|
||||||
CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(String inviteeId, Paging paging);
|
CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(String inviteeId, Paging paging);
|
||||||
|
|
||||||
|
CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(final Parameters parameters);
|
||||||
|
|
||||||
|
void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval);
|
||||||
|
|
||||||
|
void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection);
|
||||||
}
|
}
|
||||||
|
@@ -26,28 +26,40 @@
|
|||||||
package org.alfresco.rest.api.impl;
|
package org.alfresco.rest.api.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.invitation.InvitationSearchCriteriaImpl;
|
import org.alfresco.repo.invitation.InvitationSearchCriteriaImpl;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
|
import org.alfresco.repo.security.authority.UnknownAuthorityException;
|
||||||
import org.alfresco.repo.site.SiteModel;
|
import org.alfresco.repo.site.SiteModel;
|
||||||
import org.alfresco.repo.tenant.NetworksService;
|
import org.alfresco.repo.tenant.NetworksService;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||||
|
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||||
import org.alfresco.rest.api.People;
|
import org.alfresco.rest.api.People;
|
||||||
import org.alfresco.rest.api.SiteMembershipRequests;
|
import org.alfresco.rest.api.SiteMembershipRequests;
|
||||||
import org.alfresco.rest.api.Sites;
|
import org.alfresco.rest.api.Sites;
|
||||||
|
import org.alfresco.rest.api.model.Person;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipApproval;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipRejection;
|
||||||
import org.alfresco.rest.api.model.SiteMembershipRequest;
|
import org.alfresco.rest.api.model.SiteMembershipRequest;
|
||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||||
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;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.where.Query;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
|
||||||
|
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker;
|
||||||
import org.alfresco.service.cmr.invitation.Invitation;
|
import org.alfresco.service.cmr.invitation.Invitation;
|
||||||
import org.alfresco.service.cmr.invitation.Invitation.ResourceType;
|
import org.alfresco.service.cmr.invitation.Invitation.ResourceType;
|
||||||
import org.alfresco.service.cmr.invitation.InvitationExceptionNotFound;
|
import org.alfresco.service.cmr.invitation.InvitationExceptionNotFound;
|
||||||
@@ -76,6 +88,9 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
// Default role to assign to the site membership request
|
// Default role to assign to the site membership request
|
||||||
public final static String DEFAULT_ROLE = SiteModel.SITE_CONSUMER;
|
public final static String DEFAULT_ROLE = SiteModel.SITE_CONSUMER;
|
||||||
|
|
||||||
|
// List site memberships filtering (via where clause)
|
||||||
|
private final static Set<String> LIST_SITE_MEMBERSHIPS_EQUALS_QUERY_PROPERTIES = new HashSet<>(Arrays.asList(new String[] { PARAM_SITE_ID, PARAM_PERSON_ID }));
|
||||||
|
|
||||||
private People people;
|
private People people;
|
||||||
private Sites sites;
|
private Sites sites;
|
||||||
private SiteService siteService;
|
private SiteService siteService;
|
||||||
@@ -386,6 +401,11 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation)
|
private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation)
|
||||||
|
{
|
||||||
|
return getSiteMembershipRequest(moderatedInvitation, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation, boolean includePersonDetails)
|
||||||
{
|
{
|
||||||
SiteMembershipRequest siteMembershipRequest = null;
|
SiteMembershipRequest siteMembershipRequest = null;
|
||||||
|
|
||||||
@@ -420,6 +440,12 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
|
siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
|
||||||
siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
|
siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
|
||||||
siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
|
siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
|
||||||
|
|
||||||
|
if (includePersonDetails)
|
||||||
|
{
|
||||||
|
Person person = people.getPerson(moderatedInvitation.getInviteeUserName());
|
||||||
|
siteMembershipRequest.setPerson(person);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -430,23 +456,20 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
return siteMembershipRequest;
|
return siteMembershipRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private List<SiteMembershipRequest> toSiteMembershipRequests(List<Invitation> invitations)
|
||||||
public CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(String personId, Paging paging)
|
|
||||||
{
|
{
|
||||||
personId = people.validatePerson(personId, true);
|
return toSiteMembershipRequests(invitations, false);
|
||||||
|
}
|
||||||
|
|
||||||
int skipCount = paging.getSkipCount();
|
private List<SiteMembershipRequest> toSiteMembershipRequests(List<Invitation> invitations, boolean includePersonDetails)
|
||||||
int maxItems = paging.getMaxItems();
|
{
|
||||||
int max = skipCount + maxItems + 1; // to detect hasMoreItems
|
|
||||||
|
|
||||||
List<Invitation> invitations = getSiteInvitations(personId);
|
|
||||||
List<SiteMembershipRequest> siteMembershipRequests = new ArrayList<SiteMembershipRequest>(invitations.size());
|
List<SiteMembershipRequest> siteMembershipRequests = new ArrayList<SiteMembershipRequest>(invitations.size());
|
||||||
for(Invitation invitation : invitations)
|
for(Invitation invitation : invitations)
|
||||||
{
|
{
|
||||||
if(invitation instanceof ModeratedInvitation)
|
if(invitation instanceof ModeratedInvitation)
|
||||||
{
|
{
|
||||||
ModeratedInvitation moderatedInvitation = (ModeratedInvitation)invitation;
|
ModeratedInvitation moderatedInvitation = (ModeratedInvitation)invitation;
|
||||||
SiteMembershipRequest siteMembershipRequest = getSiteMembershipRequest(moderatedInvitation);
|
SiteMembershipRequest siteMembershipRequest = getSiteMembershipRequest(moderatedInvitation, includePersonDetails);
|
||||||
if(siteMembershipRequest != null)
|
if(siteMembershipRequest != null)
|
||||||
{
|
{
|
||||||
// note: siteMembershipRequest may be null if the site is now no longer a moderated site
|
// note: siteMembershipRequest may be null if the site is now no longer a moderated site
|
||||||
@@ -460,7 +483,17 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// unfortunately, need to sort in memory because there's no way to get site membership requests sorted by title from
|
return siteMembershipRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CollectionWithPagingInfo<SiteMembershipRequest> createPagedSiteMembershipRequests(List<SiteMembershipRequest> siteMembershipRequests, Paging paging)
|
||||||
|
{
|
||||||
|
int skipCount = paging.getSkipCount();
|
||||||
|
int maxItems = paging.getMaxItems();
|
||||||
|
int max = skipCount + maxItems + 1; // to detect hasMoreItems
|
||||||
|
|
||||||
|
// unfortunately, need to sort in memory because there's no way to get site
|
||||||
|
// membership requests sorted by title from
|
||||||
// the workflow apis
|
// the workflow apis
|
||||||
Collections.sort(siteMembershipRequests);
|
Collections.sort(siteMembershipRequests);
|
||||||
|
|
||||||
@@ -480,4 +513,162 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
|
|||||||
return CollectionWithPagingInfo.asPaged(paging, siteMembershipRequests, hasMoreItems, totalItems);
|
return CollectionWithPagingInfo.asPaged(paging, siteMembershipRequests, hasMoreItems, totalItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(String personId, Paging paging)
|
||||||
|
{
|
||||||
|
personId = people.validatePerson(personId, true);
|
||||||
|
|
||||||
|
List<Invitation> invitations = getSiteInvitations(personId);
|
||||||
|
return createPagedSiteMembershipRequests(toSiteMembershipRequests(invitations), paging);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionWithPagingInfo<SiteMembershipRequest> getPagedSiteMembershipRequests(final Parameters parameters)
|
||||||
|
{
|
||||||
|
InvitationSearchCriteriaImpl criteria = new InvitationSearchCriteriaImpl();
|
||||||
|
criteria.setInvitationType(InvitationType.MODERATED);
|
||||||
|
criteria.setResourceType(ResourceType.WEB_SITE);
|
||||||
|
|
||||||
|
// Parse where clause properties.
|
||||||
|
Query q = parameters.getQuery();
|
||||||
|
if (q != null)
|
||||||
|
{
|
||||||
|
// Filtering via "where" clause.
|
||||||
|
MapBasedQueryWalker propertyWalker = createSiteMembershipRequestQueryWalker();
|
||||||
|
QueryHelper.walk(q, propertyWalker);
|
||||||
|
|
||||||
|
String siteId = propertyWalker.getProperty(PARAM_SITE_ID, WhereClauseParser.EQUALS, String.class);
|
||||||
|
|
||||||
|
if (siteId != null && !siteId.isEmpty())
|
||||||
|
{
|
||||||
|
criteria.setResourceName(siteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String personId = propertyWalker.getProperty(PARAM_PERSON_ID, WhereClauseParser.EQUALS, String.class);
|
||||||
|
|
||||||
|
if (personId != null && !personId.isEmpty())
|
||||||
|
{
|
||||||
|
criteria.setInvitee(personId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Invitation> invitations = invitationService.searchInvitation(criteria);
|
||||||
|
return createPagedSiteMembershipRequests(toSiteMembershipRequests(invitations, true), parameters.getPaging());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval)
|
||||||
|
{
|
||||||
|
SiteInfo siteInfo = sites.validateSite(siteId);
|
||||||
|
if (siteInfo == null)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
siteId = siteInfo.getShortName();
|
||||||
|
|
||||||
|
// Validate invitation.
|
||||||
|
Invitation invitation = getSiteInvitation(inviteeId, siteId);
|
||||||
|
if (invitation == null || !(invitation instanceof ModeratedInvitation))
|
||||||
|
{
|
||||||
|
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
|
||||||
|
ResourceType resourceType = moderatedInvitation.getResourceType();
|
||||||
|
|
||||||
|
if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility()))
|
||||||
|
{
|
||||||
|
// note: security, no indication that this has a different visibility
|
||||||
|
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
invitationService.approve(invitation.getInviteId(), "");
|
||||||
|
|
||||||
|
if (siteMembershipApproval != null && !(siteMembershipApproval.getRole() == null || siteMembershipApproval.getRole().isEmpty()))
|
||||||
|
{
|
||||||
|
String role = siteMembershipApproval.getRole();
|
||||||
|
|
||||||
|
// Check if role chosen by moderator differs from the invite role.
|
||||||
|
if (!moderatedInvitation.getRoleName().equals(role))
|
||||||
|
{
|
||||||
|
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
|
|
||||||
|
// Update invitation with new role.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
addSiteMembership(invitation.getInviteeUserName(), siteId, role, currentUserId);
|
||||||
|
}
|
||||||
|
catch (UnknownAuthorityException e)
|
||||||
|
{
|
||||||
|
logger.debug("addSiteMember: UnknownAuthorityException " + siteId + " person " + invitation.getInviteId() + " role " + role);
|
||||||
|
throw new InvalidArgumentException("Unknown role '" + role + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection)
|
||||||
|
{
|
||||||
|
SiteInfo siteInfo = sites.validateSite(siteId);
|
||||||
|
if (siteInfo == null)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
siteId = siteInfo.getShortName();
|
||||||
|
|
||||||
|
// Validate invitation.
|
||||||
|
Invitation invitation = getSiteInvitation(inviteeId, siteId);
|
||||||
|
if (invitation == null || !(invitation instanceof ModeratedInvitation))
|
||||||
|
{
|
||||||
|
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
|
||||||
|
ResourceType resourceType = moderatedInvitation.getResourceType();
|
||||||
|
|
||||||
|
if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility()))
|
||||||
|
{
|
||||||
|
// note: security, no indication that this has a different visibility
|
||||||
|
throw new RelationshipResourceNotFoundException(siteId, inviteeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String reason = null;
|
||||||
|
if (siteMembershipRejection != null && !(siteMembershipRejection.getComment() == null || siteMembershipRejection.getComment().isEmpty()))
|
||||||
|
{
|
||||||
|
reason = siteMembershipRejection.getComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
invitationService.reject(invitation.getInviteId(), reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create query walker for <code>listChildren</code>.
|
||||||
|
*
|
||||||
|
* @return The created {@link MapBasedQueryWalker}.
|
||||||
|
*/
|
||||||
|
private MapBasedQueryWalker createSiteMembershipRequestQueryWalker()
|
||||||
|
{
|
||||||
|
return new MapBasedQueryWalker(LIST_SITE_MEMBERSHIPS_EQUALS_QUERY_PROPERTIES, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSiteMembership(final String invitee, final String siteName, final String role, final String runAsUser)
|
||||||
|
{
|
||||||
|
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
siteService.setMembership(siteName, invitee, role);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, runAsUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.model;
|
||||||
|
|
||||||
|
public class SiteMembershipApproval
|
||||||
|
{
|
||||||
|
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
public String getRole()
|
||||||
|
{
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(String role)
|
||||||
|
{
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "SiteMembershipApproval [role=" + role + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.model;
|
||||||
|
|
||||||
|
public class SiteMembershipRejection
|
||||||
|
{
|
||||||
|
|
||||||
|
private String comment;
|
||||||
|
|
||||||
|
public String getComment()
|
||||||
|
{
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment)
|
||||||
|
{
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "SiteMembershipRejection [comment=" + comment + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -52,6 +52,7 @@ public class SiteMembershipRequest implements Comparable<SiteMembershipRequest>
|
|||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
private Date modifiedAt;
|
private Date modifiedAt;
|
||||||
private String title; // for sorting only
|
private String title; // for sorting only
|
||||||
|
private Person person;
|
||||||
|
|
||||||
public static Pair<String, String> splitId(String id)
|
public static Pair<String, String> splitId(String id)
|
||||||
{
|
{
|
||||||
@@ -126,6 +127,16 @@ public class SiteMembershipRequest implements Comparable<SiteMembershipRequest>
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Person getPerson()
|
||||||
|
{
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerson(Person person)
|
||||||
|
{
|
||||||
|
this.person = person;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.sites;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.SiteMembershipRequests;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipApproval;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipRejection;
|
||||||
|
import org.alfresco.rest.framework.Operation;
|
||||||
|
import org.alfresco.rest.framework.WebApiDescription;
|
||||||
|
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
import org.alfresco.rest.framework.webscripts.WithResponse;
|
||||||
|
import org.alfresco.util.ParameterCheck;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
@RelationshipResource(name = "site-membership-requests", entityResource = SiteEntityResource.class, title = "Site Membership Requests")
|
||||||
|
public class SiteMembershipRequestsRelation implements InitializingBean
|
||||||
|
{
|
||||||
|
|
||||||
|
private SiteMembershipRequests siteMembershipRequests;
|
||||||
|
|
||||||
|
public void setSiteMembershipRequests(SiteMembershipRequests siteMembershipRequests)
|
||||||
|
{
|
||||||
|
this.siteMembershipRequests = siteMembershipRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet()
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("siteMembershipRequests", this.siteMembershipRequests);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation("approve")
|
||||||
|
@WebApiDescription(title = "Approve a site membership request.", description = "Approve a site membership request.", successStatus = HttpServletResponse.SC_OK)
|
||||||
|
public void approve(String siteId, String invitationId, SiteMembershipApproval siteMembershipApproval, Parameters parameters, WithResponse withResponse)
|
||||||
|
{
|
||||||
|
siteMembershipRequests.approveSiteMembershipRequest(siteId, invitationId, siteMembershipApproval);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation("reject")
|
||||||
|
@WebApiDescription(title = "Reject a site membership request.", description = "Reject a site membership request.", successStatus = HttpServletResponse.SC_OK)
|
||||||
|
public void reject(String siteId, String invitationId, SiteMembershipRejection siteMembershipRejection, Parameters parameters, WithResponse withResponse)
|
||||||
|
{
|
||||||
|
siteMembershipRequests.rejectSiteMembershipRequest(siteId, invitationId, siteMembershipRejection);
|
||||||
|
}
|
||||||
|
}
|
@@ -872,6 +872,14 @@
|
|||||||
<property name="sites" ref="Sites" />
|
<property name="sites" ref="Sites" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.alfresco.rest.api.sitesmembershipsrequests.SiteMembershipRequestEntityResource">
|
||||||
|
<property name="siteMembershipRequests" ref="SiteMembershipRequests" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<bean class="org.alfresco.rest.api.sites.SiteMembershipRequestsRelation">
|
||||||
|
<property name="siteMembershipRequests" ref="SiteMembershipRequests" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean class="org.alfresco.rest.api.people.PeopleEntityResource">
|
<bean class="org.alfresco.rest.api.people.PeopleEntityResource">
|
||||||
<property name="people" ref="People" />
|
<property name="people" ref="People" />
|
||||||
</bean>
|
</bean>
|
||||||
|
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.sitesmembershipsrequests;
|
||||||
|
|
||||||
|
import org.alfresco.rest.api.SiteMembershipRequests;
|
||||||
|
import org.alfresco.rest.api.model.SiteMembershipRequest;
|
||||||
|
import org.alfresco.rest.framework.WebApiDescription;
|
||||||
|
import org.alfresco.rest.framework.resource.EntityResource;
|
||||||
|
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
import org.alfresco.util.ParameterCheck;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of an Entity Resource for a Site Membership Request
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@EntityResource(name = "site-membership-requests", title = "Site Membership Request")
|
||||||
|
public class SiteMembershipRequestEntityResource implements EntityResourceAction.Read<SiteMembershipRequest>, InitializingBean
|
||||||
|
{
|
||||||
|
private SiteMembershipRequests siteMembershipRequests;
|
||||||
|
|
||||||
|
public void setSiteMembershipRequests(SiteMembershipRequests siteMembershipRequests)
|
||||||
|
{
|
||||||
|
this.siteMembershipRequests = siteMembershipRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet()
|
||||||
|
{
|
||||||
|
ParameterCheck.mandatory("siteMembershipRequests", this.siteMembershipRequests);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a paged list of all site membership request the user can action.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebApiDescription(title = "A paged list of visible site membership requests in the network.")
|
||||||
|
public CollectionWithPagingInfo<SiteMembershipRequest> readAll(Parameters parameters)
|
||||||
|
{
|
||||||
|
return siteMembershipRequests.getPagedSiteMembershipRequests(parameters);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
@WebApi(name="alfresco", scope=Api.SCOPE.PUBLIC, version=1)
|
||||||
|
package org.alfresco.rest.api.sitesmembershipsrequests;
|
||||||
|
import org.alfresco.rest.framework.Api;
|
||||||
|
import org.alfresco.rest.framework.WebApi;
|
@@ -33,8 +33,10 @@ import static org.junit.Assert.fail;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
@@ -43,25 +45,35 @@ import org.alfresco.rest.api.tests.RepoService.SiteInformation;
|
|||||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||||
import org.alfresco.rest.api.tests.RepoService.TestSite;
|
import org.alfresco.rest.api.tests.RepoService.TestSite;
|
||||||
|
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.SiteMembershipRequests;
|
import org.alfresco.rest.api.tests.client.PublicApiClient.SiteMembershipRequests;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.MemberOfSite;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.SiteMembershipApproval;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.SiteMembershipRejection;
|
||||||
import org.alfresco.rest.api.tests.client.data.SiteMembershipRequest;
|
import org.alfresco.rest.api.tests.client.data.SiteMembershipRequest;
|
||||||
import org.alfresco.rest.api.tests.client.data.SiteRole;
|
import org.alfresco.rest.api.tests.client.data.SiteRole;
|
||||||
|
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||||
import org.alfresco.service.cmr.invitation.Invitation;
|
import org.alfresco.service.cmr.invitation.Invitation;
|
||||||
import org.alfresco.service.cmr.invitation.ModeratedInvitation;
|
import org.alfresco.service.cmr.invitation.ModeratedInvitation;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||||
import org.alfresco.util.GUID;
|
import org.alfresco.util.GUID;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class TestSiteMembershipRequests extends EnterpriseTestApi
|
public class TestSiteMembershipRequests extends EnterpriseTestApi
|
||||||
{
|
{
|
||||||
|
private static final String URL_SITES = "sites";
|
||||||
|
|
||||||
private TestNetwork network1;
|
private TestNetwork network1;
|
||||||
private TestNetwork network2;
|
private TestNetwork network2;
|
||||||
|
|
||||||
@@ -1462,4 +1474,447 @@ public class TestSiteMembershipRequests extends EnterpriseTestApi
|
|||||||
siteMembershipRequest.setMessage("Please can I join your site?");
|
siteMembershipRequest.setMessage("Please can I join your site?");
|
||||||
SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
|
SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetSiteMembershipRequests() throws Exception
|
||||||
|
{
|
||||||
|
String networkId = network1.getId();
|
||||||
|
|
||||||
|
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
|
||||||
|
|
||||||
|
// note: username for site creator is of the form user@network
|
||||||
|
TestPerson siteManager = network1.createUser();
|
||||||
|
TestPerson person1 = network1.createUser();
|
||||||
|
TestPerson person2 = network1.createUser();
|
||||||
|
|
||||||
|
TestSite sitePublic = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception
|
||||||
|
{
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.PUBLIC);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception
|
||||||
|
{
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
TestSite site2 = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception
|
||||||
|
{
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Public site.
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
|
||||||
|
siteMembershipRequest.setId(sitePublic.getSiteId());
|
||||||
|
siteMembershipRequest.setMessage("Please can I join your site?");
|
||||||
|
SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
|
||||||
|
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
// Moderated site.
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
siteMembershipRequest = new SiteMembershipRequest();
|
||||||
|
siteMembershipRequest.setId(site.getSiteId());
|
||||||
|
siteMembershipRequest.setMessage("Please can I join your site?");
|
||||||
|
ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
|
||||||
|
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
int skipCount = 0;
|
||||||
|
int maxItems = Integer.MAX_VALUE;
|
||||||
|
Paging paging = getPaging(skipCount, maxItems);
|
||||||
|
|
||||||
|
// Test that we have a moderated site request only.
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
|
||||||
|
List<SiteMembershipRequest> list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
|
SiteMembershipRequest smr = list.get(0);
|
||||||
|
|
||||||
|
// Check if the person details is retrieved.
|
||||||
|
assertNotNull(smr.getPerson());
|
||||||
|
assertNotNull(smr.getPerson().getUserName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the user has no site membership requests.
|
||||||
|
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person2.getId()));
|
||||||
|
|
||||||
|
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
|
||||||
|
List<SiteMembershipRequest> list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test retrieve site membership request using where clause.
|
||||||
|
|
||||||
|
{
|
||||||
|
// Prepare test data.
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person2.getId()));
|
||||||
|
ret = createSiteMembershipRequest(site.getSiteId(), person2.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
ret = createSiteMembershipRequest(site2.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
|
||||||
|
List<SiteMembershipRequest> list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
|
||||||
|
// Test filter by site id.
|
||||||
|
|
||||||
|
Map<String, String> otherParams = new HashMap<>();
|
||||||
|
otherParams.put("where", "(siteId='" + site.getSiteId() + "')");
|
||||||
|
|
||||||
|
resp = getSiteMembershipRequests(paging, otherParams);
|
||||||
|
list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
|
||||||
|
// Test filter by person id.
|
||||||
|
|
||||||
|
otherParams = new HashMap<>();
|
||||||
|
otherParams.put("where", "(personId='" + person2.getId() + "')");
|
||||||
|
|
||||||
|
resp = getSiteMembershipRequests(paging, otherParams);
|
||||||
|
list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
|
// Test filter by site and personId
|
||||||
|
|
||||||
|
otherParams = new HashMap<>();
|
||||||
|
otherParams.put("where", "(siteId='" + site.getSiteId() + "' and personId='" + person2.getId() + "')");
|
||||||
|
|
||||||
|
resp = getSiteMembershipRequests(paging, otherParams);
|
||||||
|
list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TestPerson person3 = network1.createUser();
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person3.getId()));
|
||||||
|
ret = createSiteMembershipRequest(site.getSiteId(), person3.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
approve(site.getSiteId(), person3.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_OK, null);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person3.getId()));
|
||||||
|
|
||||||
|
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, null);
|
||||||
|
List<SiteMembershipRequest> list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApproveSiteMembershipRequests() throws Exception {
|
||||||
|
String networkId = network1.getId();
|
||||||
|
|
||||||
|
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
|
||||||
|
|
||||||
|
TestPerson siteManager = network1.createUser();
|
||||||
|
|
||||||
|
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception {
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
TestPerson person1 = network1.createUser();
|
||||||
|
TestPerson person2 = network1.createUser();
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
SiteMembershipRequest ret = createSiteMembershipRequest(site.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
// Site not found.
|
||||||
|
approve("siteId", person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
// Invitee not found.
|
||||||
|
approve(site.getSiteId(), null, new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
// Invitation not found.
|
||||||
|
approve(site.getSiteId(), person2.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
{
|
||||||
|
// Create moderated site.
|
||||||
|
TestSite tempSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception {
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Create site membership request
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
ret = createSiteMembershipRequest(tempSite.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
// Change site visibility to private.
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
SiteInfo tempSiteInfo = tempSite.getSiteInfo();
|
||||||
|
assertEquals(SiteVisibility.MODERATED, tempSiteInfo.getVisibility());
|
||||||
|
|
||||||
|
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
tempSite.setSiteVisibility(SiteVisibility.PRIVATE);
|
||||||
|
assertEquals(SiteVisibility.PRIVATE, tempSiteInfo.getVisibility());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Site private so not found error.
|
||||||
|
approve(tempSite.getSiteId(), person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// User tries to approve his own request.
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person1.getId()));
|
||||||
|
|
||||||
|
approve(site.getSiteId(), person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid request.
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
approve(site.getSiteId(), person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_OK, null);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person1.getId()));
|
||||||
|
|
||||||
|
MemberOfSite memberOfSite = publicApiClient.sites().getPersonSite(person1.getId(), site.getSiteId());
|
||||||
|
assertNotNull(memberOfSite);
|
||||||
|
assertEquals(SiteRole.SiteConsumer, memberOfSite.getRole());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Approve again.
|
||||||
|
approve(site.getSiteId(), person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
{
|
||||||
|
TestSite tempSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception {
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Create site membership request
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
ret = createSiteMembershipRequest(tempSite.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
// Invalid role.
|
||||||
|
approve(tempSite.getSiteId(), person1.getId(), new SiteMembershipApproval("invalidRole"), HttpServletResponse.SC_BAD_REQUEST, null);
|
||||||
|
|
||||||
|
approve(tempSite.getSiteId(), person1.getId(), new SiteMembershipApproval(SiteRole.SiteCollaborator.toString()), HttpServletResponse.SC_OK, null);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person1.getId()));
|
||||||
|
|
||||||
|
MemberOfSite memberOfSite = publicApiClient.sites().getPersonSite(person1.getId(), tempSite.getSiteId());
|
||||||
|
assertNotNull(memberOfSite);
|
||||||
|
assertEquals(SiteRole.SiteCollaborator, memberOfSite.getRole());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRejectSiteMembershipRequests() throws Exception {
|
||||||
|
String networkId = network1.getId();
|
||||||
|
|
||||||
|
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
|
||||||
|
|
||||||
|
TestPerson siteManager = network1.createUser();
|
||||||
|
|
||||||
|
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception {
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
TestPerson person1 = network1.createUser();
|
||||||
|
TestPerson person2 = network1.createUser();
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
SiteMembershipRequest ret = createSiteMembershipRequest(site.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
// Site not found.
|
||||||
|
reject("siteId", person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
// Invitee not found.
|
||||||
|
reject(site.getSiteId(), null, new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
// Invitation not found.
|
||||||
|
reject(site.getSiteId(), person2.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
|
||||||
|
{
|
||||||
|
// Create moderated site.
|
||||||
|
TestSite tempSite = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
|
||||||
|
@Override
|
||||||
|
public TestSite doWork() throws Exception {
|
||||||
|
TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Create site membership request
|
||||||
|
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
|
||||||
|
ret = createSiteMembershipRequest(tempSite.getSiteId(), person1.getId());
|
||||||
|
assertNotNull(ret);
|
||||||
|
|
||||||
|
// Change site visibility to private.
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
SiteInfo tempSiteInfo = tempSite.getSiteInfo();
|
||||||
|
assertEquals(SiteVisibility.MODERATED, tempSiteInfo.getVisibility());
|
||||||
|
|
||||||
|
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void doWork() throws Exception
|
||||||
|
{
|
||||||
|
tempSite.setSiteVisibility(SiteVisibility.PRIVATE);
|
||||||
|
assertEquals(SiteVisibility.PRIVATE, tempSiteInfo.getVisibility());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, siteManager.getId(), networkId);
|
||||||
|
|
||||||
|
// Site private so not found error.
|
||||||
|
reject(tempSite.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// User tries to reject his own request.
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, person1.getId()));
|
||||||
|
|
||||||
|
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid request.
|
||||||
|
{
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(networkId, siteManager.getId()));
|
||||||
|
|
||||||
|
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_OK, null);
|
||||||
|
|
||||||
|
int skipCount = 0;
|
||||||
|
int maxItems = Integer.MAX_VALUE;
|
||||||
|
Paging paging = getPaging(skipCount, maxItems);
|
||||||
|
|
||||||
|
Map<String, String> otherParams = new HashMap<>();
|
||||||
|
otherParams.put("where", "(siteId='" + site.getSiteId() + "')");
|
||||||
|
|
||||||
|
ListResponse<SiteMembershipRequest> resp = getSiteMembershipRequests(paging, otherParams);
|
||||||
|
List<SiteMembershipRequest> list = resp.getList();
|
||||||
|
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject again.
|
||||||
|
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ListResponse<SiteMembershipRequest> getSiteMembershipRequests(final Paging paging, Map<String, String> otherParams) throws Exception
|
||||||
|
{
|
||||||
|
return siteMembershipRequestsProxy.getSiteMembershipRequests(createParams(paging, otherParams), "Failed to get site membership requests", HttpServletResponse.SC_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SiteMembershipRequest createSiteMembershipRequest(String siteId, String personId) throws ParseException, PublicApiException
|
||||||
|
{
|
||||||
|
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
|
||||||
|
siteMembershipRequest.setId(siteId);
|
||||||
|
siteMembershipRequest.setMessage("Please can I join your site?");
|
||||||
|
|
||||||
|
return siteMembershipRequestsProxy.createSiteMembershipRequest(personId, siteMembershipRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void approve(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval, int expectedStatus, Map<String, String> parameters) throws Exception
|
||||||
|
{
|
||||||
|
String scope = "public";
|
||||||
|
String url = getMembershipRequestApprovalUrl(siteId, inviteeId);
|
||||||
|
String body = RestApiUtil.toJsonAsString(siteMembershipApproval);
|
||||||
|
|
||||||
|
HttpResponse response = publicApiClient.post(scope, url, null, null, null, body);
|
||||||
|
checkStatus(expectedStatus, response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reject(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection, int expectedStatus, Map<String, String> parameters) throws Exception
|
||||||
|
{
|
||||||
|
String scope = "public";
|
||||||
|
String url = getMembershipRequestRejectionUrl(siteId, inviteeId);
|
||||||
|
String body = RestApiUtil.toJsonAsString(siteMembershipRejection);
|
||||||
|
|
||||||
|
HttpResponse response = publicApiClient.post(scope, url, null, null, null, body);
|
||||||
|
checkStatus(expectedStatus, response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMembershipRequestApprovalUrl(String siteId, String inviteeId)
|
||||||
|
{
|
||||||
|
return getMembershipRequestUrlByAction(siteId, inviteeId, "approve");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMembershipRequestRejectionUrl(String siteId, String inviteeId)
|
||||||
|
{
|
||||||
|
return getMembershipRequestUrlByAction(siteId, inviteeId, "reject");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMembershipRequestUrlByAction(String siteId, String inviteeId, String action)
|
||||||
|
{
|
||||||
|
return URL_SITES + '/' + siteId + "/site-membership-requests/" + inviteeId + "/" + action;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkStatus(int expectedStatus, int actualStatus)
|
||||||
|
{
|
||||||
|
if (expectedStatus > 0 && expectedStatus != actualStatus)
|
||||||
|
{
|
||||||
|
fail("Status code " + actualStatus + " returned, but expected " + expectedStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,20 +43,19 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
||||||
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
|
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
|
||||||
import org.alfresco.rest.api.model.ActionDefinition;
|
import org.alfresco.rest.api.model.ActionDefinition;
|
||||||
import org.alfresco.rest.api.tests.client.data.Action;
|
|
||||||
import org.alfresco.rest.api.tests.client.data.AuditEntry;
|
|
||||||
import org.alfresco.rest.api.model.SiteUpdate;
|
import org.alfresco.rest.api.model.SiteUpdate;
|
||||||
import org.alfresco.rest.api.tests.TestPeople;
|
import org.alfresco.rest.api.tests.TestPeople;
|
||||||
import org.alfresco.rest.api.tests.TestSites;
|
import org.alfresco.rest.api.tests.TestSites;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.BinaryPayload;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
|
import org.alfresco.rest.api.tests.client.PublicApiHttpClient.RequestBuilder;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.Action;
|
||||||
import org.alfresco.rest.api.tests.client.data.Activities;
|
import org.alfresco.rest.api.tests.client.data.Activities;
|
||||||
import org.alfresco.rest.api.tests.client.data.Activity;
|
import org.alfresco.rest.api.tests.client.data.Activity;
|
||||||
import org.alfresco.rest.api.tests.client.data.AuditApp;
|
import org.alfresco.rest.api.tests.client.data.AuditApp;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.AuditEntry;
|
||||||
import org.alfresco.rest.api.tests.client.data.CMISNode;
|
import org.alfresco.rest.api.tests.client.data.CMISNode;
|
||||||
import org.alfresco.rest.api.tests.client.data.Comment;
|
import org.alfresco.rest.api.tests.client.data.Comment;
|
||||||
import org.alfresco.rest.api.tests.client.data.ContentData;
|
import org.alfresco.rest.api.tests.client.data.ContentData;
|
||||||
@@ -107,6 +106,8 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A client for interacting with the public api and returning Java objects.
|
* A client for interacting with the public api and returning Java objects.
|
||||||
*
|
*
|
||||||
@@ -1138,26 +1139,26 @@ public class PublicApiClient
|
|||||||
public SiteMembershipRequest getSiteMembershipRequest(String personId, String siteId) throws PublicApiException, ParseException
|
public SiteMembershipRequest getSiteMembershipRequest(String personId, String siteId) throws PublicApiException, ParseException
|
||||||
{
|
{
|
||||||
HttpResponse response = getSingle("people", personId, "site-membership-requests", siteId, "Failed to get siteMembershipRequest");
|
HttpResponse response = getSingle("people", personId, "site-membership-requests", siteId, "Failed to get siteMembershipRequest");
|
||||||
return SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry"));
|
return SiteMembershipRequest.parseSiteMembershipRequest((JSONObject) response.getJsonResponse().get("entry"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListResponse<SiteMembershipRequest> getSiteMembershipRequests(String personId, Map<String, String> params) throws PublicApiException, ParseException
|
public ListResponse<SiteMembershipRequest> getSiteMembershipRequests(String personId, Map<String, String> params) throws PublicApiException, ParseException
|
||||||
{
|
{
|
||||||
HttpResponse response = getAll("people", personId, "site-membership-requests", null, params, "Failed to get siteMembershipRequests");
|
HttpResponse response = getAll("people", personId, "site-membership-requests", null, params, "Failed to get siteMembershipRequests");
|
||||||
return SiteMembershipRequest.parseSiteMembershipRequests(personId, response.getJsonResponse());
|
return SiteMembershipRequest.parseSiteMembershipRequests(response.getJsonResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SiteMembershipRequest createSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException
|
public SiteMembershipRequest createSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException
|
||||||
{
|
{
|
||||||
HttpResponse response = create("people", personId, "site-membership-requests", null, siteMembershipRequest.toJSON().toString(), "Failed to create siteMembershipRequest");
|
HttpResponse response = create("people", personId, "site-membership-requests", null, siteMembershipRequest.toJSON().toString(), "Failed to create siteMembershipRequest");
|
||||||
SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry"));
|
SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest((JSONObject) response.getJsonResponse().get("entry"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SiteMembershipRequest updateSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException
|
public SiteMembershipRequest updateSiteMembershipRequest(String personId, SiteMembershipRequest siteMembershipRequest) throws PublicApiException, ParseException
|
||||||
{
|
{
|
||||||
HttpResponse response = update("people", personId, "site-membership-requests", siteMembershipRequest.getId(), siteMembershipRequest.toJSON().toString(), "Failed to update siteMembershipRequest");
|
HttpResponse response = update("people", personId, "site-membership-requests", siteMembershipRequest.getId(), siteMembershipRequest.toJSON().toString(), "Failed to update siteMembershipRequest");
|
||||||
SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry"));
|
SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest((JSONObject) response.getJsonResponse().get("entry"));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1165,6 +1166,21 @@ public class PublicApiClient
|
|||||||
{
|
{
|
||||||
remove("people", personId, "site-membership-requests", siteMembershipRequestId, "Failed to cancel siteMembershipRequest");
|
remove("people", personId, "site-membership-requests", siteMembershipRequestId, "Failed to cancel siteMembershipRequest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListResponse<SiteMembershipRequest> getSiteMembershipRequests(Map<String, String> params, String errorMessage, int expectedStatus) throws PublicApiException, ParseException
|
||||||
|
{
|
||||||
|
HttpResponse response = getAll("site-membership-requests", null, null, null, params, errorMessage, expectedStatus);
|
||||||
|
|
||||||
|
if (response != null && response.getJsonResponse() != null)
|
||||||
|
{
|
||||||
|
JSONObject jsonList = (JSONObject) response.getJsonResponse().get("list");
|
||||||
|
if (jsonList != null)
|
||||||
|
{
|
||||||
|
return SiteMembershipRequest.parseSiteMembershipRequests(response.getJsonResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RawProxy extends AbstractProxy
|
public class RawProxy extends AbstractProxy
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.tests.client.data;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class SiteMembershipApproval extends org.alfresco.rest.api.model.SiteMembershipApproval
|
||||||
|
{
|
||||||
|
|
||||||
|
public SiteMembershipApproval()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SiteMembershipApproval(String role)
|
||||||
|
{
|
||||||
|
setRole(role);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON()
|
||||||
|
{
|
||||||
|
JSONObject siteMembershipRequestJson = new JSONObject();
|
||||||
|
siteMembershipRequestJson.put("role", getRole());
|
||||||
|
return siteMembershipRequestJson;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Remote API
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.rest.api.tests.client.data;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class SiteMembershipRejection extends org.alfresco.rest.api.model.SiteMembershipRejection
|
||||||
|
{
|
||||||
|
|
||||||
|
public SiteMembershipRejection()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SiteMembershipRejection(String comment)
|
||||||
|
{
|
||||||
|
setComment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON()
|
||||||
|
{
|
||||||
|
JSONObject siteMembershipRequestJson = new JSONObject();
|
||||||
|
siteMembershipRequestJson.put("comment", getComment());
|
||||||
|
return siteMembershipRequestJson;
|
||||||
|
}
|
||||||
|
}
|
@@ -51,6 +51,7 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable<Sit
|
|||||||
private Date modifiedAt;
|
private Date modifiedAt;
|
||||||
private String title;
|
private String title;
|
||||||
private Site site;
|
private Site site;
|
||||||
|
private Person person;
|
||||||
|
|
||||||
public SiteMembershipRequest()
|
public SiteMembershipRequest()
|
||||||
{
|
{
|
||||||
@@ -116,6 +117,14 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable<Sit
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Person getPerson() {
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPerson(Person person) {
|
||||||
|
this.person = person;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public JSONObject toJSON()
|
public JSONObject toJSON()
|
||||||
{
|
{
|
||||||
@@ -125,13 +134,14 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable<Sit
|
|||||||
return siteMembershipRequestJson;
|
return siteMembershipRequestJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SiteMembershipRequest parseSiteMembershipRequest(String username, JSONObject jsonObject) throws ParseException
|
public static SiteMembershipRequest parseSiteMembershipRequest(JSONObject jsonObject) throws ParseException
|
||||||
{
|
{
|
||||||
String id = (String)jsonObject.get("id");
|
String id = (String)jsonObject.get("id");
|
||||||
String createdAt = (String)jsonObject.get("createdAt");
|
String createdAt = (String)jsonObject.get("createdAt");
|
||||||
String message = (String)jsonObject.get("message");
|
String message = (String)jsonObject.get("message");
|
||||||
String modifiedAt = (String)jsonObject.get("modifiedAt");
|
String modifiedAt = (String)jsonObject.get("modifiedAt");
|
||||||
JSONObject siteJSON = (JSONObject)jsonObject.get("site");
|
JSONObject siteJSON = (JSONObject)jsonObject.get("site");
|
||||||
|
JSONObject personJSON = (JSONObject)jsonObject.get("person");
|
||||||
|
|
||||||
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
|
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
|
||||||
siteMembershipRequest.setId(id);
|
siteMembershipRequest.setId(id);
|
||||||
@@ -146,11 +156,16 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable<Sit
|
|||||||
Site site = SiteImpl.parseSite(siteJSON);
|
Site site = SiteImpl.parseSite(siteJSON);
|
||||||
siteMembershipRequest.setSite(site);
|
siteMembershipRequest.setSite(site);
|
||||||
}
|
}
|
||||||
|
if (personJSON != null)
|
||||||
|
{
|
||||||
|
Person person = Person.parsePerson(personJSON);
|
||||||
|
siteMembershipRequest.setPerson(person);
|
||||||
|
}
|
||||||
|
|
||||||
return siteMembershipRequest;
|
return siteMembershipRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListResponse<SiteMembershipRequest> parseSiteMembershipRequests(String username, JSONObject jsonObject) throws ParseException
|
public static ListResponse<SiteMembershipRequest> parseSiteMembershipRequests(JSONObject jsonObject) throws ParseException
|
||||||
{
|
{
|
||||||
List<SiteMembershipRequest> siteMembershipRequests = new ArrayList<SiteMembershipRequest>();
|
List<SiteMembershipRequest> siteMembershipRequests = new ArrayList<SiteMembershipRequest>();
|
||||||
|
|
||||||
@@ -164,11 +179,11 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable<Sit
|
|||||||
{
|
{
|
||||||
JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
|
JSONObject jsonEntry = (JSONObject)jsonEntries.get(i);
|
||||||
JSONObject entry = (JSONObject)jsonEntry.get("entry");
|
JSONObject entry = (JSONObject)jsonEntry.get("entry");
|
||||||
siteMembershipRequests.add(SiteMembershipRequest.parseSiteMembershipRequest(username, entry));
|
siteMembershipRequests.add(SiteMembershipRequest.parseSiteMembershipRequest(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
|
ExpectedPaging paging = ExpectedPaging.parsePagination(jsonList);
|
||||||
return new ListResponse<SiteMembershipRequest>(paging, siteMembershipRequests);
|
return new ListResponse<>(paging, siteMembershipRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user