Search in sources :

Example 1 with Roles

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;
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) UserSession(org.olat.core.util.UserSession) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 2 with Roles

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());
}
Also used : Calendar(java.util.Calendar) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) File(java.io.File) URL(java.net.URL) Certificate(org.olat.course.certificate.Certificate) Test(org.junit.Test)

Example 3 with Roles

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();
}
Also used : LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) LectureService(org.olat.modules.lecture.LectureService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Roles

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();
}
Also used : RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 5 with Roles

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();
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Roles (org.olat.core.id.Roles)338 Identity (org.olat.core.id.Identity)146 RepositoryEntry (org.olat.repository.RepositoryEntry)104 Test (org.junit.Test)94 GroupRoles (org.olat.basesecurity.GroupRoles)94 ArrayList (java.util.ArrayList)56 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)54 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)50 ICourse (org.olat.course.ICourse)44 Produces (javax.ws.rs.Produces)42 BusinessGroup (org.olat.group.BusinessGroup)38 Translator (org.olat.core.gui.translator.Translator)36 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)36 GET (javax.ws.rs.GET)34 Controller (org.olat.core.gui.control.Controller)34 TabbableController (org.olat.core.gui.control.generic.tabbable.TabbableController)34 NodeEditController (org.olat.course.editor.NodeEditController)34 Path (javax.ws.rs.Path)30 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)30 RepositoryManager (org.olat.repository.RepositoryManager)30