use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class CatalogNodeManagerController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (addEntryCtrl == source) {
if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
loadNodesChildren();
}
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (editEntryCtrl == source) {
if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
catalogEntry = editEntryCtrl.getEditedCatalogEntry();
loadEntryInfos();
}
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.CHANGED_EVENT);
} else if (categoryMoveCtrl == source) {
cmc.deactivate();
CatalogEntry moveMe = null;
if (event.equals(Event.DONE_EVENT)) {
showInfo("tools.move.catalog.entry.success", catalogEntry.getName());
moveMe = categoryMoveCtrl.getMoveMe();
} else if (event.equals(Event.FAILED_EVENT)) {
showError("tools.move.catalog.entry.failed");
loadNodesChildren();
}
cleanUp();
// in any case, remove the lock
if (catModificationLock != null && catModificationLock.isSuccess()) {
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(catModificationLock);
catModificationLock = null;
}
// only after jump to the moved entry
if (moveMe != null) {
launchCatalogEntry(ureq, moveMe);
}
} else if (dialogDeleteSubtree == source) {
// from remove subtree dialog -> yes or no
if (DialogBoxUIFactory.isYesEvent(event)) {
catalogManager.deleteCatalogEntry(catalogEntry);
fireEvent(ureq, Event.BACK_EVENT);
}
// in any case, remove the lock
if (catModificationLock != null && catModificationLock.isSuccess()) {
CoordinatorManager.getInstance().getCoordinator().getLocker().releaseLock(catModificationLock);
catModificationLock = null;
}
} else if (childNodeCtrl == source) {
if (event == Event.BACK_EVENT) {
toolbarPanel.popUpToController(this);
removeAsListenerAndDispose(childNodeCtrl);
childNodeCtrl = null;
loadNodesChildren();
}
} else if (entrySearchCtrl == source) {
if (event.getCommand().equals(RepositoryTableModel.TABLE_ACTION_SELECT_LINK)) {
// successfully selected a repository entry which will be a link within
// the current Category
RepositoryEntry selectedEntry = entrySearchCtrl.getSelectedEntry();
doAddResource(ureq, selectedEntry);
fireEvent(ureq, Event.CHANGED_EVENT);
}
cmc.deactivate();
cleanUp();
} else if (groupCtrl == source) {
if (event instanceof IdentitiesAddEvent || event instanceof IdentitiesRemoveEvent) {
doAddRemoveOwners(event);
}
} else if (contactCtrl == source) {
cmc.deactivate();
cleanUp();
} else if (dialogDeleteLink == source) {
if (DialogBoxUIFactory.isYesEvent(event)) {
CatalogEntryRow row = (CatalogEntryRow) dialogDeleteLink.getUserObject();
catalogManager.deleteCatalogEntry(row, catalogEntry);
loadResources(ureq);
}
} else if (entryResourceMoveCtrl == source) {
if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
CatalogEntry moveMe = entryResourceMoveCtrl.getMoveMe();
showInfo("tools.move.catalog.entry.success", moveMe.getName());
loadResources(ureq);
}
cmc.deactivate();
cleanUp();
} else if (cmc == source) {
cleanUp();
}
super.event(ureq, source, event);
}
use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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));
}
Aggregations