This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from django.contrib import admin | ||
|
||
from backoffice.management.permissions import IsAdminOrCuratorUser | ||
|
||
from .models import Workflow | ||
|
||
|
||
class WorkflowsAdminSite(admin.AdminSite): | ||
""" | ||
Custom admin site for managing workflows. | ||
This admin site extends the default Django admin site to include additional | ||
functionality for managing workflows. It checks whether the user has the | ||
necessary permissions to access the admin site by verifying that they are | ||
an active user and either a superuser or a member of the 'curator' group. | ||
Attributes: | ||
None | ||
Methods: | ||
has_permission(request): Checks whether the user has permission to access | ||
the admin site. | ||
""" | ||
|
||
def has_permission(self, request): | ||
return request.user.is_active and ( | ||
request.user.is_superuser or request.user.groups.filter(name="curator").exists() | ||
) | ||
|
||
|
||
class WorkflowAdmin(admin.ModelAdmin): | ||
""" | ||
Admin class for Workflow model. Define get, update and delete permissions. | ||
""" | ||
|
||
def has_view_permission(self, request, obj=None): | ||
""" | ||
Returns True if the user has permission to view the Workflow model. | ||
""" | ||
permission_check = IsAdminOrCuratorUser() | ||
return request.user.is_superuser or permission_check.has_permission(request, self) | ||
|
||
def has_change_permission(self, request, obj=None): | ||
""" | ||
Returns True if the user has permission to change the Workflow model. | ||
""" | ||
permission_check = IsAdminOrCuratorUser() | ||
return request.user.is_superuser or permission_check.has_permission(request, self) | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
""" | ||
Returns True if the user has permission to delete the Workflow model. | ||
""" | ||
permission_check = IsAdminOrCuratorUser() | ||
return request.user.is_superuser or permission_check.has_permission(request, self) | ||
|
||
|
||
admin.site.register(Workflow) | ||
workflow_admin_site = WorkflowsAdminSite(name="backoffice_admin") | ||
workflow_admin_site.register(Workflow, WorkflowAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
from django.contrib import admin | ||
from django.urls import include, path | ||
|
||
urlpatterns = [ | ||
path("workflows/", include("workflows.urls")), | ||
path("admin/", admin.site.urls), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters