Skip to content

Commit 7bbb969

Browse files
lrosenstromolovy
andauthored
Allow S to create bulk changes of merge type (#1666)
--------- Co-authored-by: Olov Ylinenpää <[email protected]>
1 parent eb6e608 commit 7bbb969

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

rest/src/main/groovy/whelk/rest/security/AccessControl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import whelk.Document;
66
import whelk.JsonLd;
77
import whelk.datatool.bulkchange.BulkAccessControl;
8+
import whelk.datatool.bulkchange.BulkJobDocument;
89
import whelk.exception.ModelValidationException;
910
import whelk.util.LegacyIntegrationTools;
1011

@@ -13,6 +14,7 @@
1314
import java.util.Optional;
1415

1516
import static whelk.datatool.bulkchange.BulkJobDocument.JOB_TYPE;
17+
import static whelk.datatool.bulkchange.BulkJobDocument.SpecType.Merge;
1618

1719
public class AccessControl {
1820
private static final Logger log = LogManager.getLogger(AccessControl.class);
@@ -86,7 +88,13 @@ else if (document.getThingType().equals("ShelfMarkSequence")) {
8688
else if ((document.getThingType().equals(JOB_TYPE))) {
8789
// TODO step 1, new specific sigel instead
8890
// TODO step 2, configure as permission on user instead (in libris login)
89-
return hasPermissionForSigel("SEK", userPrivileges);
91+
92+
var bulkDoc = new BulkJobDocument(document);
93+
if (bulkDoc.getSpecificationType().equals(Merge)) {
94+
return hasPermissionForSigel("S", userPrivileges) || hasPermissionForSigel("SEK", userPrivileges);
95+
} else {
96+
return hasPermissionForSigel("SEK", userPrivileges);
97+
}
9098
}
9199
else if (document.isInReadOnlyDataset()) {
92100
return false;

whelktool/src/main/java/whelk/datatool/bulkchange/BulkJobDocument.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,16 @@ public void addExecution(ZonedDateTime endTime, Status status, List<String> repo
151151
_set(EXECUTION_PATH, executions, data);
152152
}
153153

154-
public Specification getSpecification() {
154+
public SpecType getSpecificationType() {
155155
Map<String, Object> spec = getSpecificationRaw();
156156
if (spec == null) {
157157
throw new ModelValidationException("Nothing in " + SPECIFICATION_PATH);
158158
}
159+
return fromKey(SpecType.class, get(spec, JsonLd.TYPE_KEY));
160+
}
159161

160-
String specType = get(spec, JsonLd.TYPE_KEY);
161-
return switch(fromKey(SpecType.class, specType)) {
162+
public Specification getSpecification() {
163+
return switch(getSpecificationType()) {
162164
case SpecType.Update -> new Specification.Update(
163165
get(spec, MATCH_FORM_KEY, Collections.emptyMap()),
164166
get(spec, TARGET_FORM_KEY, Collections.emptyMap())

0 commit comments

Comments
 (0)