Skip to content

Commit 2b682e6

Browse files
committed
UY-1571 update change entity dialog.
1 parent 6702b03 commit 2b682e6

5 files changed

Lines changed: 75 additions & 28 deletions

File tree

console/src/main/java/io/imunity/console/views/directory_browser/identities/ChangeEntityStateDialog.java

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44
*/
55
package io.imunity.console.views.directory_browser.identities;
66

7+
import java.time.Instant;
8+
import java.time.LocalDateTime;
9+
import java.time.ZoneId;
10+
import java.util.Date;
11+
import java.util.Locale;
12+
713
import com.vaadin.flow.component.checkbox.Checkbox;
814
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
915
import com.vaadin.flow.component.formlayout.FormLayout;
10-
import com.vaadin.flow.component.html.Span;
16+
import com.vaadin.flow.component.formlayout.FormLayout.FormItem;
1117
import com.vaadin.flow.component.select.Select;
18+
1219
import io.imunity.console.views.directory_browser.EntityWithLabel;
1320
import io.imunity.vaadin.elements.DialogWithActionFooter;
1421
import pl.edu.icm.unity.base.entity.EntityInformation;
1522
import pl.edu.icm.unity.base.entity.EntityScheduledOperation;
1623
import pl.edu.icm.unity.base.entity.EntityState;
1724
import pl.edu.icm.unity.base.message.MessageSource;
1825

19-
import java.time.Instant;
20-
import java.time.LocalDateTime;
21-
import java.time.ZoneId;
22-
import java.util.Date;
23-
import java.util.Locale;
24-
2526

2627
class ChangeEntityStateDialog extends DialogWithActionFooter
2728
{
@@ -35,8 +36,11 @@ class ChangeEntityStateDialog extends DialogWithActionFooter
3536
private Checkbox scheduleEnable;
3637
private Select<EntityScheduledOperation> entityScheduledChange;
3738
private DateTimePicker changeTime;
39+
private DateTimePicker removalTime;
3840
private FormLayout.FormItem changeTimeFormItem;
3941

42+
private FormItem removalFormItem;
43+
4044
ChangeEntityStateDialog(MessageSource msg, EntityWithLabel entity, Callback callback)
4145
{
4246
super(msg::getMessage);
@@ -58,6 +62,18 @@ private FormLayout getContents()
5862
entityState.setValue(entity.getEntity().getState());
5963
entityState.setWidthFull();
6064

65+
entityState.addValueChangeListener(event ->
66+
{
67+
EntityState newValue = event.getValue();
68+
if (newValue == EntityState.onlyLoginPermitted)
69+
{
70+
removalFormItem.setVisible(true);
71+
} else
72+
{
73+
removalFormItem.setVisible(false);
74+
}
75+
});
76+
6177
scheduleEnable = new Checkbox(msg.getMessage("ChangeEntityStateDialog.enableScheduled"));
6278

6379
EntityInformation initial = entity.getEntity().getEntityInformation();
@@ -67,10 +83,17 @@ private FormLayout getContents()
6783
entityScheduledChange.setItems(EntityScheduledOperation.values());
6884
entityScheduledChange.setItemLabelGenerator(item -> msg.getMessage("EntityScheduledOperation." + item));
6985
entityScheduledChange.setValue(initialOp);
86+
7087

7188
changeTime = new DateTimePicker();
7289
changeTime.setLocale(EUROPEAN_TIME_FORMAT);
7390
changeTime.setRequiredIndicatorVisible(true);
91+
92+
removalTime = new DateTimePicker();
93+
removalTime.setLocale(EUROPEAN_TIME_FORMAT);
94+
removalTime.setRequiredIndicatorVisible(true);
95+
96+
7497
if (initial.getScheduledOperation() != null)
7598
{
7699
scheduleEnable.setValue(true);
@@ -96,19 +119,24 @@ private FormLayout getContents()
96119
embedded.addFormItem(entityScheduledChange, msg.getMessage("ChangeEntityStateDialog.scheduledOperation"));
97120
changeTimeFormItem = embedded.addFormItem(changeTime,
98121
msg.getMessage("ChangeEntityStateDialog.scheduledChangeTime"));
99-
100-
if (entity.getEntity().getEntityInformation().getRemovalByUserTime() != null &&
101-
entity.getEntity().getEntityInformation().getState() == EntityState.onlyLoginPermitted)
102-
{
103-
Span infoRemovalByUser = new Span(msg.getMessage("ChangeEntityStateDialog.infoUserScheduledRemoval",
104-
entity.getEntity().getEntityInformation().getRemovalByUserTime()));
105-
main.add(infoRemovalByUser);
106-
}
107122

108123
main.addFormItem(entityState, msg.getMessage("ChangeEntityStateDialog.newState"));
124+
removalFormItem = main.addFormItem(removalTime, msg.getMessage("ChangeEntityStateDialog.removalTime"));
125+
removalFormItem.setVisible(false);
109126
main.addFormItem(scheduleEnable, "");
110127
main.addFormItem(embedded, "");
111128
main.setSizeFull();
129+
130+
131+
if (entity.getEntity().getEntityInformation().getRemovalByUserTime() != null &&
132+
entity.getEntity().getEntityInformation().getState() == EntityState.onlyLoginPermitted)
133+
{
134+
removalFormItem.setVisible(true);
135+
removalTime.setValue(LocalDateTime.ofInstant(entity.getEntity().getEntityInformation().getRemovalByUserTime()
136+
.toInstant(), ZoneId.systemDefault()));
137+
}
138+
139+
112140
return main;
113141
}
114142

@@ -121,6 +149,25 @@ private void onConfirm()
121149
changeTime.setErrorMessage(null);
122150
changeTime.setInvalid(false);
123151

152+
if (newState.equals(EntityState.onlyLoginPermitted))
153+
{
154+
LocalDateTime ldt = removalTime.getValue();
155+
if (ldt == null)
156+
{
157+
removalTime.setErrorMessage(msg.getMessage("fieldRequired"));
158+
removalTime.setInvalid(true);
159+
open();
160+
removalTime.getElement().setAttribute("invalid", true);
161+
return;
162+
}
163+
Date zonedDate = Date.from(ldt.atZone(ZoneId.systemDefault())
164+
.toInstant());
165+
newInfo.setRemovalByUserTime(zonedDate);
166+
} else
167+
{
168+
newInfo.setRemovalByUserTime(null);
169+
}
170+
124171
if (scheduleEnable.getValue())
125172
{
126173
if (changeTime.getValue() == null)

console/src/main/java/io/imunity/console/views/directory_browser/identities/ChangeEntityStateHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.imunity.vaadin.elements.grid.SingleActionHandler;
1616
import pl.edu.icm.unity.base.entity.EntityInformation;
1717
import pl.edu.icm.unity.base.entity.EntityParam;
18+
import pl.edu.icm.unity.base.entity.EntityState;
1819
import pl.edu.icm.unity.base.message.MessageSource;
1920
import pl.edu.icm.unity.engine.api.EntityManagement;
2021

@@ -57,7 +58,13 @@ private boolean setEntityStatus(long entityId, EntityInformation newState,
5758
try
5859
{
5960
EntityParam entity = new EntityParam(entityId);
60-
identitiesMan.setEntityStatus(entity, newState.getState());
61+
if (newState.getState().equals(EntityState.onlyLoginPermitted))
62+
{
63+
identitiesMan.scheduleRemovalByUser(entity, newState.getRemovalByUserTime());
64+
}else {
65+
identitiesMan.setEntityStatus(entity, newState.getState());
66+
}
67+
6168
identitiesMan.scheduleEntityChange(entity, newState.getScheduledOperationTime(),
6269
newState.getScheduledOperation());
6370
refreshCallback.run();

console/src/main/resources/messages/console/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ ChangeEntityStateDialog.newState=New status:
11041104
ChangeEntityStateDialog.enableScheduled=Schedule entity change in future
11051105
ChangeEntityStateDialog.scheduledOperation=Scheduled operation:
11061106
ChangeEntityStateDialog.scheduledChangeTime=Operation time:
1107+
ChangeEntityStateDialog.removalTime=Removal time:
11071108

11081109
EntityCreation.caption=New entity creation
11091110
EntityCreation.addToGroup=After creation add to group {0}

engine/src/main/java/pl/edu/icm/unity/engine/identity/EntityManagementImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ public void setEntityStatus(EntityParam toChange, EntityState status)
632632
throws EngineException
633633
{
634634
toChange.validateInitialization();
635+
if (status == EntityState.onlyLoginPermitted)
636+
throw new IllegalArgumentException("The new entity status 'only login permitted' "
637+
+ "can be only set as a side effect of scheduling an account "
638+
+ "removal with a grace period.");
635639
long entityId = idResolver.getEntityId(toChange);
636640
authz.checkAuthorization(authz.isSelf(entityId), AuthzCapability.identityModify);
637641
EntityInformation current = entityDAO.getByKey(entityId);

engine/src/test/java/pl/edu/icm/unity/engine/identity/TestIdentities.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,6 @@ public void disabledStatusIsReturned() throws Exception
421421
assertEquals(EntityState.disabled, entity.getState());
422422
}
423423

424-
@Test
425-
public void shouldSetOnlyLoginPermitedStatus() throws Exception
426-
{
427-
IdentityParam idParam = new IdentityParam(X500Identity.ID, "CN=golbi");
428-
Identity id = idsMan.addEntity(idParam, "crMock", EntityState.valid);
429-
430-
idsMan.setEntityStatus(new EntityParam(id), EntityState.onlyLoginPermitted);
431-
432-
Entity entity = idsMan.getEntity(new EntityParam(id));
433-
assertEquals(EntityState.onlyLoginPermitted, entity.getState());
434-
}
435-
436424
@Test
437425
public void shouldFailToAddToSubgoupWhenNotInParent() throws Exception
438426
{

0 commit comments

Comments
 (0)