Search in sources :

Example 11 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class SubscriptionResourceTest method deleteNotAdminGroup.

/**
 * Visible but not admin
 */
@Test
public void deleteNotAdminGroup() throws Exception {
    initSpringSecurityContext("fdaugan");
    delegateOrgRepository.findAll().stream().forEach(d -> d.setCanAdmin(false));
    projectRepository.findAll().stream().forEach(d -> d.setTeamLeader(null));
    // Persist the delegate and the related group to the project
    final DelegateOrg delegate = prepareDelegate();
    delegate.setCanWrite(true);
    em.flush();
    em.clear();
    Assertions.assertThrows(ForbiddenException.class, () -> resource.delete(subscription));
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Example 12 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class SubscriptionResourceTest method deleteNotWriteGroup.

/**
 * Visible but not write
 */
@Test
public void deleteNotWriteGroup() throws Exception {
    initSpringSecurityContext("fdaugan");
    delegateOrgRepository.findAll().stream().forEach(d -> d.setCanAdmin(false));
    projectRepository.findAll().stream().forEach(d -> d.setTeamLeader(null));
    // Persist the delegate and the related group to the project
    final DelegateOrg delegate = prepareDelegate();
    delegate.setCanAdmin(true);
    em.flush();
    em.clear();
    Assertions.assertThrows(ForbiddenException.class, () -> resource.delete(subscription));
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) Test(org.junit.jupiter.api.Test) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest)

Example 13 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class SubscriptionResourceTest method prepareDelegate.

private DelegateOrg prepareDelegate() {
    // Persist the delegate and the related group to the project
    final CacheProjectGroup projectGroup = new CacheProjectGroup();
    final CacheGroup group = new CacheGroup();
    group.setId("group-project");
    group.setName("group-project");
    group.setDescription("cn=group-project,ou=parent");
    em.persist(group);
    final CacheMembership membership = new CacheMembership();
    membership.setGroup(group);
    membership.setUser(em.find(CacheUser.class, "fdaugan"));
    em.persist(membership);
    projectGroup.setGroup(group);
    projectGroup.setProject(repository.findOne(subscription).getProject());
    em.persist(projectGroup);
    final DelegateOrg delegate = new DelegateOrg();
    delegate.setReceiver("fdaugan");
    delegate.setReceiverType(ReceiverType.USER);
    delegate.setReceiverDn("uid=fdaugan,ou=company");
    delegate.setType(DelegateType.GROUP);
    delegate.setName("group-project");
    delegate.setDn("cn=group-project,ou=parent");
    em.persist(delegate);
    em.flush();
    return delegate;
}
Also used : CacheProjectGroup(org.ligoj.app.model.CacheProjectGroup) CacheGroup(org.ligoj.app.iam.model.CacheGroup) DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) CacheMembership(org.ligoj.app.iam.model.CacheMembership) CacheUser(org.ligoj.app.iam.model.CacheUser)

Example 14 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResourceTest method updateType.

@Test
public void updateType() {
    initSpringSecurityContext("mtuyer");
    final int id = em.createQuery("SELECT id FROM DelegateOrg WHERE receiver=:user AND type=:type", Integer.class).setParameter("type", DelegateType.COMPANY).setParameter("user", "mtuyer").getSingleResult();
    final DelegateOrgEditionVo vo = new DelegateOrgEditionVo();
    vo.setId(id);
    vo.setName("cn=any,ou=fonction,ou=groups,dc=sample,dc=com");
    vo.setReceiver("mtuyer");
    vo.setType(DelegateType.TREE);
    vo.setCanAdmin(true);
    vo.setCanWrite(false);
    resource.update(vo);
    em.flush();
    em.clear();
    final DelegateOrg entity = repository.findOne(id);
    Assertions.assertEquals("-", entity.getName());
    Assertions.assertEquals("cn=any,ou=fonction,ou=groups,dc=sample,dc=com", entity.getDn());
    Assertions.assertEquals(DelegateType.TREE, entity.getType());
    Assertions.assertEquals("mtuyer", entity.getReceiver());
    Assertions.assertEquals(ReceiverType.USER, entity.getReceiverType());
    Assertions.assertTrue(entity.isCanAdmin());
    Assertions.assertFalse(entity.isCanWrite());
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Example 15 with DelegateOrg

use of org.ligoj.app.iam.model.DelegateOrg in project ligoj-api by ligoj.

the class DelegateOrgResourceTest method createOnGroup.

@Test
public void createOnGroup() {
    final DelegateOrgEditionVo vo = new DelegateOrgEditionVo();
    vo.setName("hUb Paris");
    vo.setType(DelegateType.GROUP);
    vo.setReceiver("fdaugan");
    final int id = resource.create(vo);
    em.flush();
    em.clear();
    final DelegateOrg entity = repository.findOneExpected(id);
    // Check the stored name is normalized
    Assertions.assertEquals("hub paris", entity.getName());
    Assertions.assertEquals("cn=hub paris,cn=hub france,cn=production,ou=branche,ou=groups,dc=sample,dc=com", entity.getDn());
    Assertions.assertNull(entity.getReceiverDn());
    Assertions.assertEquals(DelegateType.GROUP, entity.getType());
    Assertions.assertEquals(DEFAULT_USER, entity.getCreatedBy());
    Assertions.assertEquals("fdaugan", entity.getReceiver());
    Assertions.assertEquals(ReceiverType.USER, entity.getReceiverType());
    Assertions.assertFalse(entity.isCanAdmin());
    Assertions.assertFalse(entity.isCanWrite());
}
Also used : DelegateOrg(org.ligoj.app.iam.model.DelegateOrg) AbstractOrgTest(org.ligoj.app.resource.AbstractOrgTest) Test(org.junit.jupiter.api.Test)

Aggregations

DelegateOrg (org.ligoj.app.iam.model.DelegateOrg)19 Test (org.junit.jupiter.api.Test)13 AbstractOrgTest (org.ligoj.app.resource.AbstractOrgTest)13 ForbiddenException (javax.ws.rs.ForbiddenException)2 GET (javax.ws.rs.GET)1 UriInfo (javax.ws.rs.core.UriInfo)1 CompanyOrg (org.ligoj.app.iam.CompanyOrg)1 ContainerOrg (org.ligoj.app.iam.ContainerOrg)1 GroupOrg (org.ligoj.app.iam.GroupOrg)1 ResourceOrg (org.ligoj.app.iam.ResourceOrg)1 CacheGroup (org.ligoj.app.iam.model.CacheGroup)1 CacheMembership (org.ligoj.app.iam.model.CacheMembership)1 CacheUser (org.ligoj.app.iam.model.CacheUser)1 CacheProjectGroup (org.ligoj.app.model.CacheProjectGroup)1 PageRequest (org.springframework.data.domain.PageRequest)1