use of org.alfresco.rest.api.tests.RepoService.TestPerson in project alfresco-remote-api by Alfresco.
the class TestNodeRatings method testNodeRatings.
@Test
public void testNodeRatings() throws Exception {
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
final TestNetwork network1 = networksIt.next();
assertTrue(networksIt.hasNext());
final TestNetwork network2 = networksIt.next();
final List<TestPerson> people = new ArrayList<TestPerson>(3);
// create users
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network1.createUser();
people.add(person);
person = network1.createUser();
people.add(person);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestPerson person = network2.createUser();
people.add(person);
return null;
}
}, network2.getId());
final TestPerson person11 = people.get(0);
final TestPerson person12 = people.get(1);
final TestPerson person21 = people.get(2);
PublicApiClient.Sites sitesProxy = publicApiClient.sites();
Comments commentsProxy = publicApiClient.comments();
People peopleProxy = publicApiClient.people();
Nodes nodesProxy = publicApiClient.nodes();
DateFormat format = PublicApiDateFormat.getDateFormat();
// Create site and document
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
String siteId = "TESTSITE" + GUID.generate();
Site site = new SiteImpl(siteId, siteId, siteId, SiteVisibility.PRIVATE.toString());
site = sitesProxy.createSite(site);
SiteContainer sc = sitesProxy.getSingleSiteContainer(site.getSiteId(), "documentLibrary");
final String node1Id = createTextFile(sc.getId(), "Test Doc 1.txt", "Test Content").getId();
// TEMP - pending remote api to list node ratings
NodeRef nodeRef1 = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, node1Id);
// try to add a rating to a comment
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Comment comment = new Comment("Test Comment", "Test Comment");
Comment newComment = commentsProxy.createNodeComment(node1Id, comment);
NodeRating rating = new NodeRating("likes", true);
nodesProxy.createNodeRating(newComment.getId(), rating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// invalid node id
try {
NodeRating rating = new NodeRating("likes", true);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.createNodeRating(GUID.generate(), rating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// try to add a rating to a tag
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Tag tag = new Tag("testTag");
Tag newTag = nodesProxy.createNodeTag(node1Id, tag);
NodeRating rating = new NodeRating("likes", true);
nodesProxy.createNodeRating(newTag.getId(), rating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// invalid rating scheme
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.createNodeRating(node1Id, new NodeRating("missingRatingScheme", Double.valueOf(1.0f)));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// invalid rating
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.createNodeRating(node1Id, new NodeRating("likes", Double.valueOf(2.0f)));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// invalid rating
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", true));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// invalid rating - can't rate own content for fiveStar
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.createNodeRating(node1Id, new NodeRating("fiveStar", 5));
fail("");
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
}
// valid ratings
{
NodeRating rating = new NodeRating("likes", true);
Date time = new Date();
// rate by multiple users in more than 1 network
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
NodeRating ret = nodesProxy.createNodeRating(node1Id, rating);
assertEquals(rating.getMyRating(), ret.getMyRating());
assertTrue(format.parse(ret.getRatedAt()).after(time));
assertEquals(rating.getId(), ret.getId());
assertEquals(new NodeRating.Aggregate(1, null), ret.getAggregate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
ret = nodesProxy.createNodeRating(node1Id, rating);
assertEquals(rating.getMyRating(), ret.getMyRating());
assertTrue(format.parse(ret.getRatedAt()).after(time));
assertEquals(rating.getId(), ret.getId());
assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
ret = nodesProxy.createNodeRating(node1Id, rating);
assertEquals(rating.getMyRating(), ret.getMyRating());
assertTrue(format.parse(ret.getRatedAt()).after(time));
assertEquals(rating.getId(), ret.getId());
assertEquals(new NodeRating.Aggregate(2, null), ret.getAggregate());
// different network - unauthorized
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
nodesProxy.createNodeRating(node1Id, rating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
// Test Case cloud-2209
// Test Case cloud-2220
// Test Case cloud-1520
// check that the node ratings are there, test paging
{
// person11
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
List<NodeRating> expectedRatings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
{
int skipCount = 0;
int maxItems = 1;
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 1;
int maxItems = Integer.MAX_VALUE;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 1;
int maxItems = expectedRatings.size();
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
// person12
List<NodeRating> expectedRatings = repoService.getNodeRatings(person12.getId(), network1.getId(), nodeRef1);
{
int skipCount = 0;
int maxItems = 1;
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
int skipCount = 1;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(expectedRatings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
{
// person21
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
List<NodeRating> expectedRatings = Collections.emptyList();
try {
int skipCount = 0;
int maxItems = 1;
Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size());
nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
}
// invalid node id
try {
int skipCount = 1;
int maxItems = Integer.MAX_VALUE;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(skipCount, maxItems);
nodesProxy.getNodeRatings(GUID.generate(), createParams(paging, null));
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
}
// check activities have been raised for the created ratings
repoService.generateFeed();
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(0, Integer.MAX_VALUE);
ListResponse<Activity> activities = peopleProxy.getActivities(person11.getId(), createParams(paging, null));
boolean found = false;
for (Activity activity : activities.getList()) {
String activityType = activity.getActivityType();
if (activityType.equals(ActivityType.FILE_LIKED)) {
Map<String, Object> summary = activity.getSummary();
assertNotNull(summary);
String objectId = (String) summary.get("objectId");
assertNotNull(objectId);
if (node1Id.equals(objectId)) {
found = true;
break;
}
}
}
assertTrue(found);
}
}
{
// remove node rating
NodeRating rating = new NodeRating("likes", null);
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21.getId()));
nodesProxy.removeNodeRating(node1Id, rating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
nodesProxy.removeNodeRating(node1Id, rating);
}
// check list
{
List<NodeRating> ratings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1);
int skipCount = 0;
int maxItems = Integer.MAX_VALUE;
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
Paging paging = getPaging(skipCount, maxItems, ratings.size(), ratings.size());
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(paging, null));
checkList(ratings.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
// get a node rating
// 1977
{
NodeRating rating = new NodeRating("likes", true);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
NodeRating expected = nodesProxy.createNodeRating(node1Id, rating);
NodeRating actual = nodesProxy.getNodeRating(node1Id, "likes");
expected.expected(actual);
}
{
// update node rating
NodeRating rating = new NodeRating("fiveStar", 2);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person12.getId()));
// create initial rating
NodeRating createdRating = nodesProxy.createNodeRating(node1Id, rating);
NodeRating updateRating = new NodeRating(createdRating.getId(), 5);
// update - not supported
try {
nodesProxy.updateNodeRating(node1Id, updateRating);
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
// Test Case cloud-1977
// invalid methods
{
try {
// -ve test - cannot create multiple ratings in single POST call (unsupported)
List<NodeRating> ratings = new ArrayList<>(2);
ratings.add(new NodeRating("likes", true));
ratings.add(new NodeRating("likes", false));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.create("nodes", node1Id, "ratings", null, JSONArray.toJSONString(ratings), "Unable to POST to multiple ratings");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// get an arbitrary rating
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(node1Id, createParams(getPaging(0, Integer.MAX_VALUE), null));
List<NodeRating> nodeRatings = resp.getList();
assertTrue(nodeRatings.size() > 0);
try {
NodeRating rating = new NodeRating("likes", true);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.create("nodes", node1Id, "ratings", "likes", rating.toJSON().toString(), "Unable to POST to a node rating");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.update("nodes", node1Id, "ratings", null, null, "Unable to PUT node ratings");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.remove("nodes", node1Id, "ratings", null, "Unable to DELETE node ratings");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
try {
NodeRating rating = nodeRatings.get(0);
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.update("nodes", node1Id, "ratings", rating.getId(), null, "Unable to PUT a node rating");
fail();
} catch (PublicApiException e) {
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
}
// Test case ACE-5453
{
try {
testSkipCountLargeValue(person11, network1, nodeRef1, nodesProxy);
} catch (PublicApiException e) {
fail();
}
}
}
use of org.alfresco.rest.api.tests.RepoService.TestPerson 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.TestPerson 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.TestPerson 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.TestPerson 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