use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method setup.
@Override
@Before
public void setup() throws Exception {
// init networks
super.setup();
Iterator<TestNetwork> networksIt = getTestFixture().networksIterator();
this.network1 = networksIt.next();
Iterator<String> personIt = network1.getPersonIds().iterator();
this.person11Id = personIt.next();
assertNotNull(person11Id);
this.person12Id = personIt.next();
assertNotNull(person12Id);
this.person13Id = personIt.next();
assertNotNull(person13Id);
this.person14Id = personIt.next();
assertNotNull(person14Id);
this.person15Id = personIt.next();
assertNotNull(person15Id);
this.network2 = networksIt.next();
Iterator<String> person1It = network2.getPersonIds().iterator();
this.person24Id = person1It.next();
assertNotNull(person24Id);
// Create some sites, files and folders
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String guid = GUID.generate();
String[] siteNames = new String[] { "sitex" + guid, "sitea" + guid, "sitef" + guid, "site234" + guid, "sitey" + guid, "siteb" + guid, "site643" + guid, "site24" + guid, "site8d6sc" + guid };
String siteName = siteNames[0];
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
TestSite site = network1.createSite(siteInfo);
person1ModeratedSites.add(site);
for (int i = 1; i < siteNames.length; i++) {
siteName = siteNames[i];
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
site = network1.createSite(siteInfo);
person1ModeratedSites.add(site);
}
String[] mixedCaseSiteNames = new String[] { "MixedCase" + guid, "mixedCaseA" + guid };
for (int i = 0; i < mixedCaseSiteNames.length; i++) {
siteName = mixedCaseSiteNames[i];
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
site = network1.createSite(siteInfo);
person1MixedCaseModeratedSites.add(site);
}
for (int i = 0; i < 1; i++) {
siteName = "privatesite" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PRIVATE);
site = network1.createSite(siteInfo);
person1PrivateSites.add(site);
}
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
person1Folders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
person1Folders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
person1Docs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
person1Folders.add(nodeRef);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
person1PublicSites.add(site);
return null;
}
}, person12Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + System.currentTimeMillis();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
NodeRef nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc1", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder1");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc2", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder2");
personFolders.add(nodeRef);
nodeRef = repoService.createDocument(site.getContainerNodeRef("documentLibrary"), "Test Doc3", "Test Content");
personDocs.add(nodeRef);
nodeRef = repoService.createFolder(site.getContainerNodeRef("documentLibrary"), "Test Folder3");
personFolders.add(nodeRef);
return null;
}
}, person11Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
TestSite site = network1.createSite(siteInfo);
personPublicSites.add(site);
site.inviteToSite(person12Id, SiteRole.SiteCollaborator);
siteName = "site" + GUID.generate();
siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.PUBLIC);
site = network1.createSite(siteInfo);
personPublicSites.add(site);
return null;
}
}, person11Id, network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
String siteName = "site" + GUID.generate();
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, SiteVisibility.MODERATED);
TestSite site = network1.createSite(siteInfo);
person4ModeratedSites.add(site);
return null;
}
}, person24Id, network2.getId());
this.siteMembershipRequestsProxy = publicApiClient.siteMembershipRequests();
}
use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.
the class TestSiteMembershipRequests method testALF19332.
@Test
public void testALF19332() throws Exception {
String networkId = network1.getId();
final TestNetwork systemNetwork = getRepoService().getSystemNetwork();
long time = System.currentTimeMillis();
// note: username for site creator is of the form user@network
PersonInfo personInfo = new PersonInfo("test", "test", "test" + time, "password", null, "test", "test", "test", "test", "test", "test");
TestPerson person = network1.createUser(personInfo);
personInfo = new PersonInfo("test", "test", "test1" + time, "password", null, "test", "test", "test", "test", "test", "test");
TestPerson person1 = network1.createUser(personInfo);
TestSite site = TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>() {
@Override
public TestSite doWork() throws Exception {
TestSite site = systemNetwork.createSite(SiteVisibility.PUBLIC);
return site;
}
}, person.getId(), networkId);
publicApiClient.setRequestContext(new RequestContext("-default-", person1.getId()));
SiteMembershipRequest siteMembershipRequest = new SiteMembershipRequest();
siteMembershipRequest.setId(site.getSiteId());
siteMembershipRequest.setMessage("Please can I join your site?");
SiteMembershipRequest ret = siteMembershipRequestsProxy.createSiteMembershipRequest(person1.getId(), siteMembershipRequest);
}
use of org.alfresco.rest.api.tests.RepoService.TestNetwork 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());
}
}
use of org.alfresco.rest.api.tests.RepoService.TestNetwork 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);
}
use of org.alfresco.rest.api.tests.RepoService.TestNetwork 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());
}
}
Aggregations