Skip to content

Commit

Permalink
Parametrizing the service.
Browse files Browse the repository at this point in the history
  • Loading branch information
hfekete committed Nov 21, 2023
1 parent 441005b commit 6e58f75
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
10 changes: 9 additions & 1 deletion auth-api/src/auth_api/models/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Basic users will have an internal Org that is not created explicitly, but implicitly upon User account creation.
"""
from typing import List
from flask import current_app
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, and_, cast, event, func, text
from sqlalchemy.orm import contains_eager, relationship
Expand Down Expand Up @@ -158,12 +159,19 @@ def search_org(cls, search: OrgSearch, environment: str):
return pagination.items, pagination.total

@classmethod
def search_orgs_by_business_identifier(cls, business_identifier, pagination_info: PaginationInfo, environment):
def search_orgs_by_business_identifier(cls,
business_identifier,
pagination_info: PaginationInfo,
environment,
excluded_org_types: List[str] = None
):
"""Find all orgs affiliated with provided business identifier."""
query = db.session.query(Org)

query = cls._search_for_statuses(query, [])
query = cls._search_by_business_identifier(query, business_identifier, environment)
if excluded_org_types:
query = query.filter(Org.type_code.notin_(excluded_org_types))

pagination = query.order_by(Org.name.desc()) \
.paginate(per_page=pagination_info.limit, page=pagination_info.page)
Expand Down
14 changes: 6 additions & 8 deletions auth-api/src/auth_api/resources/v1/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from auth_api.services.authorization import Authorization as AuthorizationService
from auth_api.tracer import Tracer
from auth_api.utils.endpoints_enums import EndpointEnum
from auth_api.utils.enums import AccessType, NotificationType, PatchActions, Status
from auth_api.utils.enums import AccessType, NotificationType, OrgType, PatchActions, Status
from auth_api.utils.role_validator import validate_roles
from auth_api.utils.roles import ALL_ALLOWED_ROLES, CLIENT_ADMIN_ROLES, STAFF, USER, Role # noqa: I005
from auth_api.utils.util import get_request_environment
Expand Down Expand Up @@ -396,16 +396,14 @@ def get_org_details_by_affiliation(business_identifier):
limit=int(request.args.get('limit', 10)),
page=int(request.args.get('page', 1))
)

excluded_org_types = [OrgType.STAFF.value, OrgType.SBC_STAFF.value]
try:
data = OrgService.search_orgs_by_affiliation(business_identifier, pagination_info, environment)
data = OrgService.search_orgs_by_affiliation(
business_identifier, pagination_info, environment, excluded_org_types
)

org_details = \
[
{'name': org.name, 'uuid': org.uuid, 'branchName': org.branch_name} for org
in data['orgs']
if org.type_code.upper() not in ['SBC_STAFF', 'STAFF']
]
[{'name': org.name, 'uuid': org.uuid, 'branchName': org.branch_name} for org in data['orgs']]
response, status = {'orgs_details': org_details}, http_status.HTTP_200_OK

except BusinessException as exception:
Expand Down
12 changes: 9 additions & 3 deletions auth-api/src/auth_api/services/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,16 @@ def search_orgs(search: OrgSearch, environment): # pylint: disable=too-many-loc
return orgs_result

@staticmethod
def search_orgs_by_affiliation(business_identifier,
pagination_info: PaginationInfo, environment):
def search_orgs_by_affiliation(
business_identifier, pagination_info: PaginationInfo, environment, excluded_org_types
):
"""Search for orgs based on input parameters."""
orgs, total = OrgModel.search_orgs_by_business_identifier(business_identifier, pagination_info, environment)
orgs, total = OrgModel.search_orgs_by_business_identifier(
business_identifier,
pagination_info,
environment,
excluded_org_types
)

return {
'orgs': orgs,
Expand Down

0 comments on commit 6e58f75

Please sign in to comment.