|
1 | 1 | import logging |
2 | 2 | import time |
3 | | -from Access.views_helper import execute_group_access |
| 3 | +from Access.views_helper import execute_group_access, accept_request |
4 | 4 |
|
5 | 5 | from BrowserStackAutomation.settings import DECLINE_REASONS, MAIL_APPROVER_GROUPS |
6 | 6 | import datetime |
@@ -536,14 +536,14 @@ def _validate_access_request(access_request_form, user): |
536 | 536 | return {}, access_request |
537 | 537 |
|
538 | 538 |
|
539 | | -def validate_access_labels(access_labels_json, access_type): |
| 539 | +def validate_access_labels(access_labels_json, access_tag): |
540 | 540 | if access_labels_json is None or access_labels_json == "": |
541 | 541 | raise Exception("No fields were selected in the request. Please try again.") |
542 | 542 | access_labels = json.loads(access_labels_json) |
543 | 543 | if len(access_labels) == 0: |
544 | 544 | raise Exception( |
545 | | - "No fields were selected in the request for {access_type}. Please try again.".format( |
546 | | - access_type=access_type |
| 545 | + "No fields were selected in the request for {access_tag}. Please try again.".format( |
| 546 | + access_tag=access_tag |
547 | 547 | ) |
548 | 548 | ) |
549 | 549 | return access_labels |
@@ -591,7 +591,9 @@ def accept_user_access_requests(auth_user, request_id): |
591 | 591 | access_label = access_mapping.access.access_label |
592 | 592 |
|
593 | 593 | try: |
594 | | - permissions = _get_approver_permissions(access_mapping.access.access_tag, access_label) |
| 594 | + permissions = _get_approver_permissions( |
| 595 | + access_mapping.access.access_tag, access_label |
| 596 | + ) |
595 | 597 | approver_permissions = permissions["approver_permissions"] |
596 | 598 | if not helper.check_user_permissions( |
597 | 599 | auth_user, list(approver_permissions.values()) |
@@ -643,20 +645,21 @@ def run_accept_request_task( |
643 | 645 | ): |
644 | 646 | json_response = {} |
645 | 647 | json_response["status"] = [] |
646 | | - approval_type = ApprovalType.Primary if is_primary_approver else ApprovalType.Secondary |
| 648 | + approval_type = ( |
| 649 | + ApprovalType.Primary if is_primary_approver else ApprovalType.Secondary |
| 650 | + ) |
647 | 651 | json_response["msg"] = REQUEST_PROCESS_MSG.format(request_id=request_id) |
648 | 652 |
|
649 | | - with transaction.atomic(): |
650 | | - try: |
651 | | - accept_request(user_access_mapping=access_mapping, approval_type=approval_type, approver = auth_user.user) |
652 | | - except Exception as e: |
653 | | - logger.exception(e) |
654 | | - raise Exception( |
655 | | - "Error in accepting the request - {request_id}. Please try again.".format( |
656 | | - request_id=request_id |
657 | | - ) |
| 653 | + try: |
| 654 | + access_mapping.processing(approval_type=approval_type, approver=auth_user.user) |
| 655 | + except Exception as e: |
| 656 | + logger.exception(e) |
| 657 | + raise Exception( |
| 658 | + "Error in accepting the request - {request_id}. Please try again.".format( |
| 659 | + request_id=request_id |
658 | 660 | ) |
659 | | - |
| 661 | + ) |
| 662 | + accept_request(access_mapping) |
660 | 663 | json_response["status"].append( |
661 | 664 | { |
662 | 665 | "title": REQUEST_SUCCESS_MSG["title"].format(request_id=request_id), |
@@ -882,9 +885,8 @@ def create_error_response(error_msg): |
882 | 885 |
|
883 | 886 |
|
884 | 887 | def is_valid_approver(auth_user, group_mapping, approver_permissions): |
885 | | - is_primary_approver = ( |
886 | | - group_mapping.is_pending() |
887 | | - and auth_user.user.has_permission(approver_permissions["1"]) |
| 888 | + is_primary_approver = group_mapping.is_pending() and auth_user.user.has_permission( |
| 889 | + approver_permissions["1"] |
888 | 890 | ) |
889 | 891 | is_secondary_approver = ( |
890 | 892 | group_mapping.is_secondary_pending() |
|
0 commit comments