Skip to content

Commit 530e3c4

Browse files
committed
Check has_permission for staff area
Instead of `has_role`. This replaces the remaining checks against the `StaffAreaAdministrator` role to access the staff area.
1 parent 0a39ffe commit 530e3c4

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

applications/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
from django.views.generic import CreateView, RedirectView, UpdateView, View
1010

1111
from jobserver.authorization import (
12-
StaffAreaAdministrator,
1312
has_permission,
14-
has_role,
1513
permissions,
1614
)
1715
from jobserver.hash_utils import unhash_or_404
@@ -192,7 +190,9 @@ def page(request, pk_hash, key):
192190
# check the user can access this application
193191
validate_application_access(request.user, application)
194192

195-
if application.approved_at and not has_role(request.user, StaffAreaAdministrator):
193+
if application.approved_at and not has_permission(
194+
request.user, permissions.staff_area_access
195+
):
196196
messages.warning(
197197
request, "This application has been approved and can no longer be edited"
198198
)

jobserver/context_processors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from django.urls import reverse
77
from furl import furl
88

9-
from .authorization import StaffAreaAdministrator, has_role
9+
from jobserver.authorization import has_permission, permissions
10+
1011
from .models import Backend, SiteAlert
1112
from .nav import NavItem, iter_nav
1213

@@ -31,7 +32,9 @@ def in_production(request):
3132

3233
def can_view_staff_area(request):
3334
user = getattr(request, "user", None) or AnonymousUser()
34-
return {"user_can_view_staff_area": has_role(user, StaffAreaAdministrator)}
35+
return {
36+
"user_can_view_staff_area": has_permission(user, permissions.staff_area_access)
37+
}
3538

3639

3740
def disable_creating_jobs(request):

jobserver/views/job_requests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
from .. import honeycomb
2222
from ..authorization import (
23-
StaffAreaAdministrator,
2423
has_permission,
25-
has_role,
2624
permissions,
2725
)
2826
from ..backends import backends_to_choices
@@ -321,7 +319,9 @@ def get(self, request, *args, **kwargs):
321319
can_cancel_jobs = job_request.created_by == request.user or has_permission(
322320
request.user, permissions.job_cancel, project=job_request.workspace.project
323321
)
324-
honeycomb_can_view_links = has_role(self.request.user, StaffAreaAdministrator)
322+
honeycomb_can_view_links = has_permission(
323+
self.request.user, permissions.staff_area_access
324+
)
325325

326326
# build up is_missing_updates to define if we've not seen the backend
327327
# running this JobRequest for a while.

jobserver/views/jobs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
from .. import honeycomb
1010
from ..authorization import (
11-
StaffAreaAdministrator,
1211
has_permission,
13-
has_role,
1412
permissions,
1513
)
1614
from ..models import Job, JobRequest
@@ -62,7 +60,9 @@ def get(self, request, *args, **kwargs):
6260
project=job.job_request.workspace.project,
6361
)
6462

65-
honeycomb_can_view_links = has_role(self.request.user, StaffAreaAdministrator)
63+
honeycomb_can_view_links = has_permission(
64+
self.request.user, permissions.staff_area_access
65+
)
6666

6767
# we need all HTML to be in HTML files, so we built this here and make
6868
# use of it in the template rather than looking it up with a templatetag

jobserver/views/workspaces.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
from django.views.generic import CreateView, FormView, ListView, View
1414

1515
from ..authorization import (
16-
StaffAreaAdministrator,
1716
has_permission,
18-
has_role,
1917
permissions,
2018
)
2119
from ..forms import (
@@ -201,7 +199,9 @@ def get(self, request, *args, **kwargs):
201199
# Should we show the admin section in the UI?
202200
show_admin = can_archive_workspace or can_toggle_notifications
203201

204-
honeycomb_can_view_links = has_role(self.request.user, StaffAreaAdministrator)
202+
honeycomb_can_view_links = has_permission(
203+
self.request.user, permissions.staff_area_access
204+
)
205205

206206
outputs = self.get_output_permissions(workspace)
207207

staff/views/job_requests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from django.utils.decorators import method_decorator
44
from django.views.generic import DetailView, ListView
55

6-
from jobserver.authorization import StaffAreaAdministrator
7-
from jobserver.authorization.decorators import require_permission
6+
from jobserver.authorization.decorators import (
7+
has_permission,
8+
require_permission,
9+
)
810
from jobserver.authorization.permissions import staff_area_access
9-
from jobserver.authorization.utils import has_role
1011
from jobserver.models import Backend, JobRequest, Org, Project, User, Workspace
1112
from jobserver.views.job_requests import JobRequestCancel as BaseJobRequestCancel
1213

@@ -16,7 +17,7 @@
1617
@method_decorator(require_permission(staff_area_access), name="dispatch")
1718
class JobRequestCancel(BaseJobRequestCancel):
1819
def user_has_permission_to_cancel(self, request):
19-
return has_role(request.user, StaffAreaAdministrator)
20+
return has_permission(request.user, staff_area_access)
2021

2122
def redirect(self):
2223
return redirect(self.job_request.get_staff_url())

tests/unit/jobserver/test_nav.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from jobserver.authorization import StaffAreaAdministrator, has_role
3+
from jobserver.authorization import StaffAreaAdministrator, has_permission, permissions
44
from jobserver.nav import NavItem, iter_nav
55

66
from ...factories import UserFactory
@@ -71,7 +71,9 @@ def test_iter_nav_optional_items(rf, roles, expected):
7171
NavItem(
7272
name="Only Shown for CoreDevs",
7373
url_name="staff:user-list",
74-
predicate=lambda request: has_role(request.user, StaffAreaAdministrator),
74+
predicate=lambda request: has_permission(
75+
request.user, permissions.staff_area_access
76+
),
7577
),
7678
]
7779

0 commit comments

Comments
 (0)