use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.
the class CourseSiteContextEntryControllerCreator method createLaunchController.
/**
* Create a launch controller used to launch the given repo entry.
* @param re
* @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
* @param ureq
* @param wControl
* @return null if no entry was found, a no access message controller if not allowed to launch or the launch
* controller if successful.
*/
private Controller createLaunchController(RepositoryEntry re, UserRequest ureq, WindowControl wControl) {
if (re == null) {
return messageController(ureq, wControl, "repositoryentry.not.existing");
}
UserSession usess = ureq.getUserSession();
if (re.getAccess() == RepositoryEntry.DELETED) {
Roles roles = usess.getRoles();
if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
return messageController(ureq, wControl, "repositoryentry.deleted");
}
}
if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(re.getOlatResource())) {
return null;
}
RepositoryManager rm = RepositoryManager.getInstance();
RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, re);
if (!reSecurity.canLaunch()) {
return messageController(ureq, wControl, "launch.noaccess");
}
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
rs.incrementLaunchCounter(re);
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
WindowControl bwControl;
OLATResourceable businessOres = re;
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
if (ce.equals(wControl.getBusinessControl().getCurrentContextEntry())) {
bwControl = wControl;
} else {
bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
}
MainLayoutController ctrl = handler.createLaunchController(re, reSecurity, ureq, bwControl);
if (ctrl == null) {
throw new AssertException("could not create controller for repositoryEntry " + re);
}
return ctrl;
}
use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.
the class CertificatesManagerTest method deleteCourse.
/**
* Create a course, add a certificate to it and delete the course.
* The certificate stays.
*
* @throws URISyntaxException
*/
@Test
public void deleteCourse() throws URISyntaxException {
// create a course with a certificate
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cer-del-2");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(identity);
dbInstance.commitAndCloseSession();
Long resourceKey = entry.getOlatResource().getKey();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
URL certificateUrl = CertificatesManagerTest.class.getResource("template.pdf");
File certificateFile = new File(certificateUrl.toURI());
Certificate certificate = certificatesManager.uploadCertificate(identity, cal.getTime(), entry.getOlatResource(), certificateFile);
Assert.assertNotNull(certificate);
dbInstance.commitAndCloseSession();
// delete the course
Roles roles = new Roles(true, false, false, false, false, false, false);
repositoryService.deletePermanently(entry, identity, roles, Locale.ENGLISH);
dbInstance.commitAndCloseSession();
// retrieve the certificate
Certificate reloadedCertificate = certificatesManager.getCertificateById(certificate.getKey());
Assert.assertNotNull(reloadedCertificate);
Assert.assertEquals(certificate, reloadedCertificate);
Assert.assertNotNull(reloadedCertificate.getArchivedResourceKey());
Assert.assertEquals(resourceKey, reloadedCertificate.getArchivedResourceKey());
}
use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.
the class LectureBlockRollCallWebService method getRollCalls.
/**
* Return a list lecture block roll call.
*
* @response.representation.200.qname {http://www.example.com}lectureBlockRollCallVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A lecture block roll call
* @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_LECTUREBLOCKROLLCALLVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @param closed If true, the status of the block is done or the status of the roll call is closed or auto closed
* @param hasAbsence If true, the roll call has an absence
* @param hasSupervisorNotificationDate If true, the roll call has a supervisor notification date set
* @param httpRequest The HTTP request
* @return The roll calls
*/
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getRollCalls(@QueryParam("closed") Boolean closed, @QueryParam("hasAbsence") Boolean hasAbsence, @QueryParam("hasSupervisorNotificationDate") Boolean hasSupervisorNotificationDate, @QueryParam("lectureBlockKey") Long lectureBlockKey, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
LectureService lectureService = CoreSpringFactory.getImpl(LectureService.class);
LectureBlockRollCallSearchParameters searchParams = new LectureBlockRollCallSearchParameters();
if (hasAbsence != null) {
searchParams.setHasAbsence(hasAbsence);
}
if (hasSupervisorNotificationDate != null) {
searchParams.setHasSupervisorNotificationDate(hasSupervisorNotificationDate);
}
if (closed != null) {
searchParams.setClosed(closed);
}
if (lectureBlockKey != null) {
searchParams.setLectureBlockKey(lectureBlockKey);
}
List<LectureBlockRollCall> rollCalls = lectureService.getRollCalls(searchParams);
List<LectureBlockRollCallVO> voList = new ArrayList<>(rollCalls.size());
for (LectureBlockRollCall rollCall : rollCalls) {
voList.add(new LectureBlockRollCallVO(rollCall));
}
LectureBlockRollCallVO[] voes = voList.toArray(new LectureBlockRollCallVO[voList.size()]);
return Response.ok(voes).build();
}
use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.
the class LectureBlocksWebService method updateConfiguration.
/**
* Update the configuration of the lecture's feature of a specified
* course or repository entry.
* @response.representation.200.qname {http://www.example.com}repositoryEntryLectureConfigurationVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The updated configuration
* @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_REPOSITORYENTRYLECTURECONFIGURATIONVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param configuration The configuration
* @param request The HTTP request
* @return It returns the updated configuration.
*/
@POST
@Path("configuration")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateConfiguration(RepositoryEntryLectureConfigurationVO configuration, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
RepositoryEntryLectureConfiguration config = lectureService.getRepositoryEntryLectureConfiguration(entry);
if (configuration.getLectureEnabled() != null) {
config.setLectureEnabled(configuration.getLectureEnabled());
}
if (configuration.getCalculateAttendanceRate() != null) {
config.setCalculateAttendanceRate(configuration.getCalculateAttendanceRate());
}
if (configuration.getRequiredAttendanceRate() != null) {
config.setRequiredAttendanceRate(configuration.getRequiredAttendanceRate());
}
if (configuration.getOverrideModuleDefault() != null) {
config.setOverrideModuleDefault(configuration.getOverrideModuleDefault());
}
if (configuration.getCourseCalendarSyncEnabled() != null) {
config.setCourseCalendarSyncEnabled(configuration.getCourseCalendarSyncEnabled());
}
if (configuration.getRollCallEnabled() != null) {
config.setRollCallEnabled(configuration.getRollCallEnabled());
}
if (configuration.getTeacherCalendarSyncEnabled() != null) {
config.setTeacherCalendarSyncEnabled(configuration.getTeacherCalendarSyncEnabled());
}
RepositoryEntryLectureConfiguration updatedConfig = lectureService.updateRepositoryEntryLectureConfiguration(config);
return Response.ok(new RepositoryEntryLectureConfigurationVO(updatedConfig)).build();
}
use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.
the class LectureBlocksWebService method putLectureBlocks.
/**
* Create or update a lecture block.
* @response.representation.200.qname {http://www.example.com}lectureBlocksVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The updated configuration
* @response.representation.200.example {@link org.olat.modules.lecture.restapi.Examples#SAMPLE_LECTUREBLOCKVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course not found
* @param block The lecture block
* @param request The HTTP request
* @return It returns the updated / created lecture block.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response putLectureBlocks(LectureBlockVO block, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isOLATAdmin()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
LectureBlock updatedBlock = saveLectureBlock(block);
return Response.ok(new LectureBlockVO(updatedBlock, entry.getKey())).build();
}
Aggregations