Search in sources :

Example 26 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class RestSecurityHelper method isAuthorGrpManager.

public static boolean isAuthorGrpManager(ICourse course, HttpServletRequest request) {
    try {
        Roles roles = getRoles(request);
        if (roles.isOLATAdmin())
            return true;
        if (roles.isAuthor()) {
            UserRequest ureq = getUserRequest(request);
            Identity identity = ureq.getIdentity();
            CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
            boolean editor = cgm.hasRight(identity, CourseRights.RIGHT_GROUPMANAGEMENT);
            return editor;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) UserRequest(org.olat.core.gui.UserRequest) ParseException(java.text.ParseException)

Example 27 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

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 28 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class AssessmentModeEditController method doChooseAreas.

private void doChooseAreas(UserRequest ureq) {
    if (areaChooseCtrl != null)
        return;
    ICourse course = CourseFactory.loadCourse(courseOres);
    CourseGroupManager groupManager = course.getCourseEnvironment().getCourseGroupManager();
    areaChooseCtrl = new AreaSelectionController(ureq, getWindowControl(), true, groupManager, areaKeys);
    listenTo(areaChooseCtrl);
    cmc = new CloseableModalController(getWindowControl(), null, areaChooseCtrl.getInitialComponent(), true, translate("popup.chooseareas"), false);
    listenTo(cmc);
    cmc.activate();
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ICourse(org.olat.course.ICourse) AreaSelectionController(org.olat.course.condition.AreaSelectionController)

Example 29 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class PublishProcessTest method deployRawCourseFromZIP.

/**
 * This method copy the edtiro tree model and run structure as is during the import.
 * @param exportedCourseZIPFile
 * @param softKey
 * @param access
 * @return
 */
private RepositoryEntry deployRawCourseFromZIP(File exportedCourseZIPFile, String softKey, int access) {
    // create the course instance
    OLATResource newCourseResource = olatResourceManager.createOLATResourceInstance(CourseModule.class);
    ICourse course = CourseFactory.importCourseFromZip(newCourseResource, exportedCourseZIPFile);
    // course is now also in course cache!
    if (course == null) {
        return null;
    }
    File courseExportData = course.getCourseExportDataDir().getBasefile();
    // get the export data directory
    // create the repository entry
    RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(courseExportData);
    if (!StringHelper.containsNonWhitespace(softKey)) {
        softKey = importExport.getSoftkey();
    }
    RepositoryEntry re = repositoryService.create(importExport.getInitialAuthor(), importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), newCourseResource);
    // ok, continue import
    re.setSoftkey(softKey);
    // set access configuration
    re.setAccess(access);
    // save the repository entry
    re = repositoryService.update(re);
    // import groups
    course = CourseFactory.openCourseEditSession(course.getResourceableId());
    // create group management
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    // import groups
    cgm.importCourseBusinessGroups(courseExportData);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    // cleanup export data
    FileUtils.deleteDirsAndFiles(courseExportData, true, true);
    return re;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) RepositoryEntryImportExport(org.olat.repository.RepositoryEntryImportExport) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File)

Example 30 with CourseGroupManager

use of org.olat.course.groupsandrights.CourseGroupManager in project openolat by klemens.

the class UserCourseEnvironmentImpl method isAdmin.

@Override
public boolean isAdmin() {
    if (admin != null) {
        return admin.booleanValue();
    }
    // lazy loading
    CourseGroupManager cgm = courseEnvironment.getCourseGroupManager();
    boolean admiLazy = cgm.isIdentityCourseAdministrator(identityEnvironment.getIdentity());
    admin = new Boolean(admiLazy);
    return admiLazy;
}
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