Search in sources :

Example 1 with SiteMembershipRejection

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);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) SiteMembershipApproval(org.alfresco.rest.api.tests.client.data.SiteMembershipApproval) ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) MemberOfSite(org.alfresco.rest.api.tests.client.data.MemberOfSite) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ParseException(java.text.ParseException) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) ArrayList(java.util.ArrayList) List(java.util.List) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) SiteMembershipRequest(org.alfresco.rest.api.tests.client.data.SiteMembershipRequest) HashMap(java.util.HashMap) Map(java.util.Map) SiteMembershipRejection(org.alfresco.rest.api.tests.client.data.SiteMembershipRejection) Test(org.junit.Test)

Aggregations

ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)1 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)1 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)1 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)1 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)1 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)1 MemberOfSite (org.alfresco.rest.api.tests.client.data.MemberOfSite)1 SiteMembershipApproval (org.alfresco.rest.api.tests.client.data.SiteMembershipApproval)1 SiteMembershipRejection (org.alfresco.rest.api.tests.client.data.SiteMembershipRejection)1 SiteMembershipRequest (org.alfresco.rest.api.tests.client.data.SiteMembershipRequest)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 Test (org.junit.Test)1