Search in sources :

Example 51 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method deleteCourse.

/**
 * Delete a course including its course folder and all references to resources
 * this course holds.
 *
 * @param res
 */
public static void deleteCourse(RepositoryEntry entry, OLATResource res) {
    final long start = System.currentTimeMillis();
    log.info("deleteCourse: starting to delete course. res=" + res);
    PersistingCourseImpl course = null;
    try {
        course = (PersistingCourseImpl) loadCourse(res);
    } catch (CorruptedCourseException e) {
        log.error("Try to delete a corrupted course, I make want I can.");
    }
    // call cleanupOnDelete for nodes
    if (course != null) {
        Visitor visitor = new NodeDeletionVisitor(course);
        TreeVisitor tv = new TreeVisitor(visitor, course.getRunStructure().getRootNode(), true);
        tv.visitAll();
    }
    // delete assessment notifications
    OLATResourceable assessmentOres = OresHelper.createOLATResourceableInstance(CourseModule.ORES_COURSE_ASSESSMENT, res.getResourceableId());
    NotificationsManager.getInstance().deletePublishersOf(assessmentOres);
    // delete all course notifications
    NotificationsManager.getInstance().deletePublishersOf(res);
    // delete calendar subscription
    clearCalenderSubscriptions(res, course);
    // the course folder which is deleted right after)
    if (course != null) {
        CourseConfigManagerImpl.getInstance().deleteConfigOf(course);
    }
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(res);
    // delete course group- and rightmanagement
    CourseGroupManager courseGroupManager = PersistingCourseGroupManager.getInstance(res);
    courseGroupManager.deleteCourseGroupmanagement();
    // delete all remaining course properties
    CoursePropertyManager propertyManager = PersistingCoursePropertyManager.getInstance(res);
    propertyManager.deleteAllCourseProperties();
    // delete course calendar
    CoreSpringFactory.getImpl(ImportToCalendarManager.class).deleteCourseImportedCalendars(res);
    CoreSpringFactory.getImpl(CalendarManager.class).deleteCourseCalendar(res);
    // delete IM messages
    CoreSpringFactory.getImpl(InstantMessagingService.class).deleteMessages(res);
    // delete tasks
    CoreSpringFactory.getImpl(GTAManager.class).deleteAllTaskLists(entry);
    // cleanup cache
    removeFromCache(res.getResourceableId());
    // TODO: ld: broadcast event: DeleteCourseEvent
    // Everything is deleted, so we could get rid of course logging
    // with the change in user audit logging - which now all goes into a DB
    // we no longer do this though!
    // delete course directory
    VFSContainer fCourseBasePath = getCourseBaseContainer(res.getResourceableId());
    VFSStatus status = fCourseBasePath.deleteSilently();
    boolean deletionSuccessful = (status == VFSConstants.YES || status == VFSConstants.SUCCESS);
    log.info("deleteCourse: finished deletion. res=" + res + ", deletion successful: " + deletionSuccessful + ", duration: " + (System.currentTimeMillis() - start) + " ms.");
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) InstantMessagingService(org.olat.instantMessaging.InstantMessagingService) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) TreeVisitor(org.olat.core.util.tree.TreeVisitor) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) VFSStatus(org.olat.core.util.vfs.VFSStatus) GTAManager(org.olat.course.nodes.gta.GTAManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 52 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class CourseCalendars method createCourseCalendarsWrapper.

public static CourseCalendars createCourseCalendarsWrapper(UserRequest ureq, WindowControl wControl, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseEnvironment().getCourseResourceableId());
    KalendarRenderWrapper courseKalendarWrapper = getCourseCalendarWrapper(ureq, courseEnv, ne);
    // add link provider
    CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl);
    courseKalendarWrapper.setLinkProvider(clpc);
    calendars.add(courseKalendarWrapper);
    Identity identity = ureq.getIdentity();
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    // add course group calendars
    boolean isGroupManager = ureq.getUserSession().getRoles().isOLATAdmin() || ureq.getUserSession().getRoles().isGroupManager() || cgm.isIdentityCourseAdministrator(identity) || cgm.hasRight(identity, CourseRights.RIGHT_GROUPMANAGEMENT);
    boolean readOnly = courseEnv.isCourseReadOnly();
    if (isGroupManager) {
        // learning groups
        List<BusinessGroup> allGroups = cgm.getAllBusinessGroups();
        addCalendars(ureq, courseEnv, allGroups, !readOnly, clpc, calendars);
    } else {
        // learning groups
        List<BusinessGroup> ownerGroups = cgm.getOwnedBusinessGroups(identity);
        addCalendars(ureq, courseEnv, ownerGroups, !readOnly, clpc, calendars);
        List<BusinessGroup> attendedGroups = cgm.getParticipatingBusinessGroups(identity);
        for (BusinessGroup ownerGroup : ownerGroups) {
            if (attendedGroups.contains(ownerGroup)) {
                attendedGroups.remove(ownerGroup);
            }
        }
        addCalendars(ureq, courseEnv, attendedGroups, false, clpc, calendars);
    }
    return new CourseCalendars(courseKalendarWrapper, calendars);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Identity(org.olat.core.id.Identity)

Example 53 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class LTIRunController method getLTIRoles.

