Search in sources :

Example 1 with SiteMembershipApproval

use of org.alfresco.rest.api.tests.client.data.SiteMembershipApproval in project alfresco-remote-api by Alfresco.

the class TestSiteMembershipRequests method testGetSiteMembershipRequests.

@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());
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) SiteMembershipApproval(org.alfresco.rest.api.tests.client.data.SiteMembershipApproval) HashMap(java.util.HashMap) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ParseException(java.text.ParseException) 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) Test(org.junit.Test)

Example 2 with SiteMembershipApproval

use of org.alfresco.rest.api.tests.client.data.SiteMembershipApproval 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)

Example 3 with SiteMembershipApproval

use of org.alfresco.rest.api.tests.client.data.SiteMembershipApproval in project alfresco-remote-api by Alfresco.

the class TestSiteMembershipRequests method testApproveSiteMembershipRequests.

@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 another user request without having permissions.
    {
        publicApiClient.setRequestContext(new RequestContext(networkId, person2.getId()));
        approve(site.getSiteId(), person1.getId(), new SiteMembershipApproval(), HttpServletResponse.SC_NOT_FOUND, null);
    }
    // User from same site tries to approve 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());
        approve(site.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_FORBIDDEN, null);
        // null body (see REPO-3344 for details)
        approve(site.getSiteId(), person1.getId(), null, HttpServletResponse.SC_FORBIDDEN, 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());
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) SiteMembershipApproval(org.alfresco.rest.api.tests.client.data.SiteMembershipApproval) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) 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) 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) Test(org.junit.Test)

Aggregations

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