Skip to content

Commit 9cb2501

Browse files
authored
Merge pull request #1133 from NHSDigital/add-back-admin
Add back admin
2 parents bca75d7 + ceba78f commit 9cb2501

File tree

19 files changed

+228
-106
lines changed

19 files changed

+228
-106
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ There is a make task to seed a non-production instance of the service with examp
107107

108108
This command wipes the database entirely before populating it with fictitious data. The data is contained in yaml files in the [data directory](/data) and can be amended etc there as required.
109109

110+
### Django admin
111+
112+
Django admin is enabled at `http://localhost:8000/admin`
113+
114+
You must be logged in as a superuser to access it.
115+
110116
## Design
111117

112118
The service will be deployed as a web application, backed by a postgres database with authentication provided by NHS CIS2. In addtion to these elements we will deploy a gateway application to each breast screening unit that uses the service that will be responsible for interop with local hospital systems. The gateway will be developed in a future phase of this project and is not currently under active development.

manage_breast_screening/auth/demo_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def persona_login(request):
4444
"auth/persona_login.jinja",
4545
context={
4646
"providers_with_users": _get_providers_with_users(request.user),
47-
"sysadmin_users": _get_sysadmin_users(request.user),
47+
"superusers": _get_superusers(request.user),
4848
"page_title": "Persona logins",
4949
"next": next_path,
5050
},
@@ -71,7 +71,7 @@ def _user_entry(user, current_user):
7171

7272
def _get_providers_with_users(current_user):
7373
providers = OrderedDict()
74-
for user in _persona_users(current_user).filter(is_sysadmin=False):
74+
for user in _persona_users(current_user).filter(is_superuser=False):
7575
entry = _user_entry(user, current_user)
7676
for assignment in user.assignments.all():
7777
provider = assignment.provider
@@ -88,9 +88,9 @@ def _get_providers_with_users(current_user):
8888
).values()
8989

9090

91-
def _get_sysadmin_users(current_user):
91+
def _get_superusers(current_user):
9292
return [
9393
_user_entry(user, current_user)
9494
for user in _persona_users(current_user)
95-
if user.is_sysadmin
95+
if user.is_superuser
9696
]

manage_breast_screening/auth/jinja2/auth/persona_login.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
{% endfor %}
5656
{% endfor %}
5757

58-
{% if sysadmin_users %}
59-
<h2 class="nhsuk-heading-m">Sysadmin</h2>
60-
{{ persona_summary_list(sysadmin_users, "Sysadmin") }}
58+
{% if superusers %}
59+
<h2 class="nhsuk-heading-m">Superuser</h2>
60+
{{ persona_summary_list(superusers, "Superuser") }}
6161
{% endif %}
6262
</form>
6363
</div>

