Search in sources :

Example 21 with IdentitiesAddEvent

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

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 22 with IdentitiesAddEvent

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

the class RepositoryEntriesTest method testRemoveParticipant.

@Test
public void testRemoveParticipant() throws IOException, URISyntaxException {
    Identity participant = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-4-" + UUID.randomUUID().toString());
    Roles partRoles = securityManager.getRoles(participant);
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addParticipants(participant, partRoles, new IdentitiesAddEvent(participant), re, null);
    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("participants").path(participant.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> participants = repositoryService.getMembers(re, GroupRoles.participant.name());
    Assert.assertNotNull(participants);
    Assert.assertTrue(participants.isEmpty());
    Assert.assertFalse(participants.contains(participant));
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) Roles(org.olat.core.id.Roles) GroupRoles(org.olat.basesecurity.GroupRoles) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 23 with IdentitiesAddEvent

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

the class RepositoryEntriesTest method getOwners.

@Test
public void getOwners() throws IOException, URISyntaxException {
    Identity owner1 = JunitTestHelper.createAndPersistIdentityAsAuthor("author-1-" + UUID.randomUUID().toString());
    Identity owner2 = JunitTestHelper.createAndPersistIdentityAsAuthor("author-2-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addOwners(owner1, new IdentitiesAddEvent(owner1), re, null);
    repositoryManager.addOwners(owner1, new IdentitiesAddEvent(owner2), re, null);
    dbInstance.commitAndCloseSession();
    // get the owners
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("owners").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<UserVO> users = parseUserArray(response.getEntity());
    Assert.assertNotNull(users);
    // our 2
    Assert.assertEquals(2, users.size());
    int found = 0;
    for (UserVO user : users) {
        String login = user.getLogin();
        Assert.assertNotNull(login);
        if (owner1.getName().equals(login) || owner2.getName().equals(login)) {
            found++;
        }
    }
    Assert.assertEquals(2, found);
    conn.shutdown();
}
Also used : UserVO(org.olat.user.restapi.UserVO) HttpGet(org.apache.http.client.methods.HttpGet) 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)

Example 24 with IdentitiesAddEvent

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

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 25 with IdentitiesAddEvent

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

the class RepositoryManager method acceptPendingParticipation.

public void acceptPendingParticipation(Identity ureqIdentity, Identity identityToAdd, OLATResource resource, ResourceReservation reservation) {
    RepositoryEntry re = lookupRepositoryEntry(resource, false);
    if (re != null) {
        if ("repo_participant".equals(reservation.getType())) {
            IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
            // roles is not needed as I add myself as participant
            addParticipants(ureqIdentity, null, iae, re, null);
        } else if ("repo_tutors".equals(reservation.getType())) {
            IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
            // roles is not needed as I add myself as tutor
            addTutors(ureqIdentity, null, iae, re, null);
        }
        reservationDao.deleteReservation(reservation);
    }
}
Also used : IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent)

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