Search in sources :

Example 51 with MailPackage

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

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)

Example 52 with MailPackage

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

the class CourseWebService method removeParticipant.

/**
 * Remove a participant from the course
 * @response.representation.200.doc The user was successfully removed as 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 removed as participant of the course
 */
@DELETE
@Path("participants/{identityKey}")
public Response removeParticipant(@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);
    // remove the user as participant of the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    List<Identity> participants = Collections.singletonList(participant);
    rm.removeParticipants(identity, participants, repositoryEntry, new MailPackage(false), 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 53 with MailPackage

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

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

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

the class RepositoryEntryDetailsController method doLeave.

protected void doLeave() {
    if (guestOnly)
        return;
    MailerResult result = new MailerResult();
    MailPackage reMailing = new MailPackage(result, getWindowControl().getBusinessControl().getAsString(), true);
    LeavingStatusList status = new LeavingStatusList();
    // leave course
    repositoryManager.leave(getIdentity(), entry, status, reMailing);
    // leave groups
    businessGroupService.leave(getIdentity(), entry, status, reMailing);
    // make sur all changes are committed
    DBFactory.getInstance().commit();
    if (status.isWarningManagedGroup() || status.isWarningManagedCourse()) {
        showWarning("sign.out.warning.managed");
    } else if (status.isWarningGroupWithMultipleResources()) {
        showWarning("sign.out.warning.mutiple.resources");
    } else {
        showInfo("sign.out.success", new String[] { entry.getDisplayname() });
    }
}
Also used : LeavingStatusList(org.olat.repository.LeavingStatusList) MailPackage(org.olat.core.util.mail.MailPackage) MailerResult(org.olat.core.util.mail.MailerResult)

Example 55 with MailPackage

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

the class BusinessGroupServiceTest method testUpdateMemberships.

@Test
public void testUpdateMemberships() {
    // create a group with owner and participant
    Identity ureqIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-u-");
    Identity ownerIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-o-");
    Identity partIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("Up-mships-p-");
    BusinessGroup group = businessGroupService.createBusinessGroup(ureqIdentity, "Up-mships", "updateMemberships", 0, 10, false, false, null);
    businessGroupRelationDao.addRole(ownerIdentity, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(partIdentity, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // invert the roles
    BusinessGroupMembershipChange change1 = new BusinessGroupMembershipChange(ownerIdentity, group.getKey());
    change1.setTutor(Boolean.FALSE);
    change1.setParticipant(Boolean.TRUE);
    BusinessGroupMembershipChange change2 = new BusinessGroupMembershipChange(partIdentity, group.getKey());
    change2.setTutor(Boolean.TRUE);
    change2.setParticipant(Boolean.FALSE);
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    changes.add(change1);
    changes.add(change2);
    businessGroupService.updateMemberships(ureqIdentity, changes, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // check the result
    boolean partIsOwner = businessGroupService.hasRoles(partIdentity, group, GroupRoles.coach.name());
    Assert.assertTrue(partIsOwner);
    boolean partIsPart = businessGroupService.hasRoles(partIdentity, group, GroupRoles.participant.name());
    Assert.assertFalse(partIsPart);
    boolean ownerIsPart = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.participant.name());
    Assert.assertTrue(ownerIsPart);
    boolean ownerIsOwner = businessGroupService.hasRoles(ownerIdentity, group, GroupRoles.coach.name());
    Assert.assertFalse(ownerIsOwner);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

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