manage_breast_screening/auth/management/commands/create_personas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def handle(self, *args, **options):
3333
defaults={
3434
"first_name": persona.first_name,
3535
"last_name": persona.last_name,
36-
"is_sysadmin": persona.is_sysadmin,
36+
"is_superuser": persona.is_superuser,
37+
"is_staff": persona.is_superuser,
3738
},
3839
)
3940
UserAssignment.objects.create(

manage_breast_screening/auth/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Persona:
1919
first_name: str
2020
last_name: str
2121
role: str
22-
is_sysadmin: bool = False
22+
is_superuser: bool = False
2323

2424
@property
2525
def username(self):
@@ -28,7 +28,7 @@ def username(self):
2828

2929
ADMINISTRATIVE_PERSONA = Persona("Anna", "Davies", Role.ADMINISTRATIVE)
3030
CLINICAL_PERSONA = Persona("Chloë", "Robinson", Role.CLINICAL)
31-
SYSADMIN_PERSONA = Persona("Priya", "Bains", Role.ADMINISTRATIVE, is_sysadmin=True)
31+
SYSADMIN_PERSONA = Persona("Priya", "Bains", Role.ADMINISTRATIVE, is_superuser=True)
3232
PERSONAS = [
3333
ADMINISTRATIVE_PERSONA,
3434
CLINICAL_PERSONA,

manage_breast_screening/auth/rules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def is_administrative(user):
2020

2121

2222
@rules.predicate
23-
def is_sysadmin(user):
24-
return getattr(user, "is_sysadmin", False)
23+
def is_superuser(user):
24+
return getattr(user, "is_superuser", False)
2525

2626

2727
rules.add_perm(Permission.VIEW_PARTICIPANT_DATA, is_clinical | is_administrative)
28-
rules.add_perm(Permission.MANAGE_PROVIDER_SETTINGS, is_sysadmin)
28+
rules.add_perm(Permission.MANAGE_PROVIDER_SETTINGS, is_superuser)

manage_breast_screening/auth/tests/test_rules.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from manage_breast_screening.auth.rules import (
55
is_administrative,
66
is_clinical,
7-
is_sysadmin,
7+
is_superuser,
88
)
99
from manage_breast_screening.clinics.tests.factories import UserAssignmentFactory
1010
from manage_breast_screening.users.tests.factories import UserFactory
@@ -91,25 +91,25 @@ def test_returns_false_if_no_provider_given(self):
9191
@pytest.mark.django_db
9292
class TestIsSysadmin:
9393
def test_returns_true_for_sysadmin_user(self):
94-
user = UserFactory.create(is_sysadmin=True)
94+
user = UserFactory.create(is_superuser=True)
9595

96-
assert is_sysadmin(user)
96+
assert is_superuser(user)
9797

9898
def test_returns_false_for_non_sysadmin_user(self):
99-
user = UserFactory.create(is_sysadmin=False)
99+
user = UserFactory.create(is_superuser=False)
100100

101-
assert not is_sysadmin(user)
101+
assert not is_superuser(user)
102102

103103

104104
@pytest.mark.django_db
105105
class TestManageProviderSettingsPermission:
106106
def test_returns_true_for_sysadmin(self):
107-
user = UserFactory.create(is_sysadmin=True)
107+
user = UserFactory.create(is_superuser=True)
108108

109109
assert user.has_perm(Permission.MANAGE_PROVIDER_SETTINGS)
110110

111111
def test_returns_false_for_non_sysadmin(self):
112-
user = UserFactory.create(is_sysadmin=False)
112+
user = UserFactory.create(is_superuser=False)
113113

114114
assert not user.has_perm(Permission.MANAGE_PROVIDER_SETTINGS)
115115

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.contrib import admin
2+
3+
from manage_breast_screening.core.admin import admin_site
4+
5+
from .models import Clinic, ClinicSlot, Provider, Setting
6+
7+
8+
class ClinicAdmin(admin.ModelAdmin):
9+
readonly_fields = [
10+
"current_status_display",
11+
]
12+
13+
def current_status_display(self, obj):
14+
return obj.current_status.state
15+
16+
current_status_display.short_description = "Current Status"
17+
18+
19+
admin_site.register(Clinic, ClinicAdmin)
20+
admin_site.register(ClinicSlot)
21+
admin_site.register(Provider)
22+
admin_site.register(Setting)

manage_breast_screening/clinics/tests/test_views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def login_with_provider(client, user, provider):
8383
class TestProviderSettings:
8484
@pytest.mark.django_db
8585
def test_requires_sysadmin(self, client):
86-
user = UserFactory(is_sysadmin=False)
86+
user = UserFactory(is_superuser=False)
8787
provider = ProviderFactory()
8888
UserAssignmentFactory(user=user, provider=provider, administrative=True)
8989

@@ -96,7 +96,7 @@ def test_requires_sysadmin(self, client):
9696

9797
@pytest.mark.django_db
9898
def test_accessible_to_sysadmin(self, client):
99-
user = UserFactory(is_sysadmin=True)
99+
user = UserFactory(is_superuser=True)
100100
provider = ProviderFactory()
101101
UserAssignmentFactory(user=user, provider=provider)
102102

@@ -109,7 +109,7 @@ def test_accessible_to_sysadmin(self, client):
109109

110110
@pytest.mark.django_db
111111
def test_displays_provider_name(self, client):
112-
user = UserFactory(is_sysadmin=True)
112+
user = UserFactory(is_superuser=True)
113113
provider = ProviderFactory(name="Test Hospital Trust")
114114
UserAssignmentFactory(user=user, provider=provider)
115115

@@ -121,7 +121,7 @@ def test_displays_provider_name(self, client):
121121

122122
@pytest.mark.django_db
123123
def test_saves_settings(self, client):
124-
user = UserFactory(is_sysadmin=True)
124+
user = UserFactory(is_superuser=True)
125125
provider = ProviderFactory()
126126
UserAssignmentFactory(user=user, provider=provider)
127127
config = provider.get_config()
@@ -140,7 +140,7 @@ def test_saves_settings(self, client):
140140

141141
@pytest.mark.django_db
142142
def test_enables_manual_image_collection(self, client):
143-
user = UserFactory(is_sysadmin=True)
143+
user = UserFactory(is_superuser=True)
144144
provider = ProviderFactory()
145145
UserAssignmentFactory(user=user, provider=provider)
146146
config = provider.get_config()

manage_breast_screening/config/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def list_env(key):
6666
# Application definition
6767

6868
INSTALLED_APPS = [
69+
"django.contrib.admin",
6970
"django.contrib.auth",
7071
"django.contrib.contenttypes",
7172
"django.contrib.postgres",

0 commit comments

Comments
 (0)