diff --git a/src/main/java/org/alfresco/rest/api/SiteMembershipRequests.java b/src/main/java/org/alfresco/rest/api/SiteMembershipRequests.java
index 9538aa8a6f..fa6892b1df 100644
--- a/src/main/java/org/alfresco/rest/api/SiteMembershipRequests.java
+++ b/src/main/java/org/alfresco/rest/api/SiteMembershipRequests.java
@@ -1,33 +1,36 @@
-/*
- * #%L
- * Alfresco Remote API
- * %%
- * Copyright (C) 2005 - 2016 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 .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Remote API
+ * %%
+ * Copyright (C) 2005 - 2016 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 .
+ * #L%
+ */
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.framework.resource.parameters.CollectionWithPagingInfo;
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.
@@ -37,6 +40,9 @@ import org.alfresco.rest.framework.resource.parameters.Paging;
*/
public interface SiteMembershipRequests
{
+ String PARAM_SITE_ID = "siteId";
+ String PARAM_PERSON_ID = "personId";
+
/**
* Create a site membership request for the user 'inviteeId'
* @param inviteeId the site inviteee id
@@ -78,4 +84,10 @@ public interface SiteMembershipRequests
* @return a paged list of site membership requests
*/
CollectionWithPagingInfo getPagedSiteMembershipRequests(String inviteeId, Paging paging);
+
+ CollectionWithPagingInfo getPagedSiteMembershipRequests(final Parameters parameters);
+
+ void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval);
+
+ void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection);
}
diff --git a/src/main/java/org/alfresco/rest/api/impl/SiteMembershipRequestsImpl.java b/src/main/java/org/alfresco/rest/api/impl/SiteMembershipRequestsImpl.java
index 0367200421..7fd4173da1 100644
--- a/src/main/java/org/alfresco/rest/api/impl/SiteMembershipRequestsImpl.java
+++ b/src/main/java/org/alfresco/rest/api/impl/SiteMembershipRequestsImpl.java
@@ -26,28 +26,40 @@
package org.alfresco.rest.api.impl;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.invitation.InvitationSearchCriteriaImpl;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
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.tenant.NetworksService;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
+import org.alfresco.rest.antlr.WhereClauseParser;
import org.alfresco.rest.api.People;
import org.alfresco.rest.api.SiteMembershipRequests;
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.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
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.ResourceType;
import org.alfresco.service.cmr.invitation.InvitationExceptionNotFound;
@@ -74,7 +86,10 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
private static final Log logger = LogFactory.getLog(SiteMembershipRequestsImpl.class);
// 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 LIST_SITE_MEMBERSHIPS_EQUALS_QUERY_PROPERTIES = new HashSet<>(Arrays.asList(new String[] { PARAM_SITE_ID, PARAM_PERSON_ID }));
private People people;
private Sites sites;
@@ -384,8 +399,13 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
throw new RelationshipResourceNotFoundException(inviteeId, siteId);
}
}
-
- private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation)
+
+ private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation)
+ {
+ return getSiteMembershipRequest(moderatedInvitation, false);
+ }
+
+ private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation, boolean includePersonDetails)
{
SiteMembershipRequest siteMembershipRequest = null;
@@ -420,6 +440,12 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
+
+ if (includePersonDetails)
+ {
+ Person person = people.getPerson(moderatedInvitation.getInviteeUserName());
+ siteMembershipRequest.setPerson(person);
+ }
}
}
else
@@ -428,25 +454,22 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
}
return siteMembershipRequest;
- }
-
- @Override
- public CollectionWithPagingInfo getPagedSiteMembershipRequests(String personId, Paging paging)
- {
- personId = people.validatePerson(personId, true);
+ }
- int skipCount = paging.getSkipCount();
- int maxItems = paging.getMaxItems();
- int max = skipCount + maxItems + 1; // to detect hasMoreItems
+ private List toSiteMembershipRequests(List invitations)
+ {
+ return toSiteMembershipRequests(invitations, false);
+ }
- List invitations = getSiteInvitations(personId);
+ private List toSiteMembershipRequests(List invitations, boolean includePersonDetails)
+ {
List siteMembershipRequests = new ArrayList(invitations.size());
for(Invitation invitation : invitations)
{
if(invitation instanceof ModeratedInvitation)
{
ModeratedInvitation moderatedInvitation = (ModeratedInvitation)invitation;
- SiteMembershipRequest siteMembershipRequest = getSiteMembershipRequest(moderatedInvitation);
+ SiteMembershipRequest siteMembershipRequest = getSiteMembershipRequest(moderatedInvitation, includePersonDetails);
if(siteMembershipRequest != null)
{
// note: siteMembershipRequest may be null if the site is now no longer a moderated site
@@ -459,25 +482,193 @@ public class SiteMembershipRequestsImpl implements SiteMembershipRequests
// just ignore, shouldn't happen because getSiteInvitations filters by ModeratedInvitation
}
}
+
+ return siteMembershipRequests;
+ }
- // unfortunately, need to sort in memory because there's no way to get site membership requests sorted by title from
- // the workflow apis
- Collections.sort(siteMembershipRequests);
+ private CollectionWithPagingInfo createPagedSiteMembershipRequests(List siteMembershipRequests, Paging paging)
+ {
+ int skipCount = paging.getSkipCount();
+ int maxItems = paging.getMaxItems();
+ int max = skipCount + maxItems + 1; // to detect hasMoreItems
- int totalItems = siteMembershipRequests.size();
+ // unfortunately, need to sort in memory because there's no way to get site
+ // membership requests sorted by title from
+ // the workflow apis
+ Collections.sort(siteMembershipRequests);
- if(skipCount >= totalItems)
- {
- List empty = Collections.emptyList();
- return CollectionWithPagingInfo.asPaged(paging, empty, false, totalItems);
- }
- else
- {
- int end = Math.min(max - 1, totalItems);
- boolean hasMoreItems = totalItems > end;
+ int totalItems = siteMembershipRequests.size();
- siteMembershipRequests = siteMembershipRequests.subList(skipCount, end);
- return CollectionWithPagingInfo.asPaged(paging, siteMembershipRequests, hasMoreItems, totalItems);
- }
- }
+ if (skipCount >= totalItems)
+ {
+ List empty = Collections.emptyList();
+ return CollectionWithPagingInfo.asPaged(paging, empty, false, totalItems);
+ }
+ else
+ {
+ int end = Math.min(max - 1, totalItems);
+ boolean hasMoreItems = totalItems > end;
+
+ siteMembershipRequests = siteMembershipRequests.subList(skipCount, end);
+ return CollectionWithPagingInfo.asPaged(paging, siteMembershipRequests, hasMoreItems, totalItems);
+ }
+ }
+
+ @Override
+ public CollectionWithPagingInfo getPagedSiteMembershipRequests(String personId, Paging paging)
+ {
+ personId = people.validatePerson(personId, true);
+
+ List invitations = getSiteInvitations(personId);
+ return createPagedSiteMembershipRequests(toSiteMembershipRequests(invitations), paging);
+ }
+
+ @Override
+ public CollectionWithPagingInfo 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 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 listChildren
.
+ *
+ * @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()
+ {
+ public Void doWork() throws Exception
+ {
+ siteService.setMembership(siteName, invitee, role);
+ return null;
+ }
+
+ }, runAsUser);
+ }
}
diff --git a/src/main/java/org/alfresco/rest/api/model/SiteMembershipApproval.java b/src/main/java/org/alfresco/rest/api/model/SiteMembershipApproval.java
new file mode 100644
index 0000000000..02d21c2264
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/api/model/SiteMembershipApproval.java
@@ -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 .
+ * #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 + "]";
+ }
+
+}
diff --git a/src/main/java/org/alfresco/rest/api/model/SiteMembershipRejection.java b/src/main/java/org/alfresco/rest/api/model/SiteMembershipRejection.java
new file mode 100644
index 0000000000..447fb6afcd
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/api/model/SiteMembershipRejection.java
@@ -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 .
+ * #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 + "]";
+ }
+
+}
diff --git a/src/main/java/org/alfresco/rest/api/model/SiteMembershipRequest.java b/src/main/java/org/alfresco/rest/api/model/SiteMembershipRequest.java
index 0336c00ce1..e946016e0d 100644
--- a/src/main/java/org/alfresco/rest/api/model/SiteMembershipRequest.java
+++ b/src/main/java/org/alfresco/rest/api/model/SiteMembershipRequest.java
@@ -52,6 +52,7 @@ public class SiteMembershipRequest implements Comparable
private Date createdAt;
private Date modifiedAt;
private String title; // for sorting only
+ private Person person;
public static Pair splitId(String id)
{
@@ -126,6 +127,16 @@ public class SiteMembershipRequest implements Comparable
this.message = message;
}
+ public Person getPerson()
+ {
+ return person;
+ }
+
+ public void setPerson(Person person)
+ {
+ this.person = person;
+ }
+
@Override
public String toString()
{
diff --git a/src/main/java/org/alfresco/rest/api/sites/SiteMembershipRequestsRelation.java b/src/main/java/org/alfresco/rest/api/sites/SiteMembershipRequestsRelation.java
new file mode 100644
index 0000000000..93edb64721
--- /dev/null
+++ b/src/main/java/org/alfresco/rest/api/sites/SiteMembershipRequestsRelation.java
@@ -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 .
+ * #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);
+ }
+}
diff --git a/src/main/resources/alfresco/public-rest-context.xml b/src/main/resources/alfresco/public-rest-context.xml
index 0d9d0f0721..9e1b651133 100644
--- a/src/main/resources/alfresco/public-rest-context.xml
+++ b/src/main/resources/alfresco/public-rest-context.xml
@@ -872,6 +872,14 @@
+
+
+
+
+
+
+
+
diff --git a/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/SiteMembershipRequestEntityResource.java b/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/SiteMembershipRequestEntityResource.java
new file mode 100644
index 0000000000..0d8aeb754b
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/SiteMembershipRequestEntityResource.java
@@ -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 .
+ * #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, 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 readAll(Parameters parameters)
+ {
+ return siteMembershipRequests.getPagedSiteMembershipRequests(parameters);
+ }
+}
diff --git a/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/package-info.java b/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/package-info.java
new file mode 100644
index 0000000000..6fb4308dec
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/api/sitesmembershipsrequests/package-info.java
@@ -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 .
+ * #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;
\ No newline at end of file
diff --git a/src/test/java/org/alfresco/rest/api/tests/TestSiteMembershipRequests.java b/src/test/java/org/alfresco/rest/api/tests/TestSiteMembershipRequests.java
index 3b53f8f60f..135836ed66 100644
--- a/src/test/java/org/alfresco/rest/api/tests/TestSiteMembershipRequests.java
+++ b/src/test/java/org/alfresco/rest/api/tests/TestSiteMembershipRequests.java
@@ -33,8 +33,10 @@ import static org.junit.Assert.fail;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Random;
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.TestPerson;
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.Paging;
import org.alfresco.rest.api.tests.client.PublicApiClient.SiteMembershipRequests;
import org.alfresco.rest.api.tests.client.PublicApiException;
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.SiteRole;
+import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.invitation.Invitation;
import org.alfresco.service.cmr.invitation.ModeratedInvitation;
import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
import org.apache.commons.httpclient.HttpStatus;
import org.junit.Before;
import org.junit.Test;
+import javax.servlet.http.HttpServletResponse;
+
@SuppressWarnings("unused")
public class TestSiteMembershipRequests extends EnterpriseTestApi
{
+ private static final String URL_SITES = "sites";
+
private TestNetwork network1;
private TestNetwork network2;
@@ -1462,4 +1474,447 @@ public class TestSiteMembershipRequests extends EnterpriseTestApi
siteMembershipRequest.setMessage("Please can I join your site?");
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()
+ {
+ @Override
+ public TestSite doWork() throws Exception
+ {
+ TestSite site = systemNetwork.createSite(SiteVisibility.PUBLIC);
+ return site;
+ }
+ }, siteManager.getId(), networkId);
+
+ TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork()
+ {
+ @Override
+ public TestSite doWork() throws Exception
+ {
+ TestSite site = systemNetwork.createSite(SiteVisibility.MODERATED);
+ return site;
+ }
+ }, siteManager.getId(), networkId);
+
+ TestSite site2 = TenantUtil.runAsUserTenant(new TenantRunAsWork()
+ {
+ @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 resp = getSiteMembershipRequests(paging, null);
+ List 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 resp = getSiteMembershipRequests(paging, null);
+ List 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 resp = getSiteMembershipRequests(paging, null);
+ List list = resp.getList();
+
+ assertEquals(3, list.size());
+
+ // Test filter by site id.
+
+ Map 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 resp = getSiteMembershipRequests(paging, null);
+ List 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() {
+ @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() {
+ @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()
+ {
+ @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() {
+ @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() {
+ @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() {
+ @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()
+ {
+ @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 otherParams = new HashMap<>();
+ otherParams.put("where", "(siteId='" + site.getSiteId() + "')");
+
+ ListResponse resp = getSiteMembershipRequests(paging, otherParams);
+ List list = resp.getList();
+
+ assertEquals(0, list.size());
+ }
+
+ // Reject again.
+ reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
+ }
+
+ private ListResponse getSiteMembershipRequests(final Paging paging, Map 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 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 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);
+ }
+ }
}
diff --git a/src/test/java/org/alfresco/rest/api/tests/client/PublicApiClient.java b/src/test/java/org/alfresco/rest/api/tests/client/PublicApiClient.java
index 7b607cc642..ce4fe2d593 100644
--- a/src/test/java/org/alfresco/rest/api/tests/client/PublicApiClient.java
+++ b/src/test/java/org/alfresco/rest/api/tests/client/PublicApiClient.java
@@ -43,20 +43,19 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
import org.alfresco.opencmis.CMISDispatcherRegistry.Binding;
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.tests.TestPeople;
import org.alfresco.rest.api.tests.TestSites;
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.data.Action;
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.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.Comment;
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.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
/**
* 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
{
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 getSiteMembershipRequests(String personId, Map params) throws PublicApiException, ParseException
{
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
{
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;
}
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");
- SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest(personId, (JSONObject)response.getJsonResponse().get("entry"));
+ SiteMembershipRequest ret = SiteMembershipRequest.parseSiteMembershipRequest((JSONObject) response.getJsonResponse().get("entry"));
return ret;
}
@@ -1165,6 +1166,21 @@ public class PublicApiClient
{
remove("people", personId, "site-membership-requests", siteMembershipRequestId, "Failed to cancel siteMembershipRequest");
}
+
+ public ListResponse getSiteMembershipRequests(Map 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
diff --git a/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipApproval.java b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipApproval.java
new file mode 100644
index 0000000000..84f75c7d3c
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipApproval.java
@@ -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 .
+ * #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;
+ }
+}
diff --git a/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRejection.java b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRejection.java
new file mode 100644
index 0000000000..4147e9f331
--- /dev/null
+++ b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRejection.java
@@ -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 .
+ * #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;
+ }
+}
diff --git a/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRequest.java b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRequest.java
index e35ec9894a..e4033a55b2 100644
--- a/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRequest.java
+++ b/src/test/java/org/alfresco/rest/api/tests/client/data/SiteMembershipRequest.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Remote API
- * %%
- * Copyright (C) 2005 - 2016 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 .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Remote API
+ * %%
+ * Copyright (C) 2005 - 2016 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 .
+ * #L%
+ */
package org.alfresco.rest.api.tests.client.data;
import static org.junit.Assert.assertFalse;
@@ -51,6 +51,7 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable parseSiteMembershipRequests(String username, JSONObject jsonObject) throws ParseException
+ public static ListResponse parseSiteMembershipRequests(JSONObject jsonObject) throws ParseException
{
List siteMembershipRequests = new ArrayList();
@@ -164,11 +179,11 @@ public class SiteMembershipRequest implements ExpectedComparison, Comparable(paging, siteMembershipRequests);
+ return new ListResponse<>(paging, siteMembershipRequests);
}
@Override