use of org.olat.basesecurity.Group in project openolat by klemens.
the class BGRightManagerImpl method removeBGRights.
@Override
public void removeBGRights(Collection<Group> groups, OLATResource resource) {
for (Group group : groups) {
groupDao.removeGrants(group, GroupRoles.coach.name(), resource);
groupDao.removeGrants(group, GroupRoles.participant.name(), resource);
}
}
use of org.olat.basesecurity.Group in project openolat by klemens.
the class QTIStatisticsResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
CourseNode courseNode = resourceResult.getTestCourseNode();
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
hres.setHeader("Content-Description", urlEncodedLabel);
try {
// fields separated by
String sep = "\\t";
// fields embedded by
String emb = "\"";
// carriage return
String car = "\\r\\n";
sep = QTIArchiver.convert2CtrlChars(sep);
car = QTIArchiver.convert2CtrlChars(car);
int exportType = 1;
QTIExportFormatter formatter;
if (QTIType.test.equals(resourceResult.getType())) {
exportType = 1;
formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
} else if (QTIType.survey.equals(resourceResult.getType())) {
exportType = 2;
formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
} else {
return;
}
Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
QTIResultManager qrm = QTIResultManager.getInstance();
QTIStatisticSearchParams params = resourceResult.getSearchParams();
List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.basesecurity.Group in project openolat by klemens.
the class EditLectureBlockController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_repo_edit_lecture_form");
if (lectureBlock != null && StringHelper.containsNonWhitespace(lectureBlock.getManagedFlagsString())) {
setFormWarning("form.managedflags.intro.short", null);
}
String title = lectureBlock == null ? null : lectureBlock.getTitle();
titleEl = uifactory.addTextElement("title", "lecture.title", 128, title, formLayout);
titleEl.setElementCssClass("o_sel_repo_lecture_title");
titleEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.title));
titleEl.setMandatory(true);
plannedLecturesEl = uifactory.addDropdownSingleselect("planned.lectures", "planned.lectures", formLayout, plannedLecturesKeys, plannedLecturesKeys, null);
plannedLecturesEl.setMandatory(true);
String plannedlectures = lectureBlock == null ? "4" : Integer.toString(lectureBlock.getPlannedLecturesNumber());
for (String plannedLecturesKey : plannedLecturesKeys) {
if (plannedlectures.equals(plannedLecturesKey)) {
plannedLecturesEl.select(plannedLecturesKey, true);
break;
}
}
// freeze it after roll call done
boolean plannedLecturesEditable = (lectureBlock == null || (lectureBlock.getStatus() != LectureBlockStatus.done && lectureBlock.getRollCallStatus() != LectureRollCallStatus.closed && lectureBlock.getRollCallStatus() != LectureRollCallStatus.autoclosed)) && !lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.plannedLectures);
plannedLecturesEl.setEnabled(plannedLecturesEditable);
String[] onValues = new String[] { "" };
boolean compulsory = lectureBlock == null ? true : lectureBlock.isCompulsory();
compulsoryEl = uifactory.addCheckboxesVertical("compulsory", "lecture.compulsory", formLayout, onKeys, onValues, 1);
compulsoryEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.compulsory));
compulsoryEl.addActionListener(FormEvent.ONCHANGE);
if (compulsory) {
compulsoryEl.select(onKeys[0], true);
}
List<Identity> coaches = repositoryService.getMembers(entry, GroupRoles.coach.name());
teacherKeys = new String[coaches.size() + 1];
teacherValues = new String[coaches.size() + 1];
for (int i = coaches.size() + 1; i-- > 1; ) {
Identity coach = coaches.get(i - 1);
teacherKeys[i] = coach.getKey().toString();
teacherValues[i] = userManager.getUserDisplayName(coach);
}
teacherKeys[0] = "-";
teacherValues[0] = translate("no.teachers");
teacherEl = uifactory.addCheckboxesVertical("teacher", "lecture.teacher", formLayout, teacherKeys, teacherValues, 2);
teacherEl.setElementCssClass("o_sel_repo_lecture_teachers");
teacherEl.setMandatory(true);
teacherEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.teachers));
boolean found = false;
if (teachers != null && teachers.size() > 0) {
for (Identity teacher : teachers) {
String currentTeacherKey = teacher.getKey().toString();
for (String teacherKey : teacherKeys) {
if (currentTeacherKey.equals(teacherKey)) {
teacherEl.select(currentTeacherKey, true);
found = true;
}
}
}
}
if (!found) {
teacherEl.select(teacherKeys[0], true);
}
Group entryBaseGroup = repositoryService.getDefaultGroup(entry);
groupBox = new ArrayList<>();
groupBox.add(new GroupBox(entry, entryBaseGroup));
SearchBusinessGroupParams params = new SearchBusinessGroupParams();
List<BusinessGroup> businessGroups = businessGroupService.findBusinessGroups(params, entry, 0, -1, BusinessGroupOrder.nameAsc);
for (BusinessGroup businessGroup : businessGroups) {
groupBox.add(new GroupBox(businessGroup));
}
String[] groupKeys = new String[groupBox.size()];
String[] groupValues = new String[groupBox.size()];
for (int i = groupBox.size(); i-- > 0; ) {
groupKeys[i] = Integer.toString(i);
groupValues[i] = groupBox.get(i).getName();
}
groupsEl = uifactory.addCheckboxesVertical("lecture.groups", "lecture.groups", formLayout, groupKeys, groupValues, 2);
groupsEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.groups));
groupsEl.setMandatory(true);
if (lectureBlock != null) {
List<Group> selectedGroups = lectureService.getLectureBlockToGroups(lectureBlock);
for (int i = 0; i < groupBox.size(); i++) {
if (selectedGroups.contains(groupBox.get(i).getBaseGroup())) {
groupsEl.select(Integer.toString(i), true);
}
}
} else if (groupKeys.length == 1) {
groupsEl.select(groupKeys[0], true);
}
String description = lectureBlock == null ? "" : lectureBlock.getDescription();
descriptionEl = uifactory.addTextAreaElement("lecture.descr", 4, 72, description, formLayout);
descriptionEl.setElementCssClass("o_sel_repo_lecture_description");
descriptionEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.description));
String preparation = lectureBlock == null ? "" : lectureBlock.getPreparation();
preparationEl = uifactory.addTextAreaElement("lecture.preparation", 4, 72, preparation, formLayout);
preparationEl.setElementCssClass("o_sel_repo_lecture_preparation");
preparationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.preparation));
String location = lectureBlock == null ? "" : lectureBlock.getLocation();
locationEl = uifactory.addTextElementWithAutoCompleter("location", "lecture.location", 128, location, formLayout);
locationEl.setElementCssClass("o_sel_repo_lecture_location");
locationEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.location));
locationEl.setListProvider(new LocationListProvider(), ureq.getUserSession());
locationEl.setMinLength(1);
Date startDate = lectureBlock == null ? null : lectureBlock.getStartDate();
dateEl = uifactory.addDateChooser("lecture.date", startDate, formLayout);
dateEl.setElementCssClass("o_sel_repo_lecture_date");
dateEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
dateEl.setDomReplacementWrapperRequired(false);
dateEl.setMandatory(true);
String datePage = velocity_root + "/date_start_end.html";
FormLayoutContainer dateCont = FormLayoutContainer.createCustomFormLayout("start_end", getTranslator(), datePage);
dateCont.setLabel("lecture.time", null);
formLayout.add(dateCont);
startHourEl = uifactory.addTextElement("lecture.start.hour", null, 2, "", dateCont);
startHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
startHourEl.setDomReplacementWrapperRequired(false);
startHourEl.setDisplaySize(2);
startHourEl.setMandatory(true);
startMinuteEl = uifactory.addTextElement("lecture.start.minute", null, 2, "", dateCont);
startMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
startMinuteEl.setDomReplacementWrapperRequired(false);
startMinuteEl.setDisplaySize(2);
endHourEl = uifactory.addTextElement("lecture.end.hour", null, 2, "", dateCont);
endHourEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
endHourEl.setDomReplacementWrapperRequired(false);
endHourEl.setDisplaySize(2);
endHourEl.setMandatory(true);
endMinuteEl = uifactory.addTextElement("lecture.end.minute", null, 2, "", dateCont);
endMinuteEl.setEnabled(!lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.dates));
endMinuteEl.setDomReplacementWrapperRequired(false);
endMinuteEl.setDisplaySize(2);
if (lectureBlock != null) {
Calendar cal = Calendar.getInstance();
if (lectureBlock.getStartDate() != null) {
cal.setTime(lectureBlock.getStartDate());
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
startHourEl.setValue(Integer.toString(hour));
startMinuteEl.setValue(formatMinute(minute));
}
if (lectureBlock.getEndDate() != null) {
cal.setTime(lectureBlock.getEndDate());
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
endHourEl.setValue(Integer.toString(hour));
endMinuteEl.setValue(formatMinute(minute));
}
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
uifactory.addFormSubmitButton("save", buttonsCont);
}
use of org.olat.basesecurity.Group in project openolat by klemens.
the class BusinessGroupServiceTest method testDeleteBusinessGroupWithWaitingGroup.
@Test
public void testDeleteBusinessGroupWithWaitingGroup() {
RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
BusinessGroup deleteTestGroup = businessGroupService.createBusinessGroup(id1, "deleteTestGroup-1", "deleteTestGroup-1", -1, -1, true, true, resource);
dbInstance.commitAndCloseSession();
businessGroupService.deleteBusinessGroup(deleteTestGroup);
dbInstance.commitAndCloseSession();
Group reloadedGroup = groupDao.loadGroup(deleteTestGroup.getBaseGroup().getKey());
Assert.assertNull(reloadedGroup);
}
use of org.olat.basesecurity.Group in project openolat by klemens.
the class QTIResultManagerTest method selectResults_limitToSecurityGroup.
@Test
public void selectResults_limitToSecurityGroup() {
RepositoryEntry re = createRepository();
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-16");
repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-17");
dbInstance.commit();
long assessmentId = 841l;
String resSubPath = "qtiResult37";
String itemIdent1 = "NES:PS4:849235797";
String itemIdent2 = "NES:PS4:849235798";
QTIResultSet set1_1 = createSet(1.0f, assessmentId, id1, re, resSubPath, modDate(3, 8, 5), modDate(3, 8, 20));
QTIResult result1_1 = createResult(itemIdent1, "Hello world", set1_1);
QTIResultSet set2_1 = createSet(3.0f, assessmentId, id2, re, resSubPath, modDate(3, 14, 8), modDate(3, 14, 32));
QTIResult result2_1 = createResult(itemIdent1, "Bonjour madame", set2_1);
QTIResultSet set1_1b = createSet(5.0f, assessmentId, id1, re, resSubPath, modDate(3, 10, 35), modDate(3, 10, 55));
QTIResult result1_1b = createResult(itemIdent1, "Tschuss", set1_1b);
QTIResult result1_1c = createResult(itemIdent2, "Tschuss", set1_1b);
dbInstance.commitAndCloseSession();
List<Group> secGroups = Collections.singletonList(repositoryEntryRelationDao.getDefaultGroup(re));
List<QTIResult> resultsType1 = qtiResultManager.selectResults(re.getOlatResource().getResourceableId(), resSubPath, re.getKey(), secGroups, 1);
Assert.assertNotNull(resultsType1);
Assert.assertEquals(3, resultsType1.size());
Assert.assertTrue(resultsType1.contains(result1_1));
Assert.assertTrue(resultsType1.contains(result1_1b));
Assert.assertTrue(resultsType1.contains(result1_1c));
// not a participant in the security group
Assert.assertFalse(resultsType1.contains(result2_1));
}
Aggregations