Search in sources :

Example 51 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class OLATUpgrade_7_1_1 method createRepoEntrySecurityGroups.

private void createRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    boolean save = false;
    if (entry.getTutorGroup() == null) {
        // security group for tutors / coaches
        SecurityGroup tutorGroup = securityManager.createAndPersistSecurityGroup();
        // member of this group may modify member's membership
        securityManager.createAndPersistPolicy(tutorGroup, Constants.PERMISSION_ACCESS, entry.getOlatResource());
        // members of this group are always tutors also
        securityManager.createAndPersistPolicy(tutorGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_TUTOR);
        entry.setTutorGroup(tutorGroup);
        securityManager.createAndPersistPolicy(entry.getTutorGroup(), Constants.PERMISSION_COACH, entry.getOlatResource());
        DBFactory.getInstance().commit();
        save = true;
    }
    if (entry.getParticipantGroup() == null) {
        // security group for participants
        SecurityGroup participantGroup = securityManager.createAndPersistSecurityGroup();
        // member of this group may modify member's membership
        securityManager.createAndPersistPolicy(participantGroup, Constants.PERMISSION_ACCESS, entry.getOlatResource());
        // members of this group are always participants also
        securityManager.createAndPersistPolicy(participantGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_PARTICIPANT);
        entry.setParticipantGroup(participantGroup);
        securityManager.createAndPersistPolicy(entry.getParticipantGroup(), Constants.PERMISSION_PARTI, entry.getOlatResource());
        DBFactory.getInstance().commit();
        save = true;
    }
    if (save) {
        DBFactory.getInstance().updateObject(entry);
    }
}
Also used : SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 52 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class OLATUpgrade_7_1_1 method migrateRepoEntrySecurityGroups.

private void migrateRepoEntrySecurityGroups(RepositoryEntryUpgrade entry) {
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    List<BGContextImpl> contexts = findBGContextsForResource(entry.getOlatResource(), true, true);
    for (BGContextImpl context : contexts) {
        List<BusinessGroupUpgrade> groups = getGroupsOfBGContext(context);
        for (BusinessGroupUpgrade group : groups) {
            // migrate tutors
            if (group.getOwnerGroup() != null) {
                int count = 0;
                List<Identity> owners = securityManager.getIdentitiesOfSecurityGroup(group.getOwnerGroup());
                SecurityGroup tutorGroup = entry.getTutorGroup();
                for (Identity owner : owners) {
                    if (securityManager.isIdentityInSecurityGroup(owner, tutorGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(owner, tutorGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
            // migrate participants
            if (group.getPartipiciantGroup() != null) {
                int count = 0;
                List<Identity> participants = securityManager.getIdentitiesOfSecurityGroup(group.getPartipiciantGroup());
                SecurityGroup participantGroup = entry.getParticipantGroup();
                for (Identity participant : participants) {
                    if (securityManager.isIdentityInSecurityGroup(participant, participantGroup)) {
                        continue;
                    }
                    securityManager.addIdentityToSecurityGroup(participant, participantGroup);
                    if (count++ % 20 == 0) {
                        DBFactory.getInstance().intermediateCommit();
                    }
                }
                DBFactory.getInstance().intermediateCommit();
            }
        }
    }
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) BusinessGroupUpgrade(org.olat.upgrade.model.BusinessGroupUpgrade) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 53 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class BulkAssessmentTask method doProcess.

private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
    final DB dbInstance = DBFactory.getInstance();
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
    final ICourse course = CourseFactory.loadCourse(courseRes);
    final AssessableCourseNode courseNode = getCourseNode();
    final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
    final boolean hasUserComment = courseNode.hasCommentConfigured();
    final boolean hasScore = courseNode.hasScoreConfigured();
    final boolean hasPassed = courseNode.hasPassedConfigured();
    final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
    if (hasReturnFiles) {
        try {
            OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
            String tmp = FolderConfig.getCanonicalTmpDir();
            unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
            unzipped.mkdirs();
            ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
        } catch (Exception e) {
            log.error("Cannot unzip the return files during bulk assessment", e);
        }
    }
    Float min = null;
    Float max = null;
    Float cut = null;
    if (hasScore) {
        min = courseNode.getMinScoreConfiguration();
        max = courseNode.getMaxScoreConfiguration();
    }
    if (hasPassed) {
        cut = courseNode.getCutValueConfiguration();
    }
    int count = 0;
    List<BulkAssessmentRow> rows = datas.getRows();
    for (BulkAssessmentRow row : rows) {
        Long identityKey = row.getIdentityKey();
        if (identityKey == null) {
            feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
            // nothing to do
            continue;
        }
        Identity identity = securityManager.loadIdentityByKey(identityKey);
        IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // update comment, empty string will reset comment
        String userComment = row.getComment();
        if (hasUserComment && userComment != null) {
            // Update userComment in db
            courseNode.updateUserUserComment(userComment, uce, coachIdentity);
        // LD: why do we have to update the efficiency statement?
        // EfficiencyStatementManager esm =	EfficiencyStatementManager.getInstance();
        // esm.updateUserEfficiencyStatement(uce);
        }
        // update score
        Float score = row.getScore();
        if (hasScore && score != null) {
            // score < minimum score
            if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
            // "bulk.action.lessThanMin";
            } else // score > maximum score
            if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
            // "bulk.action.greaterThanMax";
            } else {
                // score between minimum and maximum score
                ScoreEvaluation se;
                if (hasPassed && cut != null) {
                    Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
                    se = new ScoreEvaluation(score, passed);
                } else {
                    se = new ScoreEvaluation(score, null);
                }
                // Update score,passed properties in db, and the user's efficiency statement
                courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
            }
        }
        Boolean passed = row.getPassed();
        if (hasPassed && passed != null && cut == null) {
            // Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
            ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
            Float oldScore = seOld.getScore();
            ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
            // Update score,passed properties in db, and the user's efficiency statement
            boolean incrementAttempts = false;
            courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
        }
        boolean identityHasReturnFile = false;
        if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
            String assessedId = row.getAssessedId();
            File assessedFolder = new File(unzipped, assessedId);
            identityHasReturnFile = assessedFolder.exists();
            if (identityHasReturnFile) {
                processReturnFile(courseNode, row, uce, assessedFolder);
            }
        }
        if (courseNode instanceof GTACourseNode) {
            // push the state further
            GTACourseNode gtaNode = (GTACourseNode) courseNode;
            if ((hasScore && score != null) || (hasPassed && passed != null)) {
                // pushed to graded
                updateTasksState(gtaNode, uce, TaskProcess.grading);
            } else if (hasReturnFiles) {
                // push to revised
                updateTasksState(gtaNode, uce, TaskProcess.correction);
            }
        }
        if (count++ % 5 == 0) {
            dbInstance.commitAndCloseSession();
        } else {
            dbInstance.commit();
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow) FileNotFoundException(java.io.FileNotFoundException) BaseSecurity(org.olat.basesecurity.BaseSecurity) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) DB(org.olat.core.commons.persistence.DB)

Example 54 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class BusinessGroupMailing method sendEmail.

protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
    if (mailing != null && !mailing.isSendEmail()) {
        return;
    }
    if (mailing == null) {
        BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
        BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
        Roles ureqRoles = securityManager.getRoles(ureqIdentity);
        if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
            return;
        }
    }
    MailTemplate template = mailing == null ? null : mailing.getTemplate();
    if (mailing == null || mailing.getTemplate() == null) {
        // booking by myself
        if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
            template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
        } else {
            template = getDefaultTemplate(type, group, ureqIdentity);
        }
    } else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
        BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
        template = new MailTemplateDelegate(template, group, repoEntries);
    }
    MailContext context = mailing == null ? null : mailing.getContext();
    if (context == null) {
        context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
    }
    MailerResult result = new MailerResult();
    String metaId = mailing != null ? mailing.getUuid() : null;
    MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
    MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
    if (bundle != null) {
        mailService.sendMessage(bundle);
    }
    if (mailing != null) {
        mailing.appendResult(result);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) BusinessGroupModule(org.olat.group.BusinessGroupModule) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Roles(org.olat.core.id.Roles) BaseSecurity(org.olat.basesecurity.BaseSecurity) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) MailManager(org.olat.core.util.mail.MailManager) List(java.util.List) MailBundle(org.olat.core.util.mail.MailBundle)

