use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.
the class CourseTest method addAuthors.
@Test
public void addAuthors() throws IOException, URISyntaxException {
Assert.assertTrue(conn.login("administrator", "openolat"));
ICourse course = CoursesWebService.createEmptyCourse(admin, "course1", "course1 long name", null);
Identity author1 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-1");
Identity author2 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-2");
dbInstance.commitAndCloseSession();
UserVO[] newAuthors = new UserVO[2];
newAuthors[0] = UserVOFactory.get(author1);
newAuthors[1] = UserVOFactory.get(author2);
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("authors").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, newAuthors);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// is auth0 author
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
boolean isAuthor1 = securityManager.isIdentityInSecurityGroup(author1, authorGroup);
boolean isAuthor2 = securityManager.isIdentityInSecurityGroup(author2, authorGroup);
dbInstance.commit();
Assert.assertTrue(isAuthor1);
Assert.assertTrue(isAuthor2);
// is auth0 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course, true);
boolean isOwner1 = repositoryService.hasRole(author1, repositoryEntry, GroupRoles.owner.name());
boolean isOwner2 = repositoryService.hasRole(author2, repositoryEntry, GroupRoles.owner.name());
dbInstance.commit();
Assert.assertTrue(isOwner1);
Assert.assertTrue(isOwner2);
}
use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.
the class ImportAuthorOverviewIdentitiesController method loadModel.
private List<Identity> loadModel(String inp) {
// securityManager.getIdentitiesOfSecurityGroup(securityGroup);
List<Identity> existIdents = Collections.emptyList();
List<Identity> okIdentities = new ArrayList<Identity>();
List<String> isanonymous = new ArrayList<String>();
List<String> notfounds = new ArrayList<String>();
List<String> alreadyin = new ArrayList<String>();
SecurityGroup anonymousSecGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
String[] lines = inp.split("\r?\n");
for (int i = 0; i < lines.length; i++) {
String username = lines[i].trim();
if (!username.equals("")) {
// skip empty lines
Identity ident = securityManager.findIdentityByName(username);
if (ident == null) {
// not found, add to not-found-list
notfounds.add(username);
} else if (securityManager.isIdentityInSecurityGroup(ident, anonymousSecGroup)) {
isanonymous.add(username);
} else {
// check if already in group
boolean inGroup = PersistenceHelper.containsPersistable(existIdents, ident);
if (inGroup) {
// added to warning: already in group
alreadyin.add(ident.getName());
} else {
// ok to add -> preview (but filter duplicate entries)
if (!PersistenceHelper.containsPersistable(okIdentities, ident)) {
okIdentities.add(ident);
}
}
}
}
}
return okIdentities;
}
use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.
the class QuestionItemDAO method addAuthors.
public void addAuthors(List<Identity> authors, QuestionItemShort item) {
QuestionItemImpl lockedItem = loadForUpdate(item);
SecurityGroup secGroup = lockedItem.getOwnerGroup();
for (Identity author : authors) {
if (!securityManager.isIdentityInSecurityGroup(author, secGroup)) {
securityManager.addIdentityToSecurityGroup(author, secGroup);
}
}
dbInstance.commit();
}
use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.
the class QuestionPoolServiceImpl method deleteItems.
@Override
public void deleteItems(List<? extends QuestionItemShort> items) {
if (items == null || items.isEmpty()) {
// nothing to do
return;
}
List<SecurityGroup> secGroups = new ArrayList<>();
for (QuestionItemShort item : items) {
markManager.deleteMarks(item);
commentAndRatingService.deleteAllIgnoringSubPath(item);
licenseService.delete(item);
QuestionItem loadedItem = loadItemById(item.getKey());
if (loadedItem instanceof QuestionItemImpl) {
QuestionItemImpl itemImpl = (QuestionItemImpl) loadedItem;
qpoolFileStorage.deleteDir(itemImpl.getDirectory());
secGroups.add(itemImpl.getOwnerGroup());
}
dbInstance.intermediateCommit();
}
poolDao.removeFromPools(items);
questionItemDao.removeFromShares(items);
collectionDao.deleteItemFromCollections(items);
questionItemDao.delete(items);
// Delete SecurityGroup after the item to avoid foreign key constraint violation.
for (SecurityGroup secGroup : secGroups) {
securityManager.deleteSecurityGroup(secGroup);
}
for (QuestionItemShort item : items) {
lifeIndexer.deleteDocument(QItemDocument.TYPE, item.getKey());
}
// allow reload of data
dbInstance.getCurrentEntityManager().flush();
}
use of org.olat.basesecurity.SecurityGroup in project openolat by klemens.
the class EPShareListController method createContainerForInvitation.
private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
invitationContainer.contextPut("wrapper", policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("map.share.with." + cmpName, invitationContainer);
TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link = getInvitationLink(invitation, map);
StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
linkEl.setLabel("map.share.with.link", null);
}
Aggregations