Skip to content

Commit 0a517c5

Browse files
committed
UY-1563 disabled entities are skiped in upman
1 parent b629400 commit 0a517c5

2 files changed

Lines changed: 57 additions & 10 deletions

File tree

engine/src/main/java/pl/edu/icm/unity/engine/project/DelegatedGroupManagementImpl.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pl.edu.icm.unity.base.attribute.Attribute;
2626
import pl.edu.icm.unity.base.entity.Entity;
2727
import pl.edu.icm.unity.base.entity.EntityParam;
28+
import pl.edu.icm.unity.base.entity.EntityState;
2829
import pl.edu.icm.unity.base.exceptions.EngineException;
2930
import pl.edu.icm.unity.base.exceptions.InternalException;
3031
import pl.edu.icm.unity.base.group.Group;
@@ -419,15 +420,18 @@ private List<DelegatedGroupMember> getDelegatedGroupMembersInternal(String proje
419420
List<String> projectAttrs = getProjectAttrs(projectPath);
420421
for (GroupMembership member : orgMembers)
421422
{
422-
long entity = member.getEntityId();
423+
Entity entity = getEntity(member.getEntityId());
424+
if (!entity.getEntityInformation().getState().equals(EntityState.valid))
425+
continue;
426+
Long entityId = entity.getId();
423427
VerifiableElementBase emailId = getEmailIdentity(entity);
424-
DelegatedGroupMember entry = new DelegatedGroupMember(member.getEntityId(), projectPath,
425-
member.getGroup(), getGroupAuthRoleAttr(entity, path),
426-
projectAttrHelper.getAttributeFromMeta(entity, "/",
428+
DelegatedGroupMember entry = new DelegatedGroupMember(entityId, projectPath,
429+
member.getGroup(), getGroupAuthRoleAttr(entityId, path),
430+
projectAttrHelper.getAttributeFromMeta(entityId, "/",
427431
EntityNameMetadataProvider.NAME),
428-
emailId != null ? emailId : projectAttrHelper.getVerifiableAttributeFromMeta(entity, "/",
432+
emailId != null ? emailId : projectAttrHelper.getVerifiableAttributeFromMeta(entityId, "/",
429433
ContactEmailMetadataProvider.NAME),
430-
Optional.ofNullable(getProjectMemberAttributes(entity, projectPath, projectAttrs)));
434+
Optional.ofNullable(getProjectMemberAttributes(entityId, projectPath, projectAttrs)));
431435
members.add(entry);
432436
}
433437
}
@@ -513,9 +517,13 @@ private void addToGroupRecursive(final Deque<String> notMember, long entity) thr
513517
addToGroupRecursive(notMember, entity);
514518
}
515519

516-
private VerifiableElementBase getEmailIdentity(long entityId) throws EngineException
520+
private Entity getEntity(long entityId) throws EngineException
521+
{
522+
return identitiesMan.getEntity(new EntityParam(entityId));
523+
}
524+
525+
private VerifiableElementBase getEmailIdentity(Entity entity) throws EngineException
517526
{
518-
Entity entity = identitiesMan.getEntity(new EntityParam(entityId));
519527
for (IdentityParam id : entity.getIdentities())
520528
{
521529
if (id != null && id.getTypeId().equals(EmailIdentity.ID))

engine/src/test/java/pl/edu/icm/unity/engine/project/TestDelegatedGroupManagement.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import pl.edu.icm.unity.base.attribute.AttributeExt;
3333
import pl.edu.icm.unity.base.attribute.AttributeType;
3434
import pl.edu.icm.unity.base.entity.Entity;
35+
import pl.edu.icm.unity.base.entity.EntityInformation;
3536
import pl.edu.icm.unity.base.entity.EntityParam;
37+
import pl.edu.icm.unity.base.entity.EntityState;
3638
import pl.edu.icm.unity.base.exceptions.EngineException;
3739
import pl.edu.icm.unity.base.group.Group;
3840
import pl.edu.icm.unity.base.group.GroupContents;
@@ -255,7 +257,7 @@ public void shouldGetGroupMembersWithExtraAttrs() throws EngineException
255257
.thenReturn(new Entity(
256258
Arrays.asList(new Identity(EmailIdentity.ID, "demo@demo.com", 1,
257259
new UsernameIdentity().getComparableValue("", "", ""))),
258-
null, null));
260+
new EntityInformation(1), null));
259261

260262
when(mockGroupMan.getContents(any(), anyInt())).thenReturn(con);
261263
when(mockGroupMan.getContents(any(), anyInt())).thenReturn(con);
@@ -289,6 +291,43 @@ public void shouldGetGroupMembersWithExtraAttrs() throws EngineException
289291
assertThat(firstMember.attributes.iterator().next().getValues().iterator().next()).isEqualTo("extraValue");
290292

291293
}
294+
295+
@Test
296+
public void shouldSkipDisabledEntity() throws EngineException
297+
{
298+
299+
GroupContents con = getConfiguredGroupContents("/project");
300+
GroupMembership member1 = new GroupMembership("/project", 1L, new Date());
301+
GroupMembership member2 = new GroupMembership("/project", 2L, new Date());
302+
303+
con.setMembers(List.of(member1, member2));
304+
con.getGroup().setDelegationConfiguration(new GroupDelegationConfiguration(true, false, null, null, null, null,
305+
Arrays.asList("extraAttr"), List.of()));
306+
307+
EntityInformation disabledEntityInfo = new EntityInformation(1);
308+
disabledEntityInfo.setState(EntityState.disabled);
309+
310+
when(mockIdMan.getEntity(new EntityParam(1L)))
311+
.thenReturn(new Entity(
312+
Arrays.asList(new Identity(EmailIdentity.ID, "demo@demo.com", 1,
313+
new UsernameIdentity().getComparableValue("", "", ""))),
314+
disabledEntityInfo, null));
315+
316+
when(mockIdMan.getEntity(new EntityParam(2L)))
317+
.thenReturn(new Entity(
318+
Arrays.asList(new Identity(EmailIdentity.ID, "demo2@demo.com", 2,
319+
new UsernameIdentity().getComparableValue("", "", ""))),
320+
new EntityInformation(2L), null));
321+
322+
when(mockGroupMan.getContents(any(), anyInt())).thenReturn(con);
323+
when(mockGroupMan.getContents(any(), anyInt())).thenReturn(con);
324+
325+
List<DelegatedGroupMember> delegatedGroupMemebers = dGroupManNoAuthz.getDelegatedGroupMembers("/project",
326+
"/project");
327+
328+
assertThat(delegatedGroupMemebers.size()).isEqualTo(1);
329+
assertThat(delegatedGroupMemebers.iterator().next().entityId).isEqualTo(2L);
330+
}
292331

293332
@Test
294333
public void shouldForbidGetDisplayNameOfNonProjectAttribute() throws EngineException
@@ -363,7 +402,7 @@ public void shouldForbidRemoveLastManagerInProjectGroup() throws EngineException
363402
.thenReturn(new Entity(
364403
Arrays.asList(new Identity(UsernameIdentity.ID, "xx", 1,
365404
new UsernameIdentity().getComparableValue("", "", ""))),
366-
null, null));
405+
new EntityInformation(1), null));
367406

368407
when(mockGroupMan.getContents(eq("/project"), anyInt()))
369408
.thenReturn(getEnabledGroupContentsWithDefaultMember("/project"));

0 commit comments

Comments
 (0)