use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class RepositoryEntriesTest method getParticipants.
@Test
public void getParticipants() throws IOException, URISyntaxException {
Identity participant1 = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-1-" + UUID.randomUUID().toString());
Identity participant2 = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-2-" + UUID.randomUUID().toString());
Roles part1Roles = securityManager.getRoles(participant1);
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addParticipants(participant1, part1Roles, new IdentitiesAddEvent(participant1), re, null);
repositoryManager.addParticipants(participant1, part1Roles, new IdentitiesAddEvent(participant2), re, null);
dbInstance.commitAndCloseSession();
// get the coaches
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("participants").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<UserVO> users = parseUserArray(response.getEntity());
Assert.assertNotNull(users);
// our 2
Assert.assertEquals(2, users.size());
int found = 0;
for (UserVO user : users) {
String login = user.getLogin();
Assert.assertNotNull(login);
if (participant1.getName().equals(login) || participant2.getName().equals(login)) {
found++;
}
}
Assert.assertEquals(2, found);
conn.shutdown();
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class RepositoryEntriesTest method removeOwner.
@Test
public void removeOwner() throws IOException, URISyntaxException {
Identity owner = JunitTestHelper.createAndPersistIdentityAsAuthor("author-4-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addOwners(owner, new IdentitiesAddEvent(owner), re, new MailPackage(false));
dbInstance.commitAndCloseSession();
// remove the owner
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("owners").path(owner.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
// check
List<Identity> owners = repositoryService.getMembers(re, GroupRoles.owner.name());
Assert.assertNotNull(owners);
Assert.assertEquals(0, owners.size());
Assert.assertFalse(owners.contains(owner));
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class RepositoryEntriesTest method removeCoach.
@Test
public void removeCoach() throws IOException, URISyntaxException {
Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-4-" + UUID.randomUUID());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addTutors(coach, ADMIN_ROLES, new IdentitiesAddEvent(coach), re, new MailPackage(false));
dbInstance.commitAndCloseSession();
// remove the owner
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("coaches").path(coach.getKey().toString()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.shutdown();
// check
List<Identity> coaches = repositoryService.getMembers(re, GroupRoles.coach.name());
Assert.assertNotNull(coaches);
Assert.assertTrue(coaches.isEmpty());
Assert.assertFalse(coaches.contains(coach));
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class RepositoryEntriesTest method getCoaches.
@Test
public void getCoaches() throws IOException, URISyntaxException {
Identity coach1 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-1-" + UUID.randomUUID().toString());
Identity coach2 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-2-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach1), re, new MailPackage(false));
repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach2), re, new MailPackage(false));
dbInstance.commitAndCloseSession();
// get the coaches
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("coaches").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<UserVO> users = parseUserArray(response.getEntity());
Assert.assertNotNull(users);
// our 2
Assert.assertEquals(2, users.size());
int found = 0;
for (UserVO user : users) {
String login = user.getLogin();
Assert.assertNotNull(login);
if (coach1.getName().equals(login) || coach2.getName().equals(login)) {
found++;
}
}
Assert.assertEquals(2, found);
conn.shutdown();
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class RepositoryManager method updateRepositoryEntryMembership.
private void updateRepositoryEntryMembership(Identity ureqIdentity, Roles ureqRoles, RepositoryEntry re, RepositoryEntryPermissionChangeEvent changes, MailPackage mailing, List<RepositoryEntryMembershipModifiedEvent> deferredEvents) {
if (changes.getRepoOwner() != null) {
if (changes.getRepoOwner().booleanValue()) {
addOwners(ureqIdentity, new IdentitiesAddEvent(changes.getMember()), re, mailing);
} else {
removeOwner(ureqIdentity, changes.getMember(), re, mailing);
deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
}
}
if (changes.getRepoTutor() != null) {
if (changes.getRepoTutor().booleanValue()) {
addTutors(ureqIdentity, ureqRoles, new IdentitiesAddEvent(changes.getMember()), re, mailing);
} else {
removeTutor(ureqIdentity, changes.getMember(), re, mailing);
deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
}
}
if (changes.getRepoParticipant() != null) {
if (changes.getRepoParticipant().booleanValue()) {
addParticipants(ureqIdentity, ureqRoles, new IdentitiesAddEvent(changes.getMember()), re, mailing);
} else {
removeParticipant(ureqIdentity, changes.getMember(), re, mailing, true);
deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
}
}
}
Aggregations