-
Notifications
You must be signed in to change notification settings - Fork 2
DT-3056: Audit Library Card DAA Associations and Removals #2853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0000e08
7c83a6a
4f028e5
b19ecbc
1584b65
87862e9
ca24ece
4911289
36e7f88
9c1374a
d286944
654044d
757146d
ea2b29a
c6ad6ea
2ed3bdf
3f25b19
051bb48
4435e9a
70ec601
676413f
d63d5e1
b274109
7d7fe56
8123386
a4c2da3
4e77909
c593a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.broadinstitute.consent.http.db.mapper; | ||
|
|
||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import org.broadinstitute.consent.http.enumeration.AuditActions; | ||
| import org.broadinstitute.consent.http.models.LibraryCardDaaAudit; | ||
| import org.jdbi.v3.core.mapper.RowMapper; | ||
| import org.jdbi.v3.core.statement.StatementContext; | ||
|
|
||
| public class LibraryCardDaaAuditMapper implements RowMapper<LibraryCardDaaAudit>, RowMapperHelper { | ||
| @Override | ||
| public LibraryCardDaaAudit map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
| int lcId = hasColumn(rs, "lc_id") ? rs.getInt("lc_id") : 0; | ||
| return new LibraryCardDaaAudit( | ||
| rs.getLong("id"), | ||
| rs.getInt("daa_id"), | ||
| lcId > 0 ? lcId : null, | ||
| rs.getInt("lc_user_id"), | ||
| rs.getInt("user_id"), | ||
| AuditActions.valueOf(rs.getString("action").toUpperCase()), | ||
| rs.getTimestamp("action_date").toInstant()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package org.broadinstitute.consent.http.models; | ||
|
|
||
| import java.time.Instant; | ||
| import org.broadinstitute.consent.http.enumeration.AuditActions; | ||
|
|
||
| /** | ||
| * @param id The audit ID | ||
| * @param daaId The Data Access Agreement ID | ||
| * @param lcId The Library Card ID | ||
| * @param lcUserId The Library Card User ID (the user associated with the library card at the time | ||
| * of the audit action) | ||
| * @param userId The User ID who initiated the action | ||
| * @param action The action performed (e.g., ADD, REMOVE) | ||
| * @param actionDate The action date | ||
| */ | ||
| public record LibraryCardDaaAudit( | ||
| Long id, | ||
| Integer daaId, | ||
| Integer lcId, | ||
| Integer lcUserId, | ||
| Integer userId, | ||
| AuditActions action, | ||
| Instant actionDate) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,12 +126,15 @@ public Response createLibraryCardDaaRelation( | |
| user.getLibraryCard() == null | ||
| ? libraryCardService.createLibraryCardForSigningOfficial(user, authedUser) | ||
| : user.getLibraryCard(); | ||
| libraryCardService.addDaaToLibraryCard(libraryCard.getId(), daaId); | ||
| libraryCardService.addDaaToLibraryCard( | ||
| user.getUserId(), authedUser.getUserId(), libraryCard.getId(), daaId); | ||
| LibraryCard updatedLibraryCard = | ||
| libraryCardService.findLibraryCardWithDaasById(libraryCard.getId()); | ||
|
Comment on lines
+131
to
+132
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes a bug in the current implementation that returns the original, un-updated library card.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a side note, I want to update the service layer to return the updated LC. I will do that in a separate PR to keep this one as focused as possible. |
||
| URI uri = | ||
| info.getBaseUriBuilder() | ||
| .replacePath("api/libraryCards/{libraryCardId}") | ||
| .build(libraryCard.getId()); | ||
| return Response.ok().location(uri).entity(libraryCard).build(); | ||
| return Response.ok().location(uri).entity(updatedLibraryCard).build(); | ||
| } catch (Exception e) { | ||
| return createExceptionResponse(e); | ||
| } | ||
|
|
@@ -194,7 +197,8 @@ public Response deleteDaaForUser( | |
| return Response.status(Status.FORBIDDEN).build(); | ||
| } | ||
| if (user.getLibraryCard() != null) { | ||
| libraryCardService.removeDaaFromLibraryCard(user.getLibraryCard().getId(), daaId); | ||
| libraryCardService.removeDaaFromLibraryCard( | ||
| user.getUserId(), authedUser.getUserId(), user.getLibraryCard().getId(), daaId); | ||
| } | ||
| return Response.ok().build(); | ||
| } catch (Exception e) { | ||
|
|
@@ -242,7 +246,7 @@ public Response bulkRemoveUsersFromDaa( | |
| } | ||
| daaService.findById(daaId); | ||
| for (User user : users) { | ||
| libraryCardService.removeDaaFromUserLibraryCard(user, daaId); | ||
| libraryCardService.removeDaaFromUserLibraryCard(user, authedUser, daaId); | ||
| } | ||
| return Response.ok().build(); | ||
| } catch (Exception e) { | ||
|
|
@@ -286,7 +290,7 @@ public Response bulkRemoveDAAsFromUser( | |
| } | ||
| List<DataAccessAgreement> daaList = daaService.findDAAsInJsonArray(json, "daaList"); | ||
| for (DataAccessAgreement daa : daaList) { | ||
| libraryCardService.removeDaaFromUserLibraryCard(user, daa.getDaaId()); | ||
| libraryCardService.removeDaaFromUserLibraryCard(user, authedUser, daa.getDaaId()); | ||
| } | ||
| return Response.ok().build(); | ||
| } catch (Exception e) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.