From 39013e0bb5dbde29b092df64f896180745532a62 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 20 Dec 2022 09:01:54 +0000 Subject: [PATCH] Add moderation/admin separation --- static/css/style.css | 10 +++++++-- templates/settings/_menu.html | 39 ++++++++++++++++++--------------- users/decorators.py | 6 +++++ users/views/admin/federation.py | 6 ++--- users/views/admin/hashtags.py | 10 ++++----- users/views/admin/identities.py | 6 ++--- users/views/admin/invites.py | 8 +++---- users/views/admin/reports.py | 6 ++--- 8 files changed, 53 insertions(+), 38 deletions(-) diff --git a/static/css/style.css b/static/css/style.css index 3a59380..907d0fe 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -93,14 +93,12 @@ td a { --color-text-dull: #99a; --color-text-main: #fff; --color-text-link: rgb(176, 194, 206); - --color-text-error: #f44336; --color-input-border: #000; --color-input-border-active: #444b5d; --color-button-main: #444b5d; --color-button-main-hover: #515d7c; --color-button-disabled: #7c9c97; - --color-bg3: #444b5d; } body { @@ -281,6 +279,14 @@ nav a.selected:hover { border-left: 3px solid transparent; } +nav a.danger { + color: var(--color-text-duller); +} + +nav a.danger:hover { + color: var(--color-text-dull); +} + nav a i { width: 20px; text-align: center; diff --git a/templates/settings/_menu.html b/templates/settings/_menu.html index 45b7ee3..aa05365 100644 --- a/templates/settings/_menu.html +++ b/templates/settings/_menu.html @@ -13,23 +13,8 @@ Logout - {% if request.user.admin %} -

Administration

- - Basic - - - Policies - - - Domains - - - Federation - - - Users - + {% if request.user.moderator or request.user.admin %} +

Moderation

Identities @@ -42,10 +27,28 @@ Reports + + Federation + + {% endif %} + {% if request.user.admin %} +

Administration

+ + Basic + + + Policies + + + Domains + + + Users + Stator - + Django Admin {% endif %} diff --git a/users/decorators.py b/users/decorators.py index 26778ec..395488b 100644 --- a/users/decorators.py +++ b/users/decorators.py @@ -29,5 +29,11 @@ def identity_required(function): return inner +def moderator_required(function): + return user_passes_test( + lambda user: user.is_authenticated and (user.admin or user.moderator) + )(function) + + def admin_required(function): return user_passes_test(lambda user: user.is_authenticated and user.admin)(function) diff --git a/users/views/admin/federation.py b/users/views/admin/federation.py index 0611b9e..8850efa 100644 --- a/users/views/admin/federation.py +++ b/users/views/admin/federation.py @@ -4,11 +4,11 @@ from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator from django.views.generic import FormView, ListView -from users.decorators import admin_required +from users.decorators import moderator_required from users.models import Domain -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class FederationRoot(ListView): template_name = "admin/federation.html" @@ -33,7 +33,7 @@ class FederationRoot(ListView): return domains -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class FederationEdit(FormView): template_name = "admin/federation_edit.html" diff --git a/users/views/admin/hashtags.py b/users/views/admin/hashtags.py index 90f7a84..cdde6c5 100644 --- a/users/views/admin/hashtags.py +++ b/users/views/admin/hashtags.py @@ -4,10 +4,10 @@ from django.utils.decorators import method_decorator from django.views.generic import FormView, TemplateView from activities.models import Hashtag, HashtagStates -from users.decorators import admin_required +from users.decorators import moderator_required -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class Hashtags(TemplateView): template_name = "admin/hashtags.html" @@ -19,7 +19,7 @@ class Hashtags(TemplateView): } -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class HashtagCreate(FormView): template_name = "admin/hashtag_create.html" @@ -68,7 +68,7 @@ class HashtagCreate(FormView): return redirect(Hashtag.urls.root) -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class HashtagEdit(FormView): template_name = "admin/hashtag_edit.html" @@ -106,7 +106,7 @@ class HashtagEdit(FormView): } -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class HashtagDelete(TemplateView): template_name = "admin/hashtag_delete.html" diff --git a/users/views/admin/identities.py b/users/views/admin/identities.py index d094978..1fc89d3 100644 --- a/users/views/admin/identities.py +++ b/users/views/admin/identities.py @@ -4,11 +4,11 @@ from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator from django.views.generic import FormView, ListView -from users.decorators import admin_required +from users.decorators import moderator_required from users.models import Identity, IdentityStates -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class IdentitiesRoot(ListView): template_name = "admin/identities.html" @@ -46,7 +46,7 @@ class IdentitiesRoot(ListView): return identities -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class IdentityEdit(FormView): template_name = "admin/identity_edit.html" diff --git a/users/views/admin/invites.py b/users/views/admin/invites.py index 2a68221..338763a 100644 --- a/users/views/admin/invites.py +++ b/users/views/admin/invites.py @@ -3,11 +3,11 @@ from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator from django.views.generic import FormView, ListView -from users.decorators import admin_required +from users.decorators import moderator_required from users.models import Invite -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class InvitesRoot(ListView): template_name = "admin/invites.html" @@ -23,7 +23,7 @@ class InvitesRoot(ListView): return Invite.objects.order_by("created") -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class InviteCreate(FormView): template_name = "admin/invite_create.html" @@ -47,7 +47,7 @@ class InviteCreate(FormView): return redirect(invite.urls.admin) -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class InviteView(FormView): template_name = "admin/invite_view.html" diff --git a/users/views/admin/reports.py b/users/views/admin/reports.py index 6187068..3d22dd5 100644 --- a/users/views/admin/reports.py +++ b/users/views/admin/reports.py @@ -4,11 +4,11 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import FormView, ListView -from users.decorators import admin_required +from users.decorators import moderator_required from users.models import Identity, Report -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class ReportsRoot(ListView): template_name = "admin/reports.html" @@ -32,7 +32,7 @@ class ReportsRoot(ListView): return reports -@method_decorator(admin_required, name="dispatch") +@method_decorator(moderator_required, name="dispatch") class ReportView(FormView): template_name = "admin/report_view.html"