Skip to content

Commit

Permalink
11228 - AffidavitStatus filter for approve/reject multiple BCeId acco…
Browse files Browse the repository at this point in the history
…unt (#1919)
  • Loading branch information
karthik-aot authored Mar 8, 2022
1 parent 0ed2478 commit daab747
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions auth-api/src/auth_api/models/affidavit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ class Affidavit(VersionedModel):
user = relationship('User', foreign_keys=[user_id], lazy='select')

@classmethod
def find_by_org_id(cls, org_id: int):
def find_by_org_id(cls, org_id: int, filtered_affidavit_statuses=None):
"""Find an affidavit by org id."""
if filtered_affidavit_statuses is None:
filtered_affidavit_statuses = [AffidavitStatus.INACTIVE.value]
return db.session.query(Affidavit) \
.join(Membership, Membership.user_id == Affidavit.user_id) \
.join(Org, Org.id == Membership.org_id) \
.filter(and_(Org.id == org_id, Affidavit.status_code != AffidavitStatus.INACTIVE.value)) \
.filter(and_(Org.id == org_id, Affidavit.status_code not in filtered_affidavit_statuses)) \
.one_or_none() # There should be only one record at most, else throw error

@classmethod
Expand Down
18 changes: 11 additions & 7 deletions auth-api/src/auth_api/services/affidavit.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def _modify_task(user):
TaskService.close_task(task_model.id, remarks)

@staticmethod
def find_affidavit_by_org_id(org_id: int):
def find_affidavit_by_org_id(org_id: int, filtered_affidavit_statuses=None):
"""Return affidavit for the org by finding the admin for the org."""
current_app.logger.debug('<find_affidavit_by_org_id ')
affidavit = AffidavitModel.find_by_org_id(org_id)
affidavit = AffidavitModel.find_by_org_id(org_id, filtered_affidavit_statuses)
affidavit_dict = Affidavit(affidavit).as_dict()
affidavit_dict['documentUrl'] = MinioService.create_signed_get_url(affidavit.document_id)
current_app.logger.debug('>find_affidavit_by_org_id ')
Expand All @@ -159,14 +159,18 @@ def find_affidavit_by_user_guid(user_guid: str, status: str = None):

@staticmethod
def approve_or_reject(org_id: int, is_approved: bool, user: UserModel):
"""Mark the affdiavit as approved or rejected."""
current_app.logger.debug('<find_affidavit_by_org_id ')
affidavit: AffidavitModel = AffidavitModel.find_by_org_id(org_id)
"""Mark the affidavit as approved or rejected."""
current_app.logger.debug('<approve_or_reject ')
# In order to get the pending affidavit to be reviewed, we need to filter out the following cases
# 1. Inactive affidavits - usually while the old affidavit is made inactive
# while the task is put on hold and the user uploads a new one.
# 2. When the user account request is rejected, then user creates a new account
filtered_affidavit_statuses = [AffidavitStatus.INACTIVE.value, AffidavitStatus.REJECTED.value]
affidavit: AffidavitModel = AffidavitModel.find_by_org_id(org_id, filtered_affidavit_statuses)
affidavit.decision_made_by = user.username
affidavit.decision_made_on = datetime.now()
affidavit.status_code = AffidavitStatus.APPROVED.value if is_approved else AffidavitStatus.REJECTED.value

current_app.logger.debug('>find_affidavit_by_org_id ')
current_app.logger.debug('>approve_or_reject')
return Affidavit(affidavit)

@staticmethod
Expand Down

0 comments on commit daab747

Please sign in to comment.