Coverage for benefits/core/admin/enrollment.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 22:14 +0000

1from django.conf import settings 

2from django.contrib import admin 

3from django.http import HttpRequest 

4 

5from adminsortable2.admin import SortableAdminMixin 

6 

7from benefits.core import models 

8from .users import is_staff_member_or_superuser 

9 

10 

11@admin.register(models.EnrollmentEvent) 

12class EnrollmentEventAdmin(admin.ModelAdmin): # pragma: no cover 

13 list_display = ("enrollment_datetime", "transit_agency", "enrollment_flow", "enrollment_method", "verified_by") 

14 

15 def get_readonly_fields(self, request: HttpRequest, obj=None): 

16 return ["id"] 

17 

18 def has_add_permission(self, request: HttpRequest, obj=None): 

19 if settings.RUNTIME_ENVIRONMENT() == settings.RUNTIME_ENVS.PROD: 

20 return False 

21 elif request.user and is_staff_member_or_superuser(request.user): 

22 return True 

23 else: 

24 return False 

25 

26 def has_change_permission(self, request: HttpRequest, obj=None): 

27 if settings.RUNTIME_ENVIRONMENT() == settings.RUNTIME_ENVS.PROD: 

28 return False 

29 elif request.user and request.user.is_superuser: 

30 return True 

31 else: 

32 return False 

33 

34 def has_delete_permission(self, request: HttpRequest, obj=None): 

35 if settings.RUNTIME_ENVIRONMENT() == settings.RUNTIME_ENVS.PROD: 

36 return False 

37 elif request.user and is_staff_member_or_superuser(request.user): 

38 return True 

39 else: 

40 return False 

41 

42 def has_view_permission(self, request: HttpRequest, obj=None): 

43 if request.user and is_staff_member_or_superuser(request.user): 

44 return True 

45 else: 

46 return False 

47 

48 

49@admin.register(models.EnrollmentFlow) 

50class SortableEnrollmentFlowAdmin(SortableAdminMixin, admin.ModelAdmin): # pragma: no cover 

51 list_display = ("label", "transit_agency", "supported_enrollment_methods") 

52 

53 def get_exclude(self, request, obj=None): 

54 if not request.user.is_superuser: 

55 return [ 

56 "eligibility_api_auth_header", 

57 "eligibility_api_auth_key_secret_name", 

58 "eligibility_api_public_key", 

59 "eligibility_api_jwe_cek_enc", 

60 "eligibility_api_jwe_encryption_alg", 

61 "eligibility_api_jws_signing_alg", 

62 "eligibility_form_class", 

63 ] 

64 else: 

65 return super().get_exclude(request, obj) 

66 

67 def get_readonly_fields(self, request, obj=None): 

68 if not request.user.is_superuser: 

69 return [ 

70 "claims_provider", 

71 "eligibility_api_url", 

72 "eligibility_start_template_override", 

73 "eligibility_unverified_template_override", 

74 "help_template", 

75 "selection_label_template_override", 

76 "claims_scheme_override", 

77 "enrollment_index_template", 

78 "reenrollment_error_template", 

79 "enrollment_success_template_override", 

80 ] 

81 else: 

82 return super().get_readonly_fields(request, obj)