Skip to content

Commit 4a1d60c

Browse files
authored
Merge pull request #93 from browserstack/feat-identity
fix: user identity fixes
2 parents d4d799e + 08f464c commit 4a1d60c

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

Access/accessrequest_helper.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,26 +385,26 @@ def create_request(auth_user, access_request_form):
385385
json_response["status_list"] = []
386386
extra_fields = get_extra_fields(access_request=access_request)
387387

388-
for index1, access_type in enumerate(access_request["accessRequests"]):
388+
for index1, access_tag in enumerate(access_request["accessRequests"]):
389389
access_labels = validate_access_labels(
390390
access_labels_json=access_request["accessLabel"][index1],
391-
access_tag=access_type,
391+
access_tag=access_tag,
392392
)
393393
access_reason = access_request["accessReason"][index1]
394394

395395
request_id = (
396396
auth_user.username
397397
+ "-"
398-
+ access_type
398+
+ access_tag
399399
+ "-"
400400
+ datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S")
401401
)
402-
json_response[access_type] = {
402+
json_response[access_tag] = {
403403
"requestId": request_id,
404404
"dateTime": current_date_time,
405405
}
406406

407-
access_module = helper.get_available_access_modules()[access_type]
407+
access_module = helper.get_available_access_modules()[access_tag]
408408
extra_field_labels = get_extra_field_labels(access_module)
409409
if extra_fields and extra_field_labels:
410410
for field in extra_field_labels:
@@ -420,7 +420,7 @@ def create_request(auth_user, access_request_form):
420420
access_create_error = _create_access(
421421
auth_user=auth_user,
422422
access_label=access_label,
423-
access_type=access_type,
423+
access_tag=access_tag,
424424
request_id=request_id,
425425
access_reason=access_reason,
426426
)
@@ -453,17 +453,17 @@ def create_request(auth_user, access_request_form):
453453
return json_response
454454

455455

456-
def _create_access(auth_user, access_label, access_type, request_id, access_reason):
457-
user_identity = auth_user.user.get_active_identity(access_tag=access_type)
456+
def _create_access(auth_user, access_label, access_tag, request_id, access_reason):
457+
user_identity = auth_user.user.get_active_identity(access_tag=access_tag)
458458
if not user_identity:
459459
return {
460460
"title": REQUEST_IDENTITY_NOT_SETUP_ERR_MSG["error_msg"],
461461
"msg": REQUEST_IDENTITY_NOT_SETUP_ERR_MSG["msg"].format(
462-
access_tag=access_type
462+
access_tag=access_tag
463463
),
464464
}
465465

466-
access = AccessV2.get(access_type=access_type, access_label=access_label)
466+
access = AccessV2.get(access_tag=access_tag, access_label=access_label)
467467
if access:
468468
if user_identity.access_mapping_exists(access):
469469
return {
@@ -481,7 +481,7 @@ def _create_access(auth_user, access_label, access_type, request_id, access_reas
481481
user_identity=user_identity,
482482
request_id=request_id,
483483
access_label=access_label,
484-
access_type=access_type,
484+
access_tag=access_tag,
485485
access_reason=access_reason,
486486
)
487487
except Exception:
@@ -493,11 +493,11 @@ def _create_access(auth_user, access_label, access_type, request_id, access_reas
493493

494494
@transaction.atomic
495495
def _create_access_mapping(
496-
user_identity, access, request_id, access_type, access_label, access_reason
496+
user_identity, access, request_id, access_tag, access_label, access_reason
497497
):
498498
if not access:
499499
access = AccessV2.objects.create(
500-
access_tag=access_type, access_label=access_label
500+
access_tag=access_tag, access_label=access_label
501501
)
502502

503503
user_identity.user_access_mapping.create(

Access/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ def get_active_users_with_permission(permission_label):
308308
)
309309
except User.DoesNotExist:
310310
return None
311+
312+
@staticmethod
313+
def get_system_user():
314+
try:
315+
return User.objects.get(name="system_user")
316+
except User.DoesNotExist:
317+
django_user = user.objects.create(username="system_user")
318+
system_user = User.objects.create(email="[email protected]", user=django_user, name=django_user.username)
319+
return system_user
311320

312321
def __str__(self):
313322
return "%s" % (self.user)
@@ -1106,10 +1115,10 @@ def __str__(self):
11061115
return self.access_tag
11071116

11081117
@staticmethod
1109-
def get(access_type, access_label):
1118+
def get(access_tag, access_label):
11101119
try:
11111120
return AccessV2.objects.get(
1112-
access_tag=access_type, access_label=access_label
1121+
access_tag=access_tag, access_label=access_label
11131122
)
11141123
except AccessV2.DoesNotExist:
11151124
return None

Access/userlist_helper.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def get_identity_templates(auth_user):
6363
all_modules.pop(user_identity.access_tag)
6464

6565
for mod in all_modules.values():
66+
if not mod.get_identity_template():
67+
if not auth_user.user.get_active_identity(mod.tag()):
68+
auth_user.user.create_new_identity(
69+
access_tag=mod.tag(), identity={}
70+
)
71+
continue
6672
context["unconfigured_identity_template"].append(
6773
{
6874
"accessUserTemplatePath": mod.get_identity_template(),
@@ -94,12 +100,12 @@ def create_identity(user_identity_form, auth_user):
94100
existing_user_identity = user.get_active_identity(
95101
access_tag=selected_access_module.tag()
96102
)
97-
if new_module_identity_json == existing_user_identity.identity:
98-
raise IdentityNotChangedException()
99103
existing_user_access_mapping = None
100104

101105
# get useraccess if an identity already exists
102106
if existing_user_identity:
107+
if new_module_identity_json == existing_user_identity.identity:
108+
raise IdentityNotChangedException()
103109
existing_user_access_mapping = (
104110
existing_user_identity.get_active_access_mapping()
105111
)
@@ -142,19 +148,20 @@ def __change_identity_and_transfer_access_mapping(
142148
)
143149
# replicate the memberships with new identity
144150
new_user_access_mapping = []
145-
if existing_user_access_mapping:
146-
new_user_access_mapping = (
147-
new_user_identity.replicate_active_access_membership_for_module(
148-
existing_access=existing_user_access_mapping
151+
if existing_user_identity:
152+
if existing_user_access_mapping:
153+
new_user_access_mapping = (
154+
new_user_identity.replicate_active_access_membership_for_module(
155+
existing_access=existing_user_access_mapping
156+
)
149157
)
150-
)
151-
system_user = User.get_system_user()
158+
system_user = User.get_system_user()
152159

153-
for mapping in existing_user_access_mapping:
154-
if mapping.is_approved():
155-
revoke_request(user_access_mapping=mapping, revoker=system_user)
160+
for mapping in existing_user_access_mapping:
161+
if mapping.is_approved():
162+
revoke_request(user_access_mapping=mapping, revoker=system_user)
156163

157-
existing_user_identity.decline_all_non_approved_access_mappings("Identity Updated")
164+
existing_user_identity.decline_all_non_approved_access_mappings("Identity Updated")
158165

159166
for mapping in new_user_access_mapping:
160167
if mapping.is_processing() or mapping.is_grantfailed():

Access/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def individual_resolve(request):
652652
"error_msg": "Bad request",
653653
"msg": "Error in request not found OR Invalid request type",
654654
}
655-
return render(request, "BSOps/accessStatus.html", json_response)
655+
return render(request, "EnigmaOps/accessStatus.html", json_response)
656656

657657

658658
@login_required
@@ -689,7 +689,7 @@ def ignore_failure(request, selector):
689689
"msg": "The request is already in final state.",
690690
}
691691
)
692-
return render(request, "BSOps/accessStatus.html", json_response)
692+
return render(request, "EnigmaOps/accessStatus.html", json_response)
693693
except Exception as e:
694694
logger.debug("Error in request not found OR Invalid request type")
695695
logger.exception(e)
@@ -698,7 +698,7 @@ def ignore_failure(request, selector):
698698
"error_msg": str(e),
699699
"msg": "Error in request not found OR Invalid request type",
700700
}
701-
return render(request, "BSOps/accessStatus.html", json_response)
701+
return render(request, "EnigmaOps/accessStatus.html", json_response)
702702

703703

704704
@login_required
@@ -727,7 +727,7 @@ def resolve_bulk(request):
727727
"msg": "The request is already in final state.",
728728
}
729729
)
730-
return render(request, "BSOps/accessStatus.html", json_response)
730+
return render(request, "EnigmaOps/accessStatus.html", json_response)
731731
except Exception as e:
732732
logger.debug("Error in request not found OR Invalid request type")
733733
logger.exception(e)

templates/updateUser.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ <h2 class="h5 no-margin-bottom">Update User Info: {{request.user}}</h2>
7272
$('#' + formId).find('#success-msg').text("")
7373
error_message = "There was an error in updating User Identity for module " + modName + ". Please contact Admin"
7474
$.ajax({
75-
url : "{% url 'saveIdentity' %}/", // the endpoint
75+
url : "{% url 'saveIdentity' %}", // the endpoint
7676
type : "POST", // http method
7777
data : $('#' + formId).serialize(),
7878

0 commit comments

Comments
 (0)