use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class CourseTest method getAuthors.
@Test
public void getAuthors() 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<Identity>();
authors.add(auth1);
authors.add(auth2);
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
dbInstance.intermediateCommit();
// get them
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
assertNotNull(body);
List<UserVO> authorVOs = parseUserArray(body);
assertNotNull(authorVOs);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class CourseTest method addAuthor.
@Test
public void addAuthor() throws IOException, URISyntaxException {
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth0.getKey()).build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
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 isAuthor = securityManager.isIdentityInSecurityGroup(auth0, authorGroup);
dbInstance.intermediateCommit();
Assert.assertTrue(isAuthor);
// is auth0 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
boolean isOwner = repositoryService.hasRole(auth0, repositoryEntry, GroupRoles.owner.name());
dbInstance.intermediateCommit();
Assert.assertTrue(isOwner);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class RepositoryManagerTest method isInstitutionalRessourceManagerFor.
/**
* How can be a resource manager if Constants.ORESOURCE_USERMANAGER is never used?
*/
@Test
public void isInstitutionalRessourceManagerFor() {
Identity owner1 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
Identity owner2 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
Identity part3 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
repositoryEntryRelationDao.addRole(owner1, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(owner2, re, GroupRoles.owner.name());
repositoryEntryRelationDao.addRole(part3, re, GroupRoles.participant.name());
dbInstance.commit();
// set the institutions
owner1.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
owner2.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
part3.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
userManager.updateUserFromIdentity(owner1);
userManager.updateUserFromIdentity(owner2);
userManager.updateUserFromIdentity(part3);
dbInstance.commit();
// promote owner1 to institution resource manager
SecurityGroup institutionalResourceManagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
securityManager.addIdentityToSecurityGroup(owner1, institutionalResourceManagerGroup);
dbInstance.commitAndCloseSession();
// check
Roles rolesOwner1 = securityManager.getRoles(owner1);
Roles rolesOwner2 = securityManager.getRoles(owner2);
Roles rolesPart3 = securityManager.getRoles(part3);
boolean institutionMgr1 = repositoryManager.isInstitutionalRessourceManagerFor(owner1, rolesOwner1, re);
boolean institutionMgr2 = repositoryManager.isInstitutionalRessourceManagerFor(owner2, rolesOwner2, re);
boolean institutionMgr3 = repositoryManager.isInstitutionalRessourceManagerFor(part3, rolesPart3, re);
Assert.assertTrue(institutionMgr1);
Assert.assertFalse(institutionMgr2);
Assert.assertFalse(institutionMgr3);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class InvitationEditRightsController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_pf_invitation_form");
FormLayoutContainer inviteeCont = FormLayoutContainer.createDefaultFormLayout("inviteeInfos", getTranslator());
inviteeCont.setRootForm(mainForm);
formLayout.add("inviteeInfos", inviteeCont);
firstNameEl = uifactory.addTextElement("firstName", "firstName", 64, invitation.getFirstName(), inviteeCont);
firstNameEl.setElementCssClass("o_sel_pf_invitation_firstname");
firstNameEl.setMandatory(true);
lastNameEl = uifactory.addTextElement("lastName", "lastName", 64, invitation.getLastName(), inviteeCont);
lastNameEl.setElementCssClass("o_sel_pf_invitation_lastname");
lastNameEl.setMandatory(true);
String invitationEmail = email != null ? email : invitation.getMail();
mailEl = uifactory.addTextElement("mail", "mail", 128, invitationEmail, inviteeCont);
mailEl.setElementCssClass("o_sel_pf_invitation_mail");
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
mailEl.setEnabled(invitation.getKey() == null);
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() });
}
}
String link = getInvitationLink();
StaticTextElement linkEl = uifactory.addStaticTextElement("invitation.link", link, inviteeCont);
linkEl.setElementCssClass("o_sel_pf_invitation_url");
linkEl.setLabel("invitation.link", null);
if (mailTemplate != null) {
subjectEl = uifactory.addTextElement("subjectElem", "mail.subject", 128, mailTemplate.getSubjectTemplate(), inviteeCont);
subjectEl.setDisplaySize(60);
subjectEl.setMandatory(true);
bodyEl = uifactory.addTextAreaElement("bodyElem", "mail.body", -1, 15, 60, true, mailTemplate.getBodyTemplate(), inviteeCont);
bodyEl.setHelpUrlForManualPage("E-Mail");
bodyEl.setMandatory(true);
}
// binder
MultipleSelectionElement accessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
accessEl.addActionListener(FormEvent.ONCHANGE);
binderRow = new BinderAccessRightsRow(accessEl, binder);
// sections
List<Section> sections = portfolioService.getSections(binder);
Map<Long, SectionAccessRightsRow> sectionMap = new HashMap<>();
for (Section section : sections) {
MultipleSelectionElement sectionAccessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
sectionAccessEl.addActionListener(FormEvent.ONCHANGE);
SectionAccessRightsRow sectionRow = new SectionAccessRightsRow(sectionAccessEl, section, binderRow);
binderRow.getSections().add(sectionRow);
sectionMap.put(section.getKey(), sectionRow);
}
// pages
List<Page> pages = portfolioService.getPages(binder, null);
for (Page page : pages) {
Section section = page.getSection();
SectionAccessRightsRow sectionRow = sectionMap.get(section.getKey());
MultipleSelectionElement pageAccessEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues);
pageAccessEl.addActionListener(FormEvent.ONCHANGE);
PortfolioElementAccessRightsRow pageRow = new PortfolioElementAccessRightsRow(pageAccessEl, page, sectionRow);
sectionRow.getPages().add(pageRow);
}
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("binderRow", binderRow);
}
selectAll = uifactory.addFormLink("form.checkall", "form.checkall", null, formLayout, Link.LINK);
selectAll.setIconLeftCSS("o_icon o_icon-sm o_icon_check_on");
deselectAll = uifactory.addFormLink("form.uncheckall", "form.uncheckall", null, formLayout, Link.LINK);
deselectAll.setIconLeftCSS("o_icon o_icon-sm o_icon_check_off");
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
buttonsCont.setRootForm(mainForm);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
if (invitation.getKey() != null) {
removeLink = uifactory.addFormLink("remove", buttonsCont, Link.BUTTON);
}
uifactory.addFormSubmitButton("save", buttonsCont);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class CourseWebService method getAuthor.
/**
* Get this specific author and owner of the course
* @response.representation.200.qname {http://www.example.com}userVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The author
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found or the user is not an onwer or author of the course
* @param identityKey The user identifier
* @param httpRequest The HTTP request
* @return It returns an <code>UserVO</code>
*/
@GET
@Path("authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
BaseSecurity securityManager = BaseSecurityManager.getInstance();
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
Identity author = securityManager.loadIdentityByKey(identityKey, false);
if (repositoryService.hasRole(author, repositoryEntry, GroupRoles.owner.name()) && securityManager.isIdentityInSecurityGroup(author, authorGroup)) {
UserVO vo = UserVOFactory.get(author);
return Response.ok(vo).build();
}
return Response.ok(author).build();
}
Aggregations