Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit f1e130c

Browse files
author
sowerstl
committed
Approval role should work as standalone permission; (DOECODE-808)
1 parent 678ad07 commit f1e130c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/main/java/gov/osti/services/Metadata.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ public Response getSingleRecord(@PathParam("codeId") Long codeId, @QueryParam("f
346346
// do you have permissions to get this?
347347
if ( !user.getEmail().equals(md.getOwner()) &&
348348
!user.hasRole("RecordAdmin") &&
349+
!user.hasRole("ApprovalAdmin") &&
349350
!user.hasRole(md.getSiteOwnershipCode()))
350351
return ErrorResponse
351352
.forbidden("Permission denied.")
@@ -771,9 +772,9 @@ private void store(EntityManager em, DOECodeMetadata md, User user) throws NotFo
771772
ValidatorFactory validators = javax.validation.Validation.buildDefaultValidatorFactory();
772773
Validator validator = validators.getValidator();
773774

774-
// must be OSTI user in order to add/update PROJECT KEYWORDS
775+
// must be RecordAdmin user in order to add/update PROJECT KEYWORDS
775776
List<String> projectKeywords = md.getProjectKeywords();
776-
if (projectKeywords != null && !projectKeywords.isEmpty() && !user.hasRole("RecordAdmin"))
777+
if (projectKeywords != null && !projectKeywords.isEmpty() && !user.hasRole("RecordAdmin") && !user.hasRole("ApprovalAdmin"))
777778
throw new ValidationException("Project Keywords can only be set by authorized users.");
778779

779780
// if there's a CODE ID, attempt to look up the record first and
@@ -794,10 +795,17 @@ private void store(EntityManager em, DOECodeMetadata md, User user) throws NotFo
794795
DOECodeMetadata emd = em.find(DOECodeMetadata.class, md.getCodeId());
795796

796797
if ( null!=emd ) {
797-
// must be the OWNER, SITE ADMIN, or OSTI in order to UPDATE
798-
if (!user.getEmail().equals(emd.getOwner()) &&
799-
!user.hasRole(emd.getSiteOwnershipCode()) &&
800-
!user.hasRole("RecordAdmin"))
798+
// to Approve, user must be an ApprovalAdmin and record must be previously Submitted/Announced
799+
if (DOECodeMetadata.Status.Approved.equals(md.getWorkflowStatus())) {
800+
if (!(user.hasRole("ApprovalAdmin")
801+
&& (DOECodeMetadata.Status.Submitted.equals(emd.getWorkflowStatus())
802+
|| DOECodeMetadata.Status.Announced.equals(emd.getWorkflowStatus()))))
803+
throw new IllegalAccessException("Invalid approval attempt.");
804+
}
805+
// otherwise, must be the OWNER, SITE ADMIN, or RecordAdmin in order to UPDATE
806+
else if (!user.getEmail().equals(emd.getOwner())
807+
&& !user.hasRole(emd.getSiteOwnershipCode())
808+
&& !user.hasRole("RecordAdmin"))
801809
throw new IllegalAccessException("Invalid access attempt.");
802810

803811
// to Save, item must be non-existant, or already in Saved workflow status (if here, we know it exists)
@@ -2075,6 +2083,7 @@ public Response approve(@PathParam("codeId") Long codeId) {
20752083

20762084
try {
20772085
DOECodeMetadata md = em.find(DOECodeMetadata.class, codeId);
2086+
em.detach(md);
20782087

20792088
if ( null==md )
20802089
return ErrorResponse

0 commit comments

Comments
 (0)