Search in sources :

Example 71 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class RepositoryEntryResource method addOwner.

/**
 * Adds an owner to the repository entry.
 * @response.representation.200.doc The user is added as owner of the repository entry
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The repository entry or the user cannot be found
 * @param repoEntryKey The key of the repository entry
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@PUT
@Path("owners/{identityKey}")
public Response addOwner(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
        if (repoEntry == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        } else if (!isAuthorEditor(repoEntry, request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        Identity identityToAdd = securityManager.loadIdentityByKey(identityKey);
        if (identityToAdd == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
        repositoryManager.addOwners(ureq.getIdentity(), iae, repoEntry, new MailPackage(false));
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to add an owner to a repository entry", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) 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) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 72 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class RepositoryEntryResource method removeCoach.

/**
 * Removes the coach from the repository entry.
 * @response.representation.200.doc The user is removed as coach from the repository entry
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The repository entry or the user cannot be found
 * @param repoEntryKey The key of the repository entry
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@DELETE
@Path("coaches/{identityKey}")
public Response removeCoach(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
        if (repoEntry == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        } else if (!isAuthorEditor(repoEntry, request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        Identity identityToRemove = securityManager.loadIdentityByKey(identityKey);
        if (identityToRemove == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        repositoryManager.removeTutors(ureq.getIdentity(), Collections.singletonList(identityToRemove), repoEntry, new MailPackage(false));
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to remove a coach from a repository entry", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) 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) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 73 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

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 74 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class CourseWebService method removeAuthor.

/**
 * Remove an owner and author to the course
 * @response.representation.200.doc The user was successfully removed as 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 removed as owner of the course
 */
@DELETE
@Path("authors/{identityKey}")
public Response removeAuthor(@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);
    // remove the author as owner of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> authors = Collections.singletonList(author);
    rm.removeOwners(identity, authors, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 75 with MailPackage

use of org.olat.core.util.mail.MailPackage in project openolat by klemens.

the class CourseWebService method removeCoach.

/**
 * Remove a coach from the course
 * @response.representation.200.doc The user was successfully removed as 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 removed as coach of the course
 */
@DELETE
@Path("tutors/{identityKey}")
public Response removeCoach(@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 coach = securityManager.loadIdentityByKey(identityKey, false);
    if (coach == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    Identity identity = getIdentity(httpRequest);
    // remove the user as coach of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> coaches = Collections.singletonList(coach);
    rm.removeTutors(identity, coaches, repositoryEntry, new MailPackage(false));
    return Response.ok().build();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Aggregations

MailPackage (org.olat.core.util.mail.MailPackage)84 Identity (org.olat.core.id.Identity)58 RepositoryEntry (org.olat.repository.RepositoryEntry)42 Path (javax.ws.rs.Path)26 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)26 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)22 PUT (javax.ws.rs.PUT)16 Test (org.junit.Test)16 UserRequest (org.olat.core.gui.UserRequest)16 BusinessGroup (org.olat.group.BusinessGroup)16 BusinessGroupMembershipChange (org.olat.group.model.BusinessGroupMembershipChange)16 RepositoryManager (org.olat.repository.RepositoryManager)16 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)16 BaseSecurity (org.olat.basesecurity.BaseSecurity)14 ArrayList (java.util.ArrayList)12 MailerResult (org.olat.core.util.mail.MailerResult)12 RepositoryEntryPermissionChangeEvent (org.olat.repository.model.RepositoryEntryPermissionChangeEvent)12 DELETE (javax.ws.rs.DELETE)10 Consumes (javax.ws.rs.Consumes)8 MailTemplate (org.olat.core.util.mail.MailTemplate)8