Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
add workflows to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
MJedr committed Nov 13, 2023
1 parent 1067b0f commit 514f1da
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
60 changes: 60 additions & 0 deletions backoffice/workflows/admin.py
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)
2 changes: 0 additions & 2 deletions backoffice/workflows/urls.py
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),
]
3 changes: 3 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from rest_framework.authtoken.views import obtain_auth_token

from backoffice.workflows.admin import workflow_admin_site

urlpatterns = [
path("dashboard/", workflow_admin_site.urls),
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
path("about/", TemplateView.as_view(template_name="pages/about.html"), name="about"),
# Django Admin, use {% url 'admin:index' %}
Expand Down

0 comments on commit 514f1da

Please sign in to comment.