@@ -162,6 +162,8 @@ def create_org(org_info: dict, user_id):
162162
163163 if is_staff_review_needed :
164164 Org ._create_staff_review_task (org , UserModel .find_by_jwt_token ())
165+ else :
166+ Org ._send_account_created_notification (org , UserModel .find_by_jwt_token ())
165167
166168 org .commit ()
167169
@@ -200,6 +202,30 @@ def _create_staff_review_task(org: OrgModel, user: UserModel):
200202 TaskService .create_task (task_info = task_info , do_commit = False )
201203 Org .send_staff_review_account_reminder (relationship_id = org .id )
202204
205+ @staticmethod
206+ def _send_account_created_notification (org : OrgModel , user : UserModel ):
207+ """Send account created notification to the user."""
208+ current_app .logger .debug ("<_send_account_created_notification" )
209+ app_url = current_app .config .get ("WEB_APP_URL" )
210+ recipients = UserService .get_admin_emails_for_org (org .id )
211+ login_source = user .login_source
212+ if not recipients :
213+ current_app .logger .warning (f"No recipient found for org { org .id } " )
214+ return
215+
216+ data = {
217+ "accountId" : org .id ,
218+ "orgName" : org .name ,
219+ "emailAddresses" : recipients ,
220+ "contextUrl" : app_url ,
221+ "loginSource" : login_source ,
222+ }
223+ try :
224+ publish_to_mailer (QueueMessageTypes .ACCOUNT_CREATED_NOTIFICATION .value , data = data )
225+ current_app .logger .debug ("_send_account_created_notification>" )
226+ except Exception as e : # noqa: B901
227+ current_app .logger .warning (f"_send_account_created_notification failed: { e } " )
228+
203229 @staticmethod
204230 @user_context
205231 def create_membership (org , user_id , ** kwargs ):
@@ -954,7 +980,7 @@ def change_org_status(self, status_code, suspension_reason_code):
954980 return Org (org_model )
955981
956982 @staticmethod
957- def approve_or_reject (org_id : int , is_approved : bool , origin_url : str = None , task_action : str = None ):
983+ def approve_or_reject (org_id : int , is_approved : bool , task_action : str = None ):
958984 """Mark the affidavit as approved or rejected."""
959985 current_app .logger .debug ("<find_affidavit_by_org_id " )
960986 # Get the org and check what's the current status
@@ -981,10 +1007,10 @@ def approve_or_reject(org_id: int, is_approved: bool, origin_url: str = None, ta
9811007 admin_emails = UserService .get_admin_emails_for_org (org_id )
9821008 if admin_emails != "" :
9831009 if org .access_type in (AccessType .EXTRA_PROVINCIAL .value , AccessType .REGULAR_BCEID .value ):
984- Org .send_approved_rejected_notification (admin_emails , org .name , org .id , org .status_code , origin_url )
1010+ Org .send_approved_rejected_notification (admin_emails , org .name , org .id , org .status_code , user )
9851011 elif org .access_type in (AccessType .GOVM .value , AccessType .GOVN .value ):
9861012 Org .send_approved_rejected_govm_govn_notification (
987- admin_emails , org .name , org .id , org .status_code , origin_url
1013+ admin_emails , org .name , org .id , org .status_code , user
9881014 )
9891015 else :
9901016 # continue but log error
@@ -1025,7 +1051,7 @@ def send_staff_review_account_reminder(relationship_id, task_relationship_type=T
10251051 raise BusinessException (Error .FAILED_NOTIFICATION , None ) from e
10261052
10271053 @staticmethod
1028- def send_approved_rejected_notification (receipt_admin_emails , org_name , org_id , org_status : OrgStatus , origin_url ):
1054+ def send_approved_rejected_notification (receipt_admin_emails , org_name , org_id , org_status : OrgStatus , user : UserModel = None ):
10291055 """Send Approved/Rejected notification to the user."""
10301056 current_app .logger .debug ("<send_approved_rejected_notification" )
10311057
@@ -1035,8 +1061,14 @@ def send_approved_rejected_notification(receipt_admin_emails, org_name, org_id,
10351061 notification_type = QueueMessageTypes .NON_BCSC_ORG_REJECTED_NOTIFICATION .value
10361062 else :
10371063 return # Don't send mail for any other status change
1038- app_url = f"{ origin_url } /"
1039- data = {"accountId" : org_id , "emailAddresses" : receipt_admin_emails , "contextUrl" : app_url , "orgName" : org_name }
1064+ app_url = current_app .config .get ("WEB_APP_URL" )
1065+ data = {
1066+ "accountId" : org_id ,
1067+ "emailAddresses" : receipt_admin_emails ,
1068+ "contextUrl" : app_url ,
1069+ "orgName" : org_name ,
1070+ "loginSource" : user .login_source
1071+ }
10401072 try :
10411073 publish_to_mailer (notification_type , data = data )
10421074 current_app .logger .debug ("<send_approved_rejected_notification" )
@@ -1046,7 +1078,7 @@ def send_approved_rejected_notification(receipt_admin_emails, org_name, org_id,
10461078
10471079 @staticmethod
10481080 def send_approved_rejected_govm_govn_notification (
1049- receipt_admin_email , org_name , org_id , org_status : OrgStatus , origin_url
1081+ receipt_admin_email , org_name , org_id , org_status : OrgStatus , origin_url , user : UserModel
10501082 ):
10511083 """Send Approved govm notification to the user."""
10521084 current_app .logger .debug ("<send_approved_rejected_govm_govn_notification" )
@@ -1058,7 +1090,7 @@ def send_approved_rejected_govm_govn_notification(
10581090 else :
10591091 return # Don't send mail for any other status change
10601092 app_url = f"{ origin_url } /"
1061- data = {"accountId" : org_id , "emailAddresses" : receipt_admin_email , "contextUrl" : app_url , "orgName" : org_name }
1093+ data = {"accountId" : org_id , "emailAddresses" : receipt_admin_email , "contextUrl" : app_url , "orgName" : org_name , "loginSource" : user . login_source }
10621094 try :
10631095 publish_to_mailer (notification_type , data = data )
10641096 current_app .logger .debug ("send_approved_rejected_govm_govn_notification>" )
0 commit comments