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));
}
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));
}
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;
}
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());
}
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());
}
Aggregations