Example 55 with BaseSecurity

use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.

the class CertificationWebService method postCertificate.

/**
 * Upload a new certificate.
 *
 * @response.representation.200.doc if the certificate was uploaded
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The identity or the resource cannot be found
 * @param identityKey The owner of the certificate
 * @param resourceKey The primary key of the resource of the repository entry of the course.
 * @param request The request
 * @return Nothing special
 */
@POST
@Path("{identityKey}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postCertificate(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    MultipartReader partsReader = null;
    try {
        partsReader = new MultipartReader(request);
        File tmpFile = partsReader.getFile();
        String courseTitle = partsReader.getValue("courseTitle");
        String creationDateStr = partsReader.getValue("creationDate");
        Date creationDate = null;
        if (StringHelper.containsNonWhitespace(creationDateStr)) {
            creationDate = ObjectFactory.parseDate(creationDateStr);
        }
        CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
        BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
        Identity assessedIdentity = baseSecurity.loadIdentityByKey(identityKey);
        if (assessedIdentity == null) {
            return Response.serverError().status(Response.Status.NOT_FOUND).build();
        }
        OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
        OLATResource resource = resourceManager.findResourceById(resourceKey);
        if (resource == null) {
            certificatesManager.uploadStandaloneCertificate(assessedIdentity, creationDate, courseTitle, resourceKey, tmpFile);
        } else {
            certificatesManager.uploadCertificate(assessedIdentity, creationDate, resource, tmpFile);
        }
        return Response.ok().build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    } finally {
        MultipartReader.closeQuietly(partsReader);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) CertificatesManager(org.olat.course.certificate.CertificatesManager) OLATResourceManager(org.olat.resource.OLATResourceManager) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) File(java.io.File) MultipartReader(org.olat.restapi.support.MultipartReader) Date(java.util.Date) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

BaseSecurity (org.olat.basesecurity.BaseSecurity)116 Identity (org.olat.core.id.Identity)88 Path (javax.ws.rs.Path)48 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)28 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)22 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 DELETE (javax.ws.rs.DELETE)14 Authentication (org.olat.basesecurity.Authentication)14 MailPackage (org.olat.core.util.mail.MailPackage)14 RepositoryManager (org.olat.repository.RepositoryManager)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 CertificatesManager (org.olat.course.certificate.CertificatesManager)10 OLATResource (org.olat.resource.OLATResource)10 OLATResourceManager (org.olat.resource.OLATResourceManager)10 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8