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