From b32fb681ac1d0f84eee11c91f9f49b7a82853e86 Mon Sep 17 00:00:00 2001 From: karthik-aot <78374865+karthik-aot@users.noreply.github.com> Date: Mon, 28 Jun 2021 17:30:03 -0700 Subject: [PATCH] account staff review fix (#1706) --- auth-api/src/auth_api/models/task.py | 10 +++++++++- auth-api/src/auth_api/services/org.py | 20 ++++++++++++-------- auth-api/tests/unit/models/test_task.py | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/auth-api/src/auth_api/models/task.py b/auth-api/src/auth_api/models/task.py index 1897e1c4dd..82f76aaa73 100644 --- a/auth-api/src/auth_api/models/task.py +++ b/auth-api/src/auth_api/models/task.py @@ -16,7 +16,7 @@ from sqlalchemy import Column, DateTime, ForeignKey, Integer, String from sqlalchemy.orm import relationship -from ..utils.enums import TaskRelationshipStatus +from ..utils.enums import TaskRelationshipStatus, TaskStatus from .base_model import BaseModel from .db import db @@ -69,3 +69,11 @@ def fetch_tasks(cls, task_type: str, task_status: str, # pylint:disable=too-man def find_by_task_id(cls, task_id): """Find a task instance that matches the provided id.""" return db.session.query(Task).filter_by(id=task_id).first() + + @classmethod + def find_by_task_relationship_id(cls, relationship_id: int, task_relationship_type: str, + task_status: str = TaskStatus.OPEN.value): + """Find a task instance that related to the relationship id ( may be an ORG or a PRODUCT.""" + return db.session.query(Task).filter(Task.relationship_id == relationship_id, + Task.relationship_type == task_relationship_type, + task_status == task_status).first() diff --git a/auth-api/src/auth_api/services/org.py b/auth-api/src/auth_api/services/org.py index ec837edf19..4eda5d82ff 100644 --- a/auth-api/src/auth_api/services/org.py +++ b/auth-api/src/auth_api/services/org.py @@ -29,6 +29,7 @@ from auth_api.models import Membership as MembershipModel from auth_api.models import Org as OrgModel from auth_api.models import User as UserModel +from auth_api.models import Task as TaskModel from auth_api.models.affidavit import Affidavit as AffidavitModel from auth_api.schemas import ContactSchema, InvitationSchema, OrgSchema from auth_api.services.validators.access_type import validate as access_type_validate @@ -53,7 +54,6 @@ from .task import Task as TaskService from .validators.validator_response import ValidatorResponse - ENV = Environment(loader=FileSystemLoader('.'), autoescape=True) @@ -133,14 +133,14 @@ def create_org(org_info: dict, user_id, origin_url: str = None): # Send an email to staff to remind review the pending account is_bceid_status_handling_needed = access_type in (AccessType.EXTRA_PROVINCIAL.value, AccessType.REGULAR_BCEID.value) \ - and not AffidavitModel.find_approved_by_user_id(user_id=user_id) + and not AffidavitModel.find_approved_by_user_id(user_id=user_id) if is_bceid_status_handling_needed: Org._handle_bceid_status_and_notification(org) org.commit() if is_bceid_status_handling_needed: - Org.send_staff_review_account_reminder(org.id, origin_url) + Org.send_staff_review_account_reminder(relationship_id=org.id, origin_url=origin_url) current_app.logger.info(f'update_org ') @@ -815,11 +815,16 @@ def approve_or_reject(org_id: int, is_approved: bool, origin_url: str = None): @staticmethod @user_context - def send_staff_review_account_reminder(org_id, origin_url, **kwargs): + def send_staff_review_account_reminder(relationship_id, origin_url, + task_relationship_type=TaskRelationshipType.ORG.value, + **kwargs): """Send staff review account reminder notification.""" current_app.logger.debug('