diff --git a/auth-api/src/auth_api/models/activity_log.py b/auth-api/src/auth_api/models/activity_log.py index df850bd379..c94842c1fd 100644 --- a/auth-api/src/auth_api/models/activity_log.py +++ b/auth-api/src/auth_api/models/activity_log.py @@ -49,7 +49,7 @@ def fetch_activity_logs_for_account( # pylint: disable=too-many-positional-argu query = ( db.session.query(ActivityLog, User) .outerjoin(User, User.id == ActivityLog.actor_id) - .filter(ActivityLog.org_id == org_id) + .filter(ActivityLog.org_id == int(org_id or -1)) .order_by(desc(ActivityLog.created)) ) diff --git a/auth-api/src/auth_api/models/affiliation_invitation.py b/auth-api/src/auth_api/models/affiliation_invitation.py index 3729d35a6e..168588a073 100644 --- a/auth-api/src/auth_api/models/affiliation_invitation.py +++ b/auth-api/src/auth_api/models/affiliation_invitation.py @@ -167,19 +167,21 @@ def find_invitation_by_id(cls, invitation_id: int): @classmethod 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) + results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.from_org_id == int(org_id or -1)) return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all() @classmethod 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) + results = db.session.query(AffiliationInvitation).filter(AffiliationInvitation.to_org_id == int(org_id or -1)) return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all() @classmethod 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) + results = db.session.query(AffiliationInvitation).filter( + AffiliationInvitation.entity_id == int(entity_id or -1) + ) return results.filter(AffiliationInvitation.status == status.value).all() if status else results.all() @classmethod @@ -192,8 +194,8 @@ def find_invitations_by_org_entity_ids(from_org_id: int, entity_id: int): """Find all affiliation invitation for org and entity ids.""" return ( db.session.query(AffiliationInvitation) - .filter(AffiliationInvitation.from_org_id == from_org_id) - .filter(AffiliationInvitation.entity_id == entity_id) + .filter(AffiliationInvitation.from_org_id == int(from_org_id or -1)) + .filter(AffiliationInvitation.entity_id == int(entity_id or -1)) .filter( or_( AffiliationInvitation.invitation_status_code == InvitationStatuses.PENDING.value, diff --git a/auth-api/src/auth_api/models/invitation.py b/auth-api/src/auth_api/models/invitation.py index 6e2929ceb4..19183d15e2 100644 --- a/auth-api/src/auth_api/models/invitation.py +++ b/auth-api/src/auth_api/models/invitation.py @@ -115,7 +115,7 @@ def find_pending_invitations_by_org(org_id: int): """Find all invitations that are not in accepted state.""" return ( db.session.query(Invitation) - .filter(Invitation.membership.any(InvitationMembership.org_id == org_id)) + .filter(Invitation.membership.any(InvitationMembership.org_id == int(org_id or -1))) .filter(Invitation.invitation_status_code != "ACCEPTED") .all() ) @@ -125,7 +125,7 @@ def find_invitations_by_status(user_id: int, status): """Find all invitations that are not in accepted state.""" return ( db.session.query(Invitation) - .filter(Invitation.sender_id == user_id) + .filter(Invitation.sender_id == int(user_id or -1)) .filter(Invitation.invitation_status_code == status) .all() ) diff --git a/auth-api/src/auth_api/models/product_subscription.py b/auth-api/src/auth_api/models/product_subscription.py index 9f512a904a..64482456f0 100644 --- a/auth-api/src/auth_api/models/product_subscription.py +++ b/auth-api/src/auth_api/models/product_subscription.py @@ -49,7 +49,7 @@ def find_by_org_id_product_code(cls, org_id: int, product_code, valid_statuses=V """Find an product subscription instance that matches the provided id.""" return cls.query.filter( and_( - ProductSubscription.org_id == org_id, + ProductSubscription.org_id == int(org_id or -1), ProductSubscription.product_code == product_code, ProductSubscription.status_code.in_(valid_statuses), ) diff --git a/auth-api/src/auth_api/models/task.py b/auth-api/src/auth_api/models/task.py index 288cc6cc3e..0badd670ec 100644 --- a/auth-api/src/auth_api/models/task.py +++ b/auth-api/src/auth_api/models/task.py @@ -105,7 +105,7 @@ def find_by_task_relationship_id( return ( db.session.query(Task) .filter( - Task.relationship_id == relationship_id, + Task.relationship_id == int(relationship_id or -1), Task.relationship_type == task_relationship_type, Task.status == task_status, ) diff --git a/auth-api/src/auth_api/services/affiliation.py b/auth-api/src/auth_api/services/affiliation.py index 9fb8b85dea..8267e8dadc 100644 --- a/auth-api/src/auth_api/services/affiliation.py +++ b/auth-api/src/auth_api/services/affiliation.py @@ -140,7 +140,10 @@ def find_affiliations_by_org_id(org_id, environment=None): subqueryload(Entity.created_by), subqueryload(Entity.modified_by), ) - .filter(AffiliationModel.org_id == org_id, Entity.affiliations.any(AffiliationModel.org_id == org_id)) + .filter( + AffiliationModel.org_id == int(org_id or -1), + Entity.affiliations.any(AffiliationModel.org_id == int(org_id or -1)), + ) ) if environment: entities = entities.filter(AffiliationModel.environment == environment) diff --git a/auth-api/src/auth_api/services/user.py b/auth-api/src/auth_api/services/user.py index 666a424757..f94341d598 100644 --- a/auth-api/src/auth_api/services/user.py +++ b/auth-api/src/auth_api/services/user.py @@ -133,7 +133,7 @@ def create_user_and_add_membership( enabled_in_kc = getattr(existing_kc_user, "enabled", True) if getattr(user_model, "status", None) == Status.INACTIVE.value and not enabled_in_kc: membership_model = MembershipModel.find_membership_by_userid(user_model.id) - re_enable_user = membership_model.org_id == org_id + re_enable_user = membership_model.org_id == int(org_id or -1) if user_model and not re_enable_user: logger.debug("Existing users found in DB") users.append(User._get_error_dict(username, Error.USER_ALREADY_EXISTS))