Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by global roles #4728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions jobserver/authorization/global_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ..models import User
from .utils import roles_for


# A global role can be assigned to a User independently of ProjectMembership.
# It either does not relate to Projects or grants permissions across ALL projects.

GLOBAL_ROLES = roles_for(User)

GLOBAL_ROLE_NAMES = [role.__name__ for role in GLOBAL_ROLES]
9 changes: 3 additions & 6 deletions staff/views/users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import inspect

import structlog
from django.core.exceptions import FieldError
from django.db import transaction
Expand All @@ -14,9 +12,10 @@
from interactive.commands import create_user
from interactive.emails import send_welcome_email
from jobserver.auditing.presenters.lookup import get_presenter
from jobserver.authorization import permissions, roles
from jobserver.authorization import permissions
from jobserver.authorization.decorators import require_permission
from jobserver.authorization.forms import RolesForm
from jobserver.authorization.global_roles import GLOBAL_ROLE_NAMES
from jobserver.authorization.utils import roles_for, strings_to_roles
from jobserver.commands import users
from jobserver.models import (
Expand Down Expand Up @@ -243,14 +242,12 @@ class UserList(ListView):
queryset = User.objects.prefetch_related("project_memberships", "org_memberships")

def get_context_data(self, **kwargs):
all_roles = [name for name, value in inspect.getmembers(roles, inspect.isclass)]

return super().get_context_data(**kwargs) | {
"backends": Backend.objects.order_by("slug"),
"missing_names": ["backend", "org", "project"],
"orgs": Org.objects.order_by("name"),
"q": self.request.GET.get("q", ""),
"roles": all_roles,
"roles": GLOBAL_ROLE_NAMES,
}

def get_queryset(self):
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/jobserver/authorization/test_global_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from jobserver.authorization.global_roles import GLOBAL_ROLE_NAMES


def test_global_role_names():
assert set(GLOBAL_ROLE_NAMES) & set(
[
"DeploymentAdministrator",
"InteractiveReporter",
"OutputChecker",
"OutputPublisher",
"ProjectCollaborator",
"SignOffRepoWithOutputs",
"StaffAreaAdministrator",
]
)