Skip to content

Commit

Permalink
Force conver string to int.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwei1018 committed Sep 21, 2024
1 parent cd449d2 commit dc3914a
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 93 deletions.
1 change: 1 addition & 0 deletions .github/workflows/account-mailer-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature*
paths:
- "queue_services/account-mailer/**"
- "auth-api/src/auth_api/models/**"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/auth-api-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature*
paths:
- "auth-api/**"
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/auth-queue-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature*
paths:
- "queue_services/auth-queue/**"
- "auth-api/src/auth_api/models/**"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/auth-web-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
- feature*
paths:
- "auth-web/**"
workflow_dispatch:
inputs:
target:
Expand Down
4 changes: 2 additions & 2 deletions auth-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion auth-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "auth-api"
version = "3.0.3"
version = "3.0.4"
description = ""
authors = ["\"BC Registries and Online Services\""]
readme = "README.md"
Expand All @@ -25,6 +25,7 @@ aiohttp = "^3.10.2"
cattrs = "^23.2.3"
orjson = "^3.10.7"
sqlalchemy-utils = "^0.41.2"
psycopg2 = "^2.9.9"

# VCS dependencies
sql-versioning = { git = "https://github.com/bcgov/sbc-connect-common.git", subdirectory = "python/sql-versioning", branch = "main" }
Expand Down
10 changes: 6 additions & 4 deletions auth-api/src/auth_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ class _Config: # pylint: disable=too-few-public-methods
DB_PASSWORD = os.getenv("DATABASE_PASSWORD", "")
DB_NAME = os.getenv("DATABASE_NAME", "")
DB_HOST = os.getenv("DATABASE_HOST", "")
DB_PORT = os.getenv("DATABASE_PORT", "5432")
DB_PORT = int(os.getenv("DATABASE_PORT", "5432")) # POSTGRESQL
if DB_UNIX_SOCKET := os.getenv("DATABASE_UNIX_SOCKET", None):
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_UNIX_SOCKET}"
SQLALCHEMY_DATABASE_URI = (
f"postgresql+pg8000://{DB_USER}:{DB_PASSWORD}@/{DB_NAME}?unix_sock={DB_UNIX_SOCKET}/.s.PGSQL.5432"
)
else:
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}"
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"

# JWT_OIDC Settings
JWT_OIDC_WELL_KNOWN_CONFIG = os.getenv("JWT_OIDC_WELL_KNOWN_CONFIG")
Expand Down Expand Up @@ -220,7 +222,7 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
DB_HOST = os.getenv("DATABASE_TEST_HOST", "localhost")
DB_PORT = os.getenv("DATABASE_TEST_PORT", "5432")
SQLALCHEMY_DATABASE_URI = os.getenv(
"DATABASE_TEST_URL", f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}"
"DATABASE_TEST_URL", f"postgresql+pg8000://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{int(DB_PORT)}/{DB_NAME}"
)

# JWT OIDC settings
Expand Down
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/account_login_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class AccountLoginOptions(Versioned, BaseModel): # pylint: disable=too-few-publ
org = relationship("Org", foreign_keys=[org_id], lazy="select")

@classmethod
def find_active_by_org_id(cls, account_id):
def find_active_by_org_id(cls, account_id: int):
"""Find an account setting instance that matches the provided org_id."""
return cls.query.filter_by(org_id=account_id).filter_by(is_active=True).first()
return cls.query.filter_by(org_id=int(account_id)).filter_by(is_active=True).first()
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/affidavit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def find_by_org_id(cls, org_id: int, filtered_affidavit_statuses=None):
@classmethod
def find_pending_by_user_id(cls, user_id: int):
"""Find pending affidavit by user id."""
return cls.query.filter_by(user_id=user_id, status_code=AffidavitStatus.PENDING.value).one_or_none()
return cls.query.filter_by(user_id=int(user_id), status_code=AffidavitStatus.PENDING.value).one_or_none()

@classmethod
def find_approved_by_user_id(cls, user_id: int):
"""Find pending affidavit by user id."""
return cls.query.filter_by(user_id=user_id, status_code=AffidavitStatus.APPROVED.value).one_or_none()
return cls.query.filter_by(user_id=int(user_id), status_code=AffidavitStatus.APPROVED.value).one_or_none()

@classmethod
def find_effective_by_user_guid(cls, user_guid: str, status: str = None):
Expand Down
10 changes: 5 additions & 5 deletions auth-api/src/auth_api/models/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ def filter_environment(cls, environment: str):
return query

@classmethod
def find_affiliation_by_org_and_entity_ids(cls, org_id, entity_id, environment) -> Affiliation:
def find_affiliation_by_org_and_entity_ids(cls, org_id: int, entity_id: int, environment) -> Affiliation:
"""Return an affiliation for the provided org and entity ids."""
query = cls.filter_environment(environment).filter_by(org_id=org_id, entity_id=entity_id)
query = cls.filter_environment(environment).filter_by(org_id=int(org_id), entity_id=int(entity_id))
return query.one_or_none()

