Search in sources :

Example 51 with IdentitiesAddEvent

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

the class RepositoryEntriesTest method getParticipants.

@Test
public void getParticipants() throws IOException, URISyntaxException {
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-1-" + UUID.randomUUID().toString());
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsAuthor("participant-2-" + UUID.randomUUID().toString());
    Roles part1Roles = securityManager.getRoles(participant1);
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addParticipants(participant1, part1Roles, new IdentitiesAddEvent(participant1), re, null);
    repositoryManager.addParticipants(participant1, part1Roles, new IdentitiesAddEvent(participant2), re, null);
    dbInstance.commitAndCloseSession();
    // get the coaches
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("participants").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 (participant1.getName().equals(login) || participant2.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) 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 52 with IdentitiesAddEvent

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

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)

Example 53 with IdentitiesAddEvent

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

the class RepositoryEntriesTest method removeCoach.

@Test
public void removeCoach() throws IOException, URISyntaxException {
    Identity coach = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-4-" + UUID.randomUUID());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addTutors(coach, ADMIN_ROLES, new IdentitiesAddEvent(coach), 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("coaches").path(coach.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> coaches = repositoryService.getMembers(re, GroupRoles.coach.name());
    Assert.assertNotNull(coaches);
    Assert.assertTrue(coaches.isEmpty());
    Assert.assertFalse(coaches.contains(coach));
}
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)

Example 54 with IdentitiesAddEvent

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

the class RepositoryEntriesTest method getCoaches.

@Test
public void getCoaches() throws IOException, URISyntaxException {
    Identity coach1 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-1-" + UUID.randomUUID().toString());
    Identity coach2 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-2-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach1), re, new MailPackage(false));
    repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach2), re, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // get the coaches
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("coaches").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 (coach1.getName().equals(login) || coach2.getName().equals(login)) {
            found++;
        }
    }
    Assert.assertEquals(2, found);
    conn.shutdown();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) 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 55 with IdentitiesAddEvent

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

the class RepositoryManager method updateRepositoryEntryMembership.

private void updateRepositoryEntryMembership(Identity ureqIdentity, Roles ureqRoles, RepositoryEntry re, RepositoryEntryPermissionChangeEvent changes, MailPackage mailing, List<RepositoryEntryMembershipModifiedEvent> deferredEvents) {
    if (changes.getRepoOwner() != null) {
        if (changes.getRepoOwner().booleanValue()) {
            addOwners(ureqIdentity, new IdentitiesAddEvent(changes.getMember()), re, mailing);
        } else {
            removeOwner(ureqIdentity, changes.getMember(), re, mailing);
            deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
        }
    }
    if (changes.getRepoTutor() != null) {
        if (changes.getRepoTutor().booleanValue()) {
            addTutors(ureqIdentity, ureqRoles, new IdentitiesAddEvent(changes.getMember()), re, mailing);
        } else {
            removeTutor(ureqIdentity, changes.getMember(), re, mailing);
            deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
        }
    }
    if (changes.getRepoParticipant() != null) {
        if (changes.getRepoParticipant().booleanValue()) {
            addParticipants(ureqIdentity, ureqRoles, new IdentitiesAddEvent(changes.getMember()), re, mailing);
        } else {
            removeParticipant(ureqIdentity, changes.getMember(), re, mailing, true);
            deferredEvents.add(RepositoryEntryMembershipModifiedEvent.removed(changes.getMember(), re));
        }
    }
}
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