5656 get_product_notification_data ,
5757 get_product_notification_type ,
5858)
59- from auth_api .utils .roles import CLIENT_ADMIN_ROLES , CLIENT_AUTH_ROLES , GOV_ORG_TYPES , STAFF
59+ from auth_api .utils .roles import CLIENT_ADMIN_ROLES , CLIENT_AUTH_ROLES , STAFF
6060from auth_api .utils .user_context import UserContext , user_context
6161
6262from .activity_log_publisher import ActivityLogPublisher
@@ -170,7 +170,7 @@ def _is_previously_approved(org_id: int, product_code: str):
170170 )
171171 if task is None or (
172172 task .relationship_status != TaskRelationshipStatus .ACTIVE .value
173- and task .action in ( TaskAction .PRODUCT_REVIEW .value , TaskAction . NEW_PRODUCT_FEE_REVIEW . value )
173+ and task .action == TaskAction .PRODUCT_REVIEW .value
174174 ):
175175 return False , None
176176
@@ -183,7 +183,6 @@ def create_product_subscription(
183183 is_new_transaction : bool = True ,
184184 skip_auth = False ,
185185 auto_approve = False ,
186- staff_review_for_create_org = False ,
187186 ):
188187 """Create product subscription for the user.
189188
@@ -199,7 +198,6 @@ def create_product_subscription(
199198
200199 subscriptions_list = subscription_data .get ("subscriptions" )
201200 for subscription in subscriptions_list :
202- auto_approve_current = auto_approve
203201 product_code = subscription .get ("productCode" )
204202 if ProductSubscriptionModel .find_by_org_id_product_code (org_id , product_code ):
205203 raise BusinessException (Error .PRODUCT_SUBSCRIPTION_EXISTS , None )
@@ -210,11 +208,9 @@ def create_product_subscription(
210208 check_auth (system_required = True , org_id = org_id )
211209 previously_approved , inactive_sub = Product ._is_previously_approved (org_id , product_code )
212210 if previously_approved :
213- auto_approve_current = True
211+ auto_approve = True
214212
215- subscription_status = Product .find_subscription_status (
216- org , product_model , auto_approve_current , staff_review_for_create_org
217- )
213+ subscription_status = Product .find_subscription_status (org , product_model , auto_approve )
218214 product_subscription = Product ._subscribe_and_publish_activity (
219215 SubscriptionRequest (
220216 org_id = org_id ,
@@ -249,7 +245,6 @@ def create_product_subscription(
249245 ProductReviewTask (
250246 org_id = org .id ,
251247 org_name = org .name ,
252- org_access_type = org .access_type ,
253248 product_code = product_subscription .product_code ,
254249 product_description = product_model .description ,
255250 product_subscription_id = product_subscription .id ,
@@ -376,14 +371,11 @@ def _reset_subscription_and_review_task(
376371 @staticmethod
377372 def _create_review_task (review_task : ProductReviewTask ):
378373 task_type = review_task .product_description
379-
380- required_review_types = {AccessType .GOVM .value , AccessType .GOVN .value }
381- if review_task .product_code in QUALIFIED_SUPPLIER_PRODUCT_CODES :
382- action_type = TaskAction .QUALIFIED_SUPPLIER_REVIEW .value
383- elif review_task .org_access_type in required_review_types :
384- action_type = TaskAction .NEW_PRODUCT_FEE_REVIEW .value
385- else :
386- action_type = TaskAction .PRODUCT_REVIEW .value
374+ action_type = (
375+ TaskAction .QUALIFIED_SUPPLIER_REVIEW .value
376+ if review_task .product_code in QUALIFIED_SUPPLIER_PRODUCT_CODES
377+ else TaskAction .PRODUCT_REVIEW .value
378+ )
387379
388380 task_info = {
389381 "name" : review_task .org_name ,
@@ -401,13 +393,14 @@ def _create_review_task(review_task: ProductReviewTask):
401393 TaskService .create_task (task_info , False )
402394
403395 @staticmethod
404- def find_subscription_status (org , product_model , auto_approve = False , staff_review_for_create_org = False ):
396+ def find_subscription_status (org , product_model , auto_approve = False ):
405397 """Return the subscriptions status based on org type."""
406- skip_review = org .access_type in GOV_ORG_TYPES and staff_review_for_create_org # prevent create second task when it's already added a staff review when creating org
407- if (product_model .need_review or org .access_type in GOV_ORG_TYPES ) and not auto_approve :
398+ # GOVM accounts has default active subscriptions
399+ skip_review_types = [AccessType .GOVM .value ]
400+ if product_model .need_review and auto_approve is False :
408401 return (
409402 ProductSubscriptionStatus .ACTIVE .value
410- if skip_review
403+ if ( org . access_type in skip_review_types )
411404 else ProductSubscriptionStatus .PENDING_STAFF_REVIEW .value
412405 )
413406 return ProductSubscriptionStatus .ACTIVE .value
@@ -459,10 +452,7 @@ def get_all_product_subscription(org_id, skip_auth=False, **kwargs):
459452 check_auth (one_of_roles = (* CLIENT_AUTH_ROLES , STAFF ), org_id = org_id )
460453
461454 product_subscriptions : list [ProductSubscriptionModel ] = ProductSubscriptionModel .find_by_org_ids ([org_id ])
462- subscription_by_code = {
463- sub .product_code : sub
464- for sub in product_subscriptions
465- }
455+ subscriptions_dict = {x .product_code : x .status_code for x in product_subscriptions }
466456
467457 # Include hidden products only for staff and SBC staff
468458 include_hidden = (
@@ -474,9 +464,9 @@ def get_all_product_subscription(org_id, skip_auth=False, **kwargs):
474464
475465 products = Product .get_products (include_hidden = include_hidden , staff_check = False )
476466 for product in products :
477- sub = subscription_by_code .get (product . get ( "code" ))
478- product [ "subscriptionStatus" ] = getattr ( sub , "status_code" , ProductSubscriptionStatus .NOT_SUBSCRIBED .value )
479- product [ "id" ] = getattr ( sub , "id" , None )
467+ product [ "subscriptionStatus" ] = subscriptions_dict .get (
468+ product . get ( "code" ) , ProductSubscriptionStatus .NOT_SUBSCRIBED .value
469+ )
480470
481471 return products
482472
@@ -490,6 +480,7 @@ def update_product_subscription(product_sub_info: ProductSubscriptionInfo, is_ne
490480 is_hold = product_sub_info .is_hold
491481 org_id = product_sub_info .org_id
492482 org_name = product_sub_info .org_name
483+
493484 # Approve/Reject Product subscription
494485 product_subscription : ProductSubscriptionModel = ProductSubscriptionModel .find_by_id (product_subscription_id )
495486
@@ -510,6 +501,7 @@ def update_product_subscription(product_sub_info: ProductSubscriptionInfo, is_ne
510501 product_model : ProductCodeModel = ProductCodeModel .find_by_code (product_subscription .product_code )
511502 # Find admin email addresses
512503 admin_emails = UserService .get_admin_emails_for_org (org_id )
504+
513505 if admin_emails != "" and not is_hold :
514506 Product .send_product_subscription_notification (
515507 ProductNotificationInfo (
@@ -519,7 +511,7 @@ def update_product_subscription(product_sub_info: ProductSubscriptionInfo, is_ne
519511 is_reapproved = is_reapproved ,
520512 remarks = product_sub_info .task_remarks ,
521513 org_id = org_id ,
522- org_name = org_name ,
514+ org_name = org_name
523515 )
524516 )
525517
0 commit comments