@classmethod
def find_affiliations_by_entity_id(cls, entity_id, environment) -> List[Affiliation]:
def find_affiliations_by_entity_id(cls, entity_id: int, environment) -> List[Affiliation]:
"""Return affiliations for the provided entity id."""
return cls.filter_environment(environment).filter_by(entity_id=entity_id).all()
return cls.filter_environment(environment).filter_by(entity_id=int(entity_id)).all()

@classmethod
def find_affiliation_by_ids(cls, org_id: int, affiliation_id: int) -> Affiliation:
"""Return the first Affiliation with the provided ids."""
return cls.query.filter_by(org_id=org_id).filter_by(id=affiliation_id).one_or_none()
return cls.query.filter_by(org_id=int(org_id)).filter_by(id=int(affiliation_id)).one_or_none()

@classmethod
def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affiliation]:
Expand Down
44 changes: 28 additions & 16 deletions auth-api/src/auth_api/models/affiliation_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,39 @@ def filter_by(cls, search_filter: AffiliationInvitationSearch, query=None) -> li
results = db.session.query(AffiliationInvitation)

if search_filter.from_org_id:
results = results.filter(AffiliationInvitation.from_org_id == search_filter.from_org_id)
results = results.filter(
AffiliationInvitation.from_org_id.cast(Integer) == search_filter.from_org_id.cast(Integer)
)
filter_set = True

if search_filter.to_org_id:
results = results.filter(AffiliationInvitation.to_org_id == search_filter.to_org_id)
results = results.filter(
AffiliationInvitation.to_org_id.cast(Integer) == search_filter.to_org_id.cast(Integer)
)
filter_set = True

if search_filter.sender_id:
results = results.filter(AffiliationInvitation.sender_id == search_filter.sender_id)
results = results.filter(
AffiliationInvitation.sender_id.cast(Integer) == search_filter.sender_id.cast(Integer)
)
filter_set = True

if search_filter.approver_id:
results = results.filter(AffiliationInvitation.approver_id == search_filter.approver_id)
results = results.filter(
AffiliationInvitation.approver_id.cast(Integer) == search_filter.approver_id.cast(Integer)
)
filter_set = True

if search_filter.entity_id:
results = results.filter(AffiliationInvitation.entity_id == search_filter.entity_id)
results = results.filter(
AffiliationInvitation.entity_id.cast(Integer) == search_filter.entity_id.cast(Integer)
)
filter_set = True

if search_filter.affiliation_id:
results = results.filter(AffiliationInvitation.affiliation_id == search_filter.affiliation_id)
results = results.filter(
AffiliationInvitation.affiliation_id.cast(Integer) == search_filter.affiliation_id.cast(Integer)
)
filter_set = True

if search_filter.status_codes:
Expand All @@ -159,32 +171,32 @@ def filter_by(cls, search_filter: AffiliationInvitationSearch, query=None) -> li
return results.all()

@classmethod
def find_invitation_by_id(cls, invitation_id):
def find_invitation_by_id(cls, invitation_id: int):
"""Find an affiliation invitation record that matches the id."""
return cls.query.filter_by(id=invitation_id).first()
return cls.query.filter_by(id=int(invitation_id)).first()

@classmethod
def find_invitations_from_org(cls, org_id, status=None):
def find_invitations_from_org(cls, org_id: int, status=None):
"""Find all affiliation invitations sent from a specific org filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.from_org_id == org_id)
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
def find_invitations_to_org(cls, org_id, status=None):
def find_invitations_to_org(cls, org_id: int, status=None):
"""Find all affiliation invitations sent to a specific org filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.to_org_id == org_id)
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
def find_invitations_by_entity(cls, entity_id, status=None):
def find_invitations_by_entity(cls, entity_id: int, status=None):
"""Find all affiliation invitations sent for specific entity filtered by status."""
results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.entity_id == entity_id)
return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all()

@classmethod
def find_invitations_by_affiliation(cls, affiliation_id):
def find_invitations_by_affiliation(cls, affiliation_id: int):
"""Find all affiliation invitations associated to an affiliation."""
return cls.query.filter_by(affiliation_id=affiliation_id).all()
return cls.query.filter_by(affiliation_id=int(affiliation_id)).all()

@staticmethod
def find_invitations_by_org_entity_ids(from_org_id: int, entity_id: int):
Expand All @@ -202,7 +214,7 @@ def find_invitations_by_org_entity_ids(from_org_id: int, entity_id: int):
.all()
)

def update_invitation_as_retried(self, sender_id):
def update_invitation_as_retried(self, sender_id: int):
"""Update this affiliation invitation with the new data."""
self.sender_id = sender_id
self.sent_date = datetime.now()
Expand All @@ -217,10 +229,10 @@ def set_status(self, new_status_code: str):
return self

