Search in sources :

Example 6 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class ProjectGroupController method handleProjectMemberGroupEvent.

private void handleProjectMemberGroupEvent(UserRequest urequest, Event event) {
    if (event instanceof IdentitiesAddEvent) {
        IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
        BusinessGroupAddResponse response = businessGroupService.addParticipants(urequest.getIdentity(), urequest.getUserSession().getRoles(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), null);
        identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities());
        identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission());
        identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup());
        getLogger().info("Add users as project-members");
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesRemoveEvent) {
        businessGroupService.removeParticipants(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup(), null);
        getLogger().info("Remove users as account-managers");
        fireEvent(urequest, Event.CHANGED_EVENT);
    }
}
Also used : IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse)

Example 7 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class ProjectGroupController method handleProjectLeaderGroupEvent.

private void handleProjectLeaderGroupEvent(UserRequest urequest, Event event) {
    if (event instanceof IdentitiesAddEvent) {
        IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
        BusinessGroupAddResponse response = businessGroupService.addOwners(urequest.getIdentity(), urequest.getUserSession().getRoles(), identitiesAddedEvent.getAddIdentities(), project.getProjectGroup(), null);
        identitiesAddedEvent.setIdentitiesAddedEvent(response.getAddedIdentities());
        identitiesAddedEvent.setIdentitiesWithoutPermission(response.getIdentitiesWithoutPermission());
        identitiesAddedEvent.setIdentitiesAlreadyInGroup(response.getIdentitiesAlreadyInGroup());
        getLogger().info("Add users as project-leader");
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesRemoveEvent) {
        businessGroupService.removeOwners(urequest.getIdentity(), ((IdentitiesRemoveEvent) event).getRemovedIdentities(), project.getProjectGroup());
        getLogger().info("Remove users as account-managers");
        fireEvent(urequest, Event.CHANGED_EVENT);
    }
}
Also used : IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse)

Example 8 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class CourseWebService method addCoach.

/**
 * Add a coach to the course
 * @response.representation.200.doc The user is a coach of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or the user not found
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as coach of the course
 */
@PUT
@Path("tutors/{identityKey}")
public Response addCoach(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity tutor = securityManager.loadIdentityByKey(identityKey, false);
    if (tutor == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    UserRequest ureq = getUserRequest(httpRequest);
    // add the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> tutors = Collections.singletonList(tutor);
    IdentitiesAddEvent iae = new IdentitiesAddEvent(tutors);
    rm.addTutors(identity, ureq.getUserSession().getRoles(), iae, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 9 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class CourseWebService method addParticipant.

/**
 * Add an participant to the course
 * @response.representation.200.doc The user is a participant of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or the user not found
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as owner and author of the course
 */
@PUT
@Path("participants/{identityKey}")
public Response addParticipant(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity participant = securityManager.loadIdentityByKey(identityKey, false);
    if (participant == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    UserRequest ureq = getUserRequest(httpRequest);
    // add the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> participants = Collections.singletonList(participant);
    IdentitiesAddEvent iae = new IdentitiesAddEvent(participants);
    rm.addParticipants(identity, ureq.getUserSession().getRoles(), iae, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 10 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class CourseWebService method addAuthor.

/**
 * Add an owner and author to the course
 * @response.representation.200.doc The user is an author and owner of the course
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course or the user not found
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns 200  if the user is added as owner and author of the course
 */
@PUT
@Path("authors/{identityKey}")
public Response addAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (author == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    boolean hasBeenAuthor = securityManager.isIdentityInSecurityGroup(author, authorGroup);
    if (!hasBeenAuthor) {
        // not an author already, add this identity to the security group "authors"
        securityManager.addIdentityToSecurityGroup(author, authorGroup);
        log.audit("User::" + identity.getName() + " added system role::" + Constants.GROUP_AUTHORS + " to user::" + author.getName() + " via addAuthor method in course REST API", null);
    }
    // add the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> authors = Collections.singletonList(author);
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
    rm.addOwners(identity, identitiesAddedEvent, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Aggregations

IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)64 Identity (org.olat.core.id.Identity)50 RepositoryEntry (org.olat.repository.RepositoryEntry)44 PUT (javax.ws.rs.PUT)24 Path (javax.ws.rs.Path)24 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)24 MailPackage (org.olat.core.util.mail.MailPackage)22 UserRequest (org.olat.core.gui.UserRequest)20 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)20 URI (java.net.URI)16 HttpResponse (org.apache.http.HttpResponse)16 Test (org.junit.Test)16 IdentitiesRemoveEvent (org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent)16 Consumes (javax.ws.rs.Consumes)12 RepositoryManager (org.olat.repository.RepositoryManager)12 ArrayList (java.util.ArrayList)8 HttpDelete (org.apache.http.client.methods.HttpDelete)8 HttpGet (org.apache.http.client.methods.HttpGet)8 BaseSecurity (org.olat.basesecurity.BaseSecurity)8 SecurityGroup (org.olat.basesecurity.SecurityGroup)8