Search in sources :

Example 11 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method addOwners.

@PUT
@Path("owners")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addOwners(UserVO[] owners, @PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
    try {
        RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
        if (repoEntry == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        } else if (!isAuthorEditor(repoEntry, request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        List<Identity> identityToAdd = loadIdentities(owners);
        UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
        repositoryManager.addOwners(ureq.getIdentity(), iae, repoEntry, new MailPackage(false));
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to add an owner to a repository entry", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 12 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method addOwner.

/**
 * Adds an owner to the repository entry.
 * @response.representation.200.doc The user is added as owner of the repository entry
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The repository entry or the user cannot be found
 * @param repoEntryKey The key of the repository entry
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@PUT
@Path("owners/{identityKey}")
public Response addOwner(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
        if (repoEntry == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        } else if (!isAuthorEditor(repoEntry, request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        Identity identityToAdd = securityManager.loadIdentityByKey(identityKey);
        if (identityToAdd == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
        repositoryManager.addOwners(ureq.getIdentity(), iae, repoEntry, new MailPackage(false));
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to add an owner to a repository entry", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 13 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class RepositoryEntryResource method addCoach.

/**
 * Adds a coach to the repository entry.
 * @response.representation.200.doc The user is added as coach of the repository entry
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The repository entry or the user cannot be found
 * @param repoEntryKey The key of the repository entry
 * @param identityKey The user's id
 * @param request The HTTP request
 * @return
 */
@PUT
@Path("coaches/{identityKey}")
public Response addCoach(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    try {
        RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
        if (repoEntry == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        } else if (!isAuthorEditor(repoEntry, request)) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        Identity identityToAdd = securityManager.loadIdentityByKey(identityKey);
        if (identityToAdd == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        UserRequest ureq = RestSecurityHelper.getUserRequest(request);
        IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
        repositoryManager.addTutors(ureq.getIdentity(), ureq.getUserSession().getRoles(), iae, repoEntry, null);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Trying to add a coach to a repository entry", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 14 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class PoolsAdminController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == poolEditCtrl) {
        if (event == Event.DONE_EVENT) {
            reloadModel();
            fireEvent(ureq, new QPoolEvent(QPoolEvent.POOL_CREATED));
        }
        cmc.deactivate();
        cleanUp();
    } else if (source == groupCtrl) {
        Pool selectedPool = (Pool) groupCtrl.getUserObject();
        if (event instanceof IdentitiesAddEvent) {
            IdentitiesAddEvent identitiesAddedEvent = (IdentitiesAddEvent) event;
            List<Identity> list = identitiesAddedEvent.getAddIdentities();
            qpoolService.addOwners(list, Collections.singletonList(selectedPool));
            identitiesAddedEvent.getAddedIdentities().addAll(list);
        } else if (event instanceof IdentitiesRemoveEvent) {
            IdentitiesRemoveEvent identitiesRemoveEvent = (IdentitiesRemoveEvent) event;
            List<Identity> list = identitiesRemoveEvent.getRemovedIdentities();
            qpoolService.removeOwners(list, Collections.singletonList(selectedPool));
        }
    } else if (source == confirmDeleteCtrl) {
        if (DialogBoxUIFactory.isOkEvent(event) || DialogBoxUIFactory.isYesEvent(event)) {
            Pool pool = (Pool) confirmDeleteCtrl.getUserObject();
            doDelete(ureq, pool);
        }
    } else if (source == cmc) {
        cleanUp();
    }
}
Also used : IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) QPoolEvent(org.olat.modules.qpool.ui.events.QPoolEvent) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) Pool(org.olat.modules.qpool.Pool) List(java.util.List) Identity(org.olat.core.id.Identity)

Example 15 with IdentitiesAddEvent

use of org.olat.admin.securitygroup.gui.IdentitiesAddEvent in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesTest method removeOwner.

@Test
public void removeOwner() throws IOException, URISyntaxException {
    Identity owner = JunitTestHelper.createAndPersistIdentityAsAuthor("author-4-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addOwners(owner, new IdentitiesAddEvent(owner), re, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // remove the owner
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("owners").path(owner.getKey().toString()).build();
    HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
    // check
    List<Identity> owners = repositoryService.getMembers(re, GroupRoles.owner.name());
    Assert.assertNotNull(owners);
    Assert.assertEquals(0, owners.size());
    Assert.assertFalse(owners.contains(owner));
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) HttpDelete(org.apache.http.client.methods.HttpDelete) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Aggregations

IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)64 Identity (org.olat.core.id.Identity)50 RepositoryEntry (org.olat.repository.RepositoryEntry)44 PUT (javax.ws.rs.PUT)24 Path (javax.ws.rs.Path)24 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)24 MailPackage (org.olat.core.util.mail.MailPackage)22 UserRequest (org.olat.core.gui.UserRequest)20 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)20 URI (java.net.URI)16 HttpResponse (org.apache.http.HttpResponse)16 Test (org.junit.Test)16 IdentitiesRemoveEvent (org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent)16 Consumes (javax.ws.rs.Consumes)12 RepositoryManager (org.olat.repository.RepositoryManager)12 ArrayList (java.util.ArrayList)8 HttpDelete (org.apache.http.client.methods.HttpDelete)8 HttpGet (org.apache.http.client.methods.HttpGet)8 BaseSecurity (org.olat.basesecurity.BaseSecurity)8 SecurityGroup (org.olat.basesecurity.SecurityGroup)8