@classmethod
def find_all_related_to_org(cls, org_id, search_filter=AffiliationInvitationSearch()):
def find_all_related_to_org(cls, org_id: int, search_filter=AffiliationInvitationSearch()):
"""Return all affiliation invitations that are related to the org (from org or to org) filtered by statuses."""
query = db.session.query(AffiliationInvitation).filter(
or_(AffiliationInvitation.to_org_id == org_id, AffiliationInvitation.from_org_id == org_id)
or_(AffiliationInvitation.to_org_id == int(org_id), AffiliationInvitation.from_org_id == int(org_id))
)

return cls.filter_by(search_filter=search_filter, query=query)
16 changes: 8 additions & 8 deletions auth-api/src/auth_api/models/contact_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ class ContactLink(Versioned, BaseModel): # pylint: disable=too-few-public-metho
affidavit = relationship("Affidavit", foreign_keys=[affidavit_id], lazy="select")

@classmethod
def find_by_entity_id(cls, entity_id):
def find_by_entity_id(cls, entity_id: int):
"""Return the first contact link with the provided entity id."""
return cls.query.filter_by(entity_id=entity_id).first()
return cls.query.filter_by(entity_id=int(entity_id)).first()

@classmethod
def find_by_user_id(cls, user_id):
def find_by_user_id(cls, user_id: int):
"""Return the first contact link with the provided user id."""
return cls.query.filter_by(user_id=user_id).first()
return cls.query.filter_by(user_id=int(user_id)).first()

@classmethod
def find_by_org_id(cls, org_id):
def find_by_org_id(cls, org_id: int):
"""Return the first contact link with the provided org id."""
return cls.query.filter_by(org_id=org_id).first()
return cls.query.filter_by(org_id=int(org_id)).first()

@classmethod
def find_by_affidavit_id(cls, affidavit_id):
def find_by_affidavit_id(cls, affidavit_id: int):
"""Return the first contact link with the provided affidavit id."""
return cls.query.filter_by(affidavit_id=affidavit_id).one_or_none()
return cls.query.filter_by(affidavit_id=int(affidavit_id)).one_or_none()

def has_links(self):
"""Check whether there are any remaining links for this contact."""
Expand Down
4 changes: 2 additions & 2 deletions auth-api/src/auth_api/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def create_from_dict(cls, entity_info: dict):
return None

@classmethod
def find_by_entity_id(cls, entity_id):
def find_by_entity_id(cls, entity_id: int):
"""Find an Entity instance that matches the provided id."""
return cls.query.filter_by(id=entity_id).first()
return cls.query.filter_by(id=int(entity_id)).first()

def reset(self):
"""Reset an Entity back to init state."""
Expand Down
20 changes: 10 additions & 10 deletions auth-api/src/auth_api/models/invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def status(self):
return self.invitation_status_code

@classmethod
def create_from_dict(cls, invitation_info: dict, user_id, invitation_type):
def create_from_dict(cls, invitation_info: dict, user_id: int, invitation_type):
"""Create a new Invitation from the provided dictionary."""
if invitation_info:
invitation = Invitation()
Expand All @@ -85,23 +85,23 @@ def create_from_dict(cls, invitation_info: dict, user_id, invitation_type):
return None

@classmethod
def find_invitations_by_user(cls, user_id):
def find_invitations_by_user(cls, user_id: int):
"""Find all invitation sent by the given user."""
return cls.query.filter_by(sender_id=user_id).all()
return cls.query.filter_by(sender_id=int(user_id)).all()

@classmethod
def find_invitation_by_id(cls, invitation_id):
def find_invitation_by_id(cls, invitation_id: int):
"""Find an invitation record that matches the id."""
return cls.query.filter_by(id=invitation_id).first()
return cls.query.filter_by(id=int(invitation_id)).first()

@classmethod
def find_invitations_by_org(cls, org_id, status=None):
def find_invitations_by_org(cls, org_id: int, status=None):
"""Find all invitations sent for specific org filtered by status."""
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id == org_id))
results = cls.query.filter(Invitation.membership.any(InvitationMembership.org_id.cast(Integer) == org_id))
return results.filter(Invitation.status == status.value).all() if status else results.all()

@staticmethod
def find_pending_invitations_by_user(user_id):
def find_pending_invitations_by_user(user_id: int):
"""Find all invitations that are not in accepted state."""
return (
db.session.query(Invitation)
Expand All @@ -111,7 +111,7 @@ def find_pending_invitations_by_user(user_id):
)

@staticmethod
def find_pending_invitations_by_org(org_id):
def find_pending_invitations_by_org(org_id: int):
"""Find all invitations that are not in accepted state."""
return (
db.session.query(Invitation)
Expand All @@ -121,7 +121,7 @@ def find_pending_invitations_by_org(org_id):
)

@staticmethod
def find_invitations_by_status(user_id, status):
def find_invitations_by_status(user_id: int, status):
"""Find all invitations that are not in accepted state."""
return (
db.session.query(Invitation)
Expand Down
Loading

0 comments on commit dc3914a

Please sign in to comment.