-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch group info for users from DB when oktaMigrationEnabled is true (#…
…8105) * Fetch group info for users from DB when oktaMigrationEnabled is true * Address PR comments * Lint backend * Address PR comments
- Loading branch information
Showing
16 changed files
with
577 additions
and
57 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
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
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
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/gov/cdc/usds/simplereport/service/DbAuthorizationService.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,60 @@ | ||
package gov.cdc.usds.simplereport.service; | ||
|
||
import gov.cdc.usds.simplereport.config.AuthorizationConfiguration; | ||
import gov.cdc.usds.simplereport.config.authorization.OrganizationRole; | ||
import gov.cdc.usds.simplereport.db.model.ApiUser; | ||
import gov.cdc.usds.simplereport.db.model.Facility; | ||
import gov.cdc.usds.simplereport.db.model.Organization; | ||
import gov.cdc.usds.simplereport.db.repository.ApiUserRepository; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class DbAuthorizationService { | ||
private final ApiUserRepository _userRepo; | ||
|
||
/** | ||
* Fetches a list of ApiUsers that belong to an Organization sorted by last name, first name, and | ||
* middle name | ||
* | ||
* @param org - Organization | ||
* @return List of ApiUsers that belong to the org | ||
*/ | ||
@AuthorizationConfiguration.RequirePermissionManageUsers | ||
public List<ApiUser> getUsersInOrganization(Organization org) { | ||
return _userRepo.findAllByOrganization(org); | ||
} | ||
|
||
/** | ||
* Fetches a list of ApiUsers that belong to an Organization and has the ADMIN role, sorted by | ||
* last name, first name, and middle name | ||
* | ||
* @param org - Organization | ||
* @return List of ApiUsers with ADMIN role in the org | ||
*/ | ||
public List<ApiUser> getOrgAdminUsers(Organization org) { | ||
return _userRepo.findAllByOrganizationAndRole(org, OrganizationRole.ADMIN); | ||
} | ||
|
||
/** | ||
* Fetches a count of ApiUsers that have permission to access the one defined facility and do not | ||
* have the ALL_FACILITIES and/or ADMIN roles | ||
* | ||
* @param facility - Facility to get count for | ||
* @return Integer - count of ApiUsers | ||
*/ | ||
public Integer getUsersWithSingleFacilityAccessCount(Facility facility) { | ||
List<ApiUser> users = | ||
_userRepo.findAllByFacilityAndRoles( | ||
facility, List.of(OrganizationRole.USER, OrganizationRole.ENTRY_ONLY)); | ||
return users.stream() | ||
.filter(user -> user.getFacilities().size() <= 1) | ||
.collect(Collectors.toList()) | ||
.size(); | ||
} | ||
} |
Oops, something went wrong.