3535import gov .osti .entity .Site ;
3636import gov .osti .entity .SponsoringOrganization ;
3737import gov .osti .entity .User ;
38+ import gov .osti .entity .UserRole ;
39+ import gov .osti .entity .UserRole .RoleType ;
3840import gov .osti .indexer .AgentSerializer ;
3941import gov .osti .listeners .DoeServletContextListener ;
4042import java .io .File ;
@@ -304,7 +306,7 @@ public Response reserveDoi() throws IOException {
304306 * to succeeding.
305307 *
306308 * Ownership is defined as: owner and user email match, OR user's roles
307- * include the SITE OWNERSHIP CODE of the record, OR user has the "OSTI "
309+ * include the SITE OWNERSHIP CODE of the record, OR user has the "RecordAdmin "
308310 * special administrative role.
309311 * Result Codes:
310312 * 200 - OK, with JSON containing the metadata information
@@ -343,7 +345,7 @@ public Response getSingleRecord(@PathParam("codeId") Long codeId, @QueryParam("f
343345
344346 // do you have permissions to get this?
345347 if ( !user .getEmail ().equals (md .getOwner ()) &&
346- !user .hasRole ("OSTI " ) &&
348+ !user .hasRole ("RecordAdmin " ) &&
347349 !user .hasRole (md .getSiteOwnershipCode ()))
348350 return ErrorResponse
349351 .forbidden ("Permission denied." )
@@ -478,20 +480,22 @@ public Response listProjects(
478480
479481 try {
480482 Set <String > roles = user .getRoles ();
481- String rolecode = (null ==roles ) ? "" :
482- (roles .isEmpty ()) ? "" : roles .iterator ().next ();
483+
484+ List <String > allowedSites = UserRole .GetRoleList (RoleType .STANDARD );
485+ allowedSites .retainAll (roles );
483486
484487 TypedQuery <DOECodeMetadata > query ;
485488 // admins see ALL PROJECTS
486- if ("OSTI" . equals ( rolecode )) {
489+ if (roles . contains ( "RecordAdmin" )) {
487490 query = em .createQuery ("SELECT md FROM DOECodeMetadata md" , DOECodeMetadata .class );
488- } else if (StringUtils .isNotEmpty (rolecode )) {
489- // if you have another ROLE, it is assumed to be a SITE ADMIN; see all those records
490- query = em .createQuery ("SELECT md FROM DOECodeMetadata md WHERE md.siteOwnershipCode = :site" , DOECodeMetadata .class )
491- .setParameter ("site" , rolecode );
491+ } else if (!allowedSites .isEmpty ()) {
492+ // if you have any allowed site ROLE, it is assumed to be a SITE ADMIN; see all those records plus their own
493+ query = em .createQuery ("SELECT md FROM DOECodeMetadata md WHERE md.owner = :owner OR md.siteOwnershipCode IN :site" , DOECodeMetadata .class )
494+ .setParameter ("owner" , user .getEmail ())
495+ .setParameter ("site" , allowedSites );
492496 } else {
493497 // no roles, you see only YOUR OWN projects
494- query = em .createQuery ("SELECT md FROM DOECodeMetadata md WHERE md.owner = lower( :owner) " , DOECodeMetadata .class )
498+ query = em .createQuery ("SELECT md FROM DOECodeMetadata md WHERE md.owner = :owner" , DOECodeMetadata .class )
495499 .setParameter ("owner" , user .getEmail ());
496500 }
497501
@@ -597,7 +601,7 @@ public Response listProjects(
597601 @ Consumes (MediaType .APPLICATION_JSON )
598602 @ Produces (MediaType .APPLICATION_JSON )
599603 @ RequiresAuthentication
600- @ RequiresRoles ("OSTI " )
604+ @ RequiresRoles ("ApprovalAdmin " )
601605 public Response listProjectsPending (@ QueryParam ("start" ) int start ,
602606 @ QueryParam ("rows" ) int rows ,
603607 @ QueryParam ("site" ) String siteCode ,
@@ -765,7 +769,7 @@ private void store(EntityManager em, DOECodeMetadata md, User user) throws NotFo
765769
766770 // must be OSTI user in order to add/update PROJECT KEYWORDS
767771 List <String > projectKeywords = md .getProjectKeywords ();
768- if (projectKeywords != null && !projectKeywords .isEmpty () && !user .hasRole ("OSTI " ))
772+ if (projectKeywords != null && !projectKeywords .isEmpty () && !user .hasRole ("RecordAdmin " ))
769773 throw new ValidationException ("Project Keywords can only be set by authorized users." );
770774
771775 // if there's a CODE ID, attempt to look up the record first and
@@ -789,7 +793,7 @@ private void store(EntityManager em, DOECodeMetadata md, User user) throws NotFo
789793 // must be the OWNER, SITE ADMIN, or OSTI in order to UPDATE
790794 if (!user .getEmail ().equals (emd .getOwner ()) &&
791795 !user .hasRole (emd .getSiteOwnershipCode ()) &&
792- !user .hasRole ("OSTI " ))
796+ !user .hasRole ("RecordAdmin " ))
793797 throw new IllegalAccessException ("Invalid access attempt." );
794798
795799 // to Save, item must be non-existant, or already in Saved workflow status (if here, we know it exists)
@@ -1992,7 +1996,7 @@ public Response save(@FormDataParam("metadata") String metadata,
19921996 @ Produces (MediaType .APPLICATION_JSON )
19931997 @ Path ("/reindex" )
19941998 @ RequiresAuthentication
1995- @ RequiresRoles ("OSTI " )
1999+ @ RequiresRoles ("ContentAdmin " )
19962000 public Response reindex () throws IOException {
19972001 EntityManager em = DoeServletContextListener .createEntityManager ();
19982002
@@ -2022,7 +2026,7 @@ public Response reindex() throws IOException {
20222026 @ Produces (MediaType .APPLICATION_JSON )
20232027 @ Path ("/refresh" )
20242028 @ RequiresAuthentication
2025- @ RequiresRoles ("OSTI " )
2029+ @ RequiresRoles ("ContentAdmin " )
20262030 public Response refresh () throws Exception {
20272031 try {
20282032 DoeServletContextListener .refreshCaches ();
@@ -2054,7 +2058,7 @@ public Response refresh() throws Exception {
20542058 @ Path ("/approve/{codeId}" )
20552059 @ Produces (MediaType .APPLICATION_JSON )
20562060 @ RequiresAuthentication
2057- @ RequiresRoles ("OSTI " )
2061+ @ RequiresRoles ("ApprovalAdmin " )
20582062 public Response approve (@ PathParam ("codeId" ) Long codeId ) {
20592063 EntityManager em = DoeServletContextListener .createEntityManager ();
20602064 Subject subject = SecurityUtils .getSubject ();
0 commit comments