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.");
}
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);
}
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";
}
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();
}
}
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);
}
Aggregations