Search in sources :

Example 46 with MailPackage

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

the class GroupOverviewController method doAddToGroups.

private void doAddToGroups(AddToGroupsEvent e, boolean sendMail) {
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    if (e.getOwnerGroupKeys() != null && !e.getOwnerGroupKeys().isEmpty()) {
        for (Long tutorGroupKey : e.getOwnerGroupKeys()) {
            BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, tutorGroupKey);
            change.setTutor(Boolean.TRUE);
            changes.add(change);
        }
    }
    if (e.getParticipantGroupKeys() != null && !e.getParticipantGroupKeys().isEmpty()) {
        for (Long partGroupKey : e.getParticipantGroupKeys()) {
            BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, partGroupKey);
            change.setParticipant(Boolean.TRUE);
            changes.add(change);
        }
    }
    MailPackage mailing = new MailPackage(sendMail);
    businessGroupService.updateMemberships(getIdentity(), changes, mailing);
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) ArrayList(java.util.ArrayList)

Example 47 with MailPackage

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

the class ACFrontendManager method allowAccesToResource.

@Override
public boolean allowAccesToResource(final Identity identity, final Offer offer) {
    // check if offer is ok: key is stupid but further check as date, validity...
    if (offer.getKey() == null) {
        return false;
    }
    // check the resource
    OLATResource resource = offer.getResource();
    if (resource == null || resource.getKey() == null || resource.getResourceableId() == null || resource.getResourceableTypeName() == null) {
        return false;
    }
    String resourceType = resource.getResourceableTypeName();
    if ("BusinessGroup".equals(resourceType)) {
        BusinessGroup group = businessGroupService.loadBusinessGroup(resource);
        if (group != null) {
            MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
            EnrollState result = businessGroupService.enroll(identity, null, identity, group, mailing);
            return !result.isFailed();
        }
    } else {
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(resource, false);
        if (entry != null) {
            if (!repositoryEntryRelationDao.hasRole(identity, entry, GroupRoles.participant.name())) {
                repositoryEntryRelationDao.addRole(identity, entry, GroupRoles.participant.name());
                if (offer.isConfirmationEmail()) {
                    MailPackage mailing = new MailPackage(offer.isConfirmationEmail());
                    RepositoryMailing.sendEmail(identity, identity, entry, RepositoryMailing.Type.addParticipantItself, mailing);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) EnrollState(org.olat.group.model.EnrollState) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 48 with MailPackage

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

the class CourseWebService method addCoaches.

@PUT
@Path("tutors")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addCoaches(UserVO[] coaches, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    List<Identity> coachList = loadIdentities(coaches);
    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();
    IdentitiesAddEvent iae = new IdentitiesAddEvent(coachList);
    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) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 49 with MailPackage

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

the class CourseWebService method addParticipants.

/**
 * 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")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addParticipants(UserVO[] participants, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    List<Identity> participantList = loadIdentities(participants);
    Identity identity = getIdentity(httpRequest);
    UserRequest ureq = getUserRequest(httpRequest);
    // add the participants to the course
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    IdentitiesAddEvent iae = new IdentitiesAddEvent(participantList);
    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) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 50 with MailPackage

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

the class CourseWebService method addAuthors.

@PUT
@Path("authors")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addAuthors(UserVO[] authors, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<Identity> authorList = loadIdentities(authors);
    Identity identity = getIdentity(httpRequest);
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    for (Identity author : authorList) {
        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
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authorList);
    RepositoryManager.getInstance().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) 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) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

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