private String getLTIRoles() {
    if (roles.isGuestOnly()) {
        return "Guest";
    }
    CourseGroupManager groupManager = courseEnv.getCourseGroupManager();
    boolean admin = groupManager.isIdentityCourseAdministrator(getIdentity());
    if (admin || roles.isOLATAdmin()) {
        String authorRole = config.getStringValue(BasicLTICourseNode.CONFIG_KEY_AUTHORROLE);
        if (StringHelper.containsNonWhitespace(authorRole)) {
            return authorRole;
        }
        return "Instructor,Administrator";
    }
    boolean coach = groupManager.isIdentityCourseCoach(getIdentity());
    if (coach) {
        String coachRole = config.getStringValue(BasicLTICourseNode.CONFIG_KEY_COACHROLE);
        if (StringHelper.containsNonWhitespace(coachRole)) {
            return coachRole;
        }
        return "Instructor";
    }
    String participantRole = config.getStringValue(BasicLTICourseNode.CONFIG_KEY_PARTICIPANTROLE);
    if (StringHelper.containsNonWhitespace(participantRole)) {
        return participantRole;
    }
    return "Learner";
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager)

Example 54 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class AssessmentNotificationsHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
        // course don't exist anymore
        notificationsManager.deactivate(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
    try {
        Date latestNews = p.getLatestNewsDate();
        Identity identity = subscriber.getIdentity();
        // can't be loaded when already deleted
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = loadCourseFromId(courseId);
            if (courseStatus(course)) {
                // course admins or users with the course right to have full access to
                // the assessment tool will have full access to user tests
                CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
                final boolean hasFullAccess = (cgm.isIdentityCourseAdministrator(identity) ? true : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
                final Set<Identity> coachedUsers = new HashSet<Identity>();
                if (!hasFullAccess) {
                    // initialize list of users, only when user has not full access
                    List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
                    List<Identity> coachedIdentites = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
                    coachedUsers.addAll(coachedIdentites);
                }
                List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
                Translator translator = Util.createPackageTranslator(AssessmentManager.class, locale);
                for (AssessableCourseNode test : testNodes) {
                    List<AssessmentEntry> assessments = courseNodeAssessmentDao.loadAssessmentEntryBySubIdent(cgm.getCourseEntry(), test.getIdent());
                    for (AssessmentEntry assessment : assessments) {
                        Date modDate = assessment.getLastModified();
                        Identity assessedIdentity = assessment.getIdentity();
                        if (modDate.after(compareDate) && (hasFullAccess || coachedUsers.contains(assessedIdentity))) {
                            BigDecimal score = assessment.getScore();
                            if (test instanceof ScormCourseNode) {
                                ScormCourseNode scormTest = (ScormCourseNode) test;
                                // check if completed or passed
                                String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
                                if (!"passed".equals(status) && !"completed".equals(status)) {
                                    continue;
                                }
                            }
                            String desc;
                            String type = translator.translate("notifications.entry." + test.getType());
                            if (score == null) {
                                desc = translator.translate("notifications.entry.attempt", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), type });
                            } else {
                                String scoreStr = AssessmentHelper.getRoundedScore(score);
                                desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), scoreStr, type });
                            }
                            String urlToSend = null;
                            String businessPath = null;
                            if (p.getBusinessPath() != null) {
                                businessPath = p.getBusinessPath() + "[Users:0][Node:" + test.getIdent() + "][Identity:" + assessedIdentity.getKey() + "]";
                                urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                            }
                            SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
                            if (si == null) {
                                String title = translator.translate("notifications.header", new String[] { course.getCourseTitle() });
                                String css = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(test.getType()).getIconCSSClass();
                                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
                            }
                            si.addSubscriptionListItem(subListItem);
                        }
                    }
                }
            }
        }
        if (si == null) {
            si = notificationsManager.getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating assessment notifications", e);
        checkPublisher(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssertException(org.olat.core.logging.AssertException) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 55 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.

the class AssessmentNotificationsHandler method canSubscribeForAssessmentNotification.

/**
 * Assessment notification rights check.<br>
 * Tests if an <code>Identity</code> can subscribe for assessment
 * notification for the specified <code>ICourse</code>.<br>
 * <br>
 * <b>PRE CONDITIONS</b>
 * <ul>
 * <li> <code>course != null</code>
 * </ul>
 *
 * @param ident the identity to check rights for. Can be <code>null</code>
 * @param course the course to check rights against
 * @return if <code>ident == null</code> this method always returns false;
 *         otherwise subscriptions rights are met only by course
 *         administrators and course coaches
 */
private boolean canSubscribeForAssessmentNotification(Identity ident, ICourse course) {
    if (ident == null)
        return false;
    CourseGroupManager grpMan = course.getCourseEnvironment().getCourseGroupManager();
    boolean isInstitutionalResourceManager = securityManager.isIdentityInSecurityGroup(ident, securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER));
    return isInstitutionalResourceManager || grpMan.isIdentityCourseAdministrator(ident) || grpMan.isIdentityCourseCoach(ident) || grpMan.hasRight(ident, CourseRights.RIGHT_ASSESSMENT);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager)

Aggregations

CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)84 Identity (org.olat.core.id.Identity)28 ICourse (org.olat.course.ICourse)28 BusinessGroup (org.olat.group.BusinessGroup)26 RepositoryEntry (org.olat.repository.RepositoryEntry)22 HashSet (java.util.HashSet)12 Roles (org.olat.core.id.Roles)12 ArrayList (java.util.ArrayList)10 BusinessGroupService (org.olat.group.BusinessGroupService)10 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)8 UserRequest (org.olat.core.gui.UserRequest)8 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)8 PersistingCourseGroupManager (org.olat.course.groupsandrights.PersistingCourseGroupManager)8 OLATResource (org.olat.resource.OLATResource)8 File (java.io.File)6 Date (java.util.Date)6 CalendarManager (org.olat.commons.calendar.CalendarManager)6 Publisher (org.olat.core.commons.services.notifications.Publisher)6 OLATResourceable (org.olat.core.id.OLATResourceable)6 AssertException (org.olat.core.logging.AssertException)6