-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist role updates and add audit columns to ApiUserRole and ApiUser…
…Facility (#7828) * add audit columns and persist role updates * rework using constructors * comment formatting * assert exception on one method invocation * give ben demo user a valid role * use lombok getters and setters when possible * put back getter to add override annotation
- Loading branch information
Showing
8 changed files
with
328 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/gov/cdc/usds/simplereport/db/model/ApiUserFacility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gov.cdc.usds.simplereport.db.model; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.Getter; | ||
|
||
@Entity(name = "api_user_facility") | ||
public class ApiUserFacility extends AuditedEntity { | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "api_user_id", nullable = false) | ||
private ApiUser apiUser; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "facility_id", nullable = false) | ||
@Getter | ||
private Facility facility; | ||
|
||
protected ApiUserFacility() { | ||
/* for hibernate */ | ||
} | ||
|
||
public ApiUserFacility(ApiUser user, Facility facility) { | ||
this.apiUser = user; | ||
this.facility = facility; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
backend/src/main/java/gov/cdc/usds/simplereport/db/model/ApiUserRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gov.cdc.usds.simplereport.db.model; | ||
|
||
import gov.cdc.usds.simplereport.config.authorization.OrganizationRole; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import org.hibernate.annotations.JdbcTypeCode; | ||
import org.hibernate.type.SqlTypes; | ||
|
||
@Entity(name = "api_user_role") | ||
public class ApiUserRole extends AuditedEntity { | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "api_user_id", nullable = false) | ||
private ApiUser apiUser; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "organization_id", nullable = false) | ||
private Organization organization; | ||
|
||
@Column(nullable = false, columnDefinition = "organization_role") | ||
@JdbcTypeCode(SqlTypes.NAMED_ENUM) | ||
@Enumerated(EnumType.STRING) | ||
private OrganizationRole role; | ||
|
||
protected ApiUserRole() { | ||
/* for hibernate */ | ||
} | ||
|
||
public ApiUserRole(ApiUser user, Organization org, OrganizationRole role) { | ||
if (role.equals(OrganizationRole.NO_ACCESS)) { | ||
throw new IllegalArgumentException( | ||
"Invalid role NO_ACCESS when creating new user role assignment"); | ||
} | ||
this.apiUser = user; | ||
this.organization = org; | ||
this.role = role; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,7 @@ simple-report: | |
organization-external-id: DIS_ORG | ||
facilities: | ||
- Testing Site | ||
granted-roles: [] | ||
granted-roles: ENTRY_ONLY | ||
- identity: | ||
username: [email protected] | ||
first-name: Jamar | ||
|
Oops, something went wrong.