Skip to content

Commit 1c31287

Browse files
committed
improved security ACLs grid
1 parent b7b9142 commit 1c31287

File tree

9 files changed

+163
-109
lines changed

9 files changed

+163
-109
lines changed

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/beans/GUIAutomationRoutine.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ public void setAutomation(String automation) {
5050
this.automation = automation;
5151
}
5252

53+
public GUIAccessControlEntry getAce(long entityId) {
54+
for (GUIAccessControlEntry ace : accessControlList) {
55+
if (ace.getEntityId() == entityId)
56+
return ace;
57+
}
58+
return null;
59+
}
60+
61+
public void removeAce(long entityId) {
62+
List<GUIAccessControlEntry> newAcls = new ArrayList<>();
63+
for (GUIAccessControlEntry ace : accessControlList) {
64+
if (ace.getEntityId() != entityId)
65+
newAcls.add(ace);
66+
}
67+
accessControlList = newAcls;
68+
}
69+
70+
public void addAce(GUIAccessControlEntry ace) {
71+
GUIAccessControlEntry existingAce = getAce(ace.getEntityId());
72+
if(existingAce==null) {
73+
accessControlList.add(ace);
74+
} else {
75+
existingAce.setRead(ace.isRead());
76+
existingAce.setWrite(ace.isWrite());
77+
}
78+
}
79+
5380
public List<GUIAccessControlEntry> getAccessControlList() {
5481
return accessControlList;
5582
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/beans/GUIStamp.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,33 @@ public void setColor(String color) {
176176
this.color = color;
177177
}
178178

179+
public GUIAccessControlEntry getAce(long entityId) {
180+
for (GUIAccessControlEntry ace : accessControlList) {
181+
if (ace.getEntityId() == entityId)
182+
return ace;
183+
}
184+
return null;
185+
}
186+
187+
public void removeAce(long entityId) {
188+
List<GUIAccessControlEntry> newAcls = new ArrayList<>();
189+
for (GUIAccessControlEntry ace : accessControlList) {
190+
if (ace.getEntityId() != entityId)
191+
newAcls.add(ace);
192+
}
193+
accessControlList = newAcls;
194+
}
195+
196+
public void addAce(GUIAccessControlEntry ace) {
197+
GUIAccessControlEntry existingAce = getAce(ace.getEntityId());
198+
if(existingAce==null) {
199+
accessControlList.add(ace);
200+
} else {
201+
existingAce.setRead(ace.isRead());
202+
existingAce.setWrite(ace.isWrite());
203+
}
204+
}
205+
179206
public List<GUIAccessControlEntry> getAccessControlList() {
180207
return accessControlList;
181208
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/beans/GUITemplate.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public GUIAttribute getAttribute(String name) {
7070
}
7171

7272
public void appendAttribute(GUIAttribute attribute) {
73-
int maxPosition=attributes.stream().mapToInt(a->a.getPosition()).max().orElse(0);
73+
int maxPosition = attributes.stream().mapToInt(a -> a.getPosition()).max().orElse(0);
7474
attribute.setPosition(++maxPosition);
7575
attributes.add(attribute);
7676
}
@@ -135,6 +135,33 @@ public void setPermissions(List<String> permissions) {
135135
this.permissions = permissions;
136136
}
137137

138+
public GUIAccessControlEntry getAce(long entityId) {
139+
for (GUIAccessControlEntry acl : accessControlList) {
140+
if (acl.getEntityId() == entityId)
141+
return acl;
142+
}
143+
return null;
144+
}
145+
146+
public void removeAce(long entityId) {
147+
List<GUIAccessControlEntry> newAce = new ArrayList<>();
148+
for (GUIAccessControlEntry ace : accessControlList) {
149+
if (ace.getEntityId() != entityId)
150+
newAce.add(ace);
151+
}
152+
accessControlList = newAce;
153+
}
154+
155+
public void addAce(GUIAccessControlEntry ace) {
156+
GUIAccessControlEntry existingAce = getAce(ace.getEntityId());
157+
if(existingAce==null) {
158+
accessControlList.add(ace);
159+
} else {
160+
existingAce.setRead(ace.isRead());
161+
existingAce.setWrite(ace.isWrite());
162+
}
163+
}
164+
138165
public List<GUIAccessControlEntry> getAccessControlList() {
139166
return accessControlList;
140167
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/stamp/StampDetailsPanel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ private boolean validate() {
143143
boolean paramsValid = parametersPanel.validate();
144144
if (!propsValid)
145145
tabSet.selectTab(1);
146-
boolean securityValid = securityPanel.validate();
147-
if (!securityValid)
148-
tabSet.selectTab(2);
149-
return propsValid && paramsValid && securityValid;
146+
return propsValid && paramsValid;
150147
}
151148

152149
public void onSave() {

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/stamp/StampSecurity.java

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.logicaldoc.gui.frontend.client.metadata.stamp;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
import com.logicaldoc.gui.common.client.beans.GUIAccessControlEntry;
74
import com.logicaldoc.gui.common.client.beans.GUIStamp;
85
import com.logicaldoc.gui.common.client.data.StampAclDS;
@@ -11,7 +8,6 @@
118
import com.logicaldoc.gui.common.client.util.ItemFactory;
129
import com.logicaldoc.gui.common.client.util.LD;
1310
import com.logicaldoc.gui.common.client.widgets.grid.UserListGridField;
14-
import com.smartgwt.client.data.Record;
1511
import com.smartgwt.client.types.ListGridFieldType;
1612
import com.smartgwt.client.types.SelectionStyle;
1713
import com.smartgwt.client.widgets.Button;
@@ -45,8 +41,6 @@ public class StampSecurity extends StampDetailsTab {
4541

4642
private ListGrid list;
4743

48-
private boolean aclInitialized = false;
49-
5044
public StampSecurity(GUIStamp stamp, ChangedHandler changedHandler) {
5145
super(stamp, changedHandler);
5246
setWidth100();
@@ -92,7 +86,16 @@ void refresh() {
9286
setupContextMenu().showContextMenu();
9387
event.cancel();
9488
});
95-
list.addEditCompleteHandler(event -> changedHandler.onChanged(null));
89+
list.addEditCompleteHandler(event -> {
90+
for (ListGridRecord rec : list.getSelectedRecords()) {
91+
GUIAccessControlEntry acl = stamp.getAce(rec.getAttributeAsLong(ENTITY_ID));
92+
if (acl != null) {
93+
acl.setWrite(rec.getAttributeAsBoolean(WRITE, false));
94+
acl.setRead(rec.getAttributeAsBoolean(READ, false));
95+
}
96+
}
97+
changedHandler.onChanged(null);
98+
});
9699
}
97100

98101
VLayout container = new VLayout();
@@ -134,8 +137,9 @@ private HLayout prepareButons() {
134137
rec.setAttribute(AVATAR, "group");
135138
rec.setAttribute(ENTITY, selectedRecord.getAttribute("name"));
136139
rec.setAttribute(READ, true);
137-
list.addData(rec);
138-
changedHandler.onChanged(null);
140+
141+
addRecord(rec);
142+
139143
group.clearValue();
140144
});
141145

@@ -167,8 +171,8 @@ private HLayout prepareButons() {
167171
selectedRecord.getAttribute("label") + " (" + selectedRecord.getAttribute("username") + ")");
168172
rec.setAttribute(READ, true);
169173

170-
list.addData(rec);
171-
changedHandler.onChanged(null);
174+
addRecord(rec);
175+
172176
user.clearValue();
173177
});
174178
if (stamp.isWrite())
@@ -187,6 +191,18 @@ private HLayout prepareButons() {
187191
return buttons;
188192
}
189193

194+
private void addRecord(ListGridRecord rec) {
195+
list.addData(rec);
196+
197+
GUIAccessControlEntry ace = new GUIAccessControlEntry();
198+
ace.setEntityId(rec.getAttributeAsLong(ENTITY_ID));
199+
ace.setRead(rec.getAttributeAsBoolean(READ, false));
200+
ace.setWrite(rec.getAttributeAsBoolean(WRITE, false));
201+
stamp.addAce(ace);
202+
203+
changedHandler.onChanged(null);
204+
}
205+
190206
private void prepareList() {
191207
list = new ListGrid();
192208
list.setEmptyMessage(I18N.message("notitemstoshow"));
@@ -198,29 +214,6 @@ private void prepareList() {
198214
list.setMinHeight(200);
199215
list.setMinWidth(300);
200216
list.setDataSource(new StampAclDS(stamp.getId()));
201-
list.addDataArrivedHandler(event -> aclInitialized = true);
202-
}
203-
204-
/**
205-
* Creates an array of all the right
206-
*
207-
* @return the array of rights
208-
*/
209-
private List<GUIAccessControlEntry> getACL() {
210-
int totalRecords = list.getRecordList().getLength();
211-
List<GUIAccessControlEntry> acl = new ArrayList<>();
212-
213-
for (int i = 0; i < totalRecords; i++) {
214-
Record rec = list.getRecordList().get(i);
215-
GUIAccessControlEntry ace = new GUIAccessControlEntry();
216-
ace.setName(rec.getAttributeAsString(ENTITY));
217-
ace.setEntityId(rec.getAttributeAsLong(ENTITY_ID));
218-
ace.setWrite(rec.getAttributeAsBoolean(WRITE));
219-
ace.setRead(rec.getAttributeAsBoolean(READ));
220-
acl.add(ace);
221-
}
222-
223-
return acl;
224217
}
225218

226219
/**
@@ -246,23 +239,14 @@ private void onDelete() {
246239

247240
LD.ask(I18N.message("question"), I18N.message("confirmdelete"), value -> {
248241
if (Boolean.TRUE.equals(value)) {
242+
for (ListGridRecord listGridRecord : selection)
243+
stamp.removeAce(listGridRecord.getAttributeAsLong(ENTITY_ID));
249244
list.removeSelectedData();
250245
changedHandler.onChanged(null);
251246
}
252247
});
253248
}
254249

255-
protected boolean validate() {
256-
if (aclInitialized)
257-
try {
258-
if (stamp.isWrite())
259-
stamp.setAccessControlList(getACL());
260-
} catch (Exception t) {
261-
// Nothing to do
262-
}
263-
return true;
264-
}
265-
266250
@Override
267251
public boolean equals(Object obj) {
268252
if (obj instanceof StampSecurity)

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/template/TemplateDetailsPanel.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ protected boolean validate() {
175175
stdValid = validationPanel.validate();
176176
if (!stdValid)
177177
tabSet.selectTab(1);
178-
stdValid = securityPanel.validate();
179-
if (!stdValid)
180-
tabSet.selectTab(2);
181178
return stdValid;
182179
}
183180

0 commit comments

Comments
 (0)