use of org.alfresco.rest.api.tests.client.data.SiteMembershipRejection in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method testRejectSiteMembershipRequests.
@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_FORBIDDEN, null);
// null body (see REPO-3344 for details)
reject(site.getSiteId(), person1.getId(), null, HttpServletResponse.SC_FORBIDDEN, null);
}
// User tries to reject another user request without having permissions.
{
publicApiClient.setRequestContext(new RequestContext(networkId, person2.getId()));
reject(site.getSiteId(), person1.getId(), new SiteMembershipRejection(), HttpServletResponse.SC_NOT_FOUND, null);
}
// User from same site tries to reject another user request without having
// permissions.
{
TestPerson person3 = network1.createUser();
// Create site membership request
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()));
MemberOfSite memberOfSite = publicApiClient.sites().getPersonSite(person3.getId(), site.getSiteId());
assertNotNull(memberOfSite);
assertEquals(SiteRole.SiteConsumer, memberOfSite.getRole());
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);
}
Aggregations