use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method testRemoveParticipant.
@Test
public void testRemoveParticipant() throws IOException, URISyntaxException {
Identity participant = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-4-" + UUID.randomUUID().toString());
Roles partRoles = securityManager.getRoles(participant);
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addParticipants(participant, partRoles, new IdentitiesAddEvent(participant), re, null);
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("participants").path(participant.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> participants = repositoryService.getMembers(re, GroupRoles.participant.name());
Assert.assertNotNull(participants);
Assert.assertTrue(participants.isEmpty());
Assert.assertFalse(participants.contains(participant));
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.
the class RepositoryEntriesTest method getOwners.
@Test
public void getOwners() throws IOException, URISyntaxException {
Identity owner1 = JunitTestHelper.createAndPersistIdentityAsAuthor("author-1-" + UUID.randomUUID().toString());
Identity owner2 = JunitTestHelper.createAndPersistIdentityAsAuthor("author-2-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryManager.addOwners(owner1, new IdentitiesAddEvent(owner1), re, null);
repositoryManager.addOwners(owner1, new IdentitiesAddEvent(owner2), re, null);
dbInstance.commitAndCloseSession();
// get the owners
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("owners").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 (owner1.getName().equals(login) || owner2.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 CatalogNodeManagerController method doAddRemoveOwners.
private void doAddRemoveOwners(Event event) {
if (event instanceof IdentitiesAddEvent) {
IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
List<Identity> list = identitiesAddedEvent.getAddIdentities();
for (Identity identity : list) {
if (!securityManager.isIdentityInSecurityGroup(identity, catalogEntry.getOwnerGroup())) {
securityManager.addIdentityToSecurityGroup(identity, catalogEntry.getOwnerGroup());
identitiesAddedEvent.getAddedIdentities().add(identity);
}
}
} else if (event instanceof IdentitiesRemoveEvent) {
IdentitiesRemoveEvent identitiesRemoveEvent = (IdentitiesRemoveEvent) event;
List<Identity> list = identitiesRemoveEvent.getRemovedIdentities();
for (Identity identity : list) {
securityManager.removeIdentityFromSecurityGroup(identity, catalogEntry.getOwnerGroup());
}
}
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class CourseSecurityTest method setUp.
/**
* SetUp is called before each test.
*/
@Before
public void setUp() throws Exception {
super.setUp();
conn = new RestConnection();
try {
// create course and persist as OLATResourceImpl
admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
id1 = JunitTestHelper.createAndPersistIdentityAsUser("id-c-s-0");
Assert.assertNotNull(id1);
auth1 = JunitTestHelper.createAndPersistIdentityAsAuthor("id-c-s-1");
Assert.assertNotNull(auth1);
auth2 = JunitTestHelper.createAndPersistIdentityAsAuthor("id-c-s-2");
Assert.assertNotNull(auth2);
course = CoursesWebService.createEmptyCourse(admin, "course-security-2", "Test course for the security test", null);
DBFactory.getInstance().intermediateCommit();
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntry re = rm.lookupRepositoryEntry(course, false);
IdentitiesAddEvent identitiesAddEvent = new IdentitiesAddEvent(Collections.singletonList(auth2));
rm.addOwners(admin, identitiesAddEvent, re, null);
DBFactory.getInstance().closeSession();
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
}
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project openolat by klemens.
the class CourseTest method removeAuthor.
@Test
public void removeAuthor() throws IOException, URISyntaxException {
// make auth1 and auth2 authors
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
if (!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
}
if (!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
}
dbInstance.intermediateCommit();
// make auth1 and auth2 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
List<Identity> authors = new ArrayList<>();
authors.add(auth1);
authors.add(auth2);
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
dbInstance.intermediateCommit();
// end setup
// test
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth1.getKey()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
URI request2 = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth2.getKey()).build();
HttpDelete method2 = conn.createDelete(request2, MediaType.APPLICATION_JSON);
HttpResponse response2 = conn.execute(method2);
assertEquals(200, response2.getStatusLine().getStatusCode());
EntityUtils.consume(response2.getEntity());
// control
repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
assertFalse(repositoryService.hasRole(auth1, repositoryEntry, GroupRoles.owner.name()));
assertFalse(repositoryService.hasRole(auth2, repositoryEntry, GroupRoles.owner.name()));
dbInstance.intermediateCommit();
}
Aggregations