Search in sources :

Example 41 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class CourseTest method getAuthors.

@Test
public void getAuthors() throws IOException, URISyntaxException {
    // make auth1 and auth2 authors
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    if (!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
        securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
    }
    if (!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
        securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
    }
    dbInstance.intermediateCommit();
    // make auth1 and auth2 owner
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
    List<Identity> authors = new ArrayList<Identity>();
    authors.add(auth1);
    authors.add(auth2);
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
    repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
    dbInstance.intermediateCommit();
    // get them
    assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    assertNotNull(body);
    List<UserVO> authorVOs = parseUserArray(body);
    assertNotNull(authorVOs);
}
Also used : UserVO(org.olat.user.restapi.UserVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 42 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class CourseTest method getParticipants.

@Test
public void getParticipants() throws IOException, URISyntaxException {
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("Course-participant");
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
    repositoryService.addRole(participant, repositoryEntry, GroupRoles.participant.name());
    dbInstance.intermediateCommit();
    // get them
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI uri = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/participants").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    Assert.assertNotNull(body);
    List<UserVO> participantVOs = parseUserArray(body);
    Assert.assertNotNull(participantVOs);
    boolean found = false;
    for (UserVO participantVo : participantVOs) {
        if (participantVo.getKey().equals(participant.getKey())) {
            found = true;
        }
    }
    Assert.assertTrue(found);
}
Also used : UserVO(org.olat.user.restapi.UserVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 43 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class CourseWebService method getTutors.

/**
 * Get all coaches of the course (don't follow the groups)
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The array of coaches
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param httpRequest The HTTP request
 * @return It returns an array of <code>UserVO</code>
 */
@GET
@Path("tutors")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTutors(@Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    List<Identity> coachList = repositoryService.getMembers(repositoryEntry, GroupRoles.coach.name());
    int count = 0;
    UserVO[] coaches = new UserVO[coachList.size()];
    for (Identity coach : coachList) {
        coaches[count++] = UserVOFactory.get(coach);
    }
    return Response.ok(coaches).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 44 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class CourseWebService method getParticipants.

/**
 * Get all participants of the course (don't follow the groups)
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The array of participants
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param httpRequest The HTTP request
 * @return It returns an array of <code>UserVO</code>
 */
@GET
@Path("participants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getParticipants(@Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    List<Identity> participantList = repositoryService.getMembers(repositoryEntry, GroupRoles.participant.name());
    int count = 0;
    UserVO[] participants = new UserVO[participantList.size()];
    for (Identity participant : participantList) {
        participants[count++] = UserVOFactory.get(participant);
    }
    return Response.ok(participants).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 45 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class CourseWebService method getAuthor.

/**
 * Get this specific author and owner of the course
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The author
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found or the user is not an onwer or author of the course
 * @param identityKey The user identifier
 * @param httpRequest The HTTP request
 * @return It returns an <code>UserVO</code>
 */
@GET
@Path("authors/{identityKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getAuthor(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    if (!isAuthorEditor(course, httpRequest) && !isInstitutionalResourceManager(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry repositoryEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
    Identity author = securityManager.loadIdentityByKey(identityKey, false);
    if (repositoryService.hasRole(author, repositoryEntry, GroupRoles.owner.name()) && securityManager.isIdentityInSecurityGroup(author, authorGroup)) {
        UserVO vo = UserVOFactory.get(author);
        return Response.ok(vo).build();
    }
    return Response.ok(author).build();
}
Also used : UserVO(org.olat.user.restapi.UserVO) RepositoryEntry(org.olat.repository.RepositoryEntry) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RepositoryService(org.olat.repository.RepositoryService) BaseSecurity(org.olat.basesecurity.BaseSecurity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UserVO (org.olat.user.restapi.UserVO)364 Test (org.junit.Test)332 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)260 UserRestClient (org.olat.test.rest.UserRestClient)258 LoginPage (org.olat.selenium.page.LoginPage)114 NavigationPage (org.olat.selenium.page.NavigationPage)110 CoursePageFragment (org.olat.selenium.page.course.CoursePageFragment)102 QTI21Page (org.olat.selenium.page.qti.QTI21Page)96 URL (java.net.URL)90 File (java.io.File)88 CourseEditorPageFragment (org.olat.selenium.page.course.CourseEditorPageFragment)84 URI (java.net.URI)72 HttpResponse (org.apache.http.HttpResponse)72 Identity (org.olat.core.id.Identity)72 UserToolsPage (org.olat.selenium.page.user.UserToolsPage)64 WebElement (org.openqa.selenium.WebElement)48 QTI21EditorPage (org.olat.selenium.page.qti.QTI21EditorPage)46 HttpGet (org.apache.http.client.methods.HttpGet)40 MembersPage (org.olat.selenium.page.course.MembersPage)36 AuthoringEnvPage (org.olat.selenium.page.repository.AuthoringEnvPage)34