From 473b04e50a567600dcfb48037225142f3aab9fe7 Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 1 Oct 2024 10:22:10 +0200 Subject: [PATCH] :fire: [#390] Remove role model --- .../src/openarchiefbeheer/accounts/admin.py | 19 +------ .../accounts/api/serializers.py | 5 +- .../openarchiefbeheer/accounts/managers.py | 6 --- .../0006_remove_user_role_delete_role.py | 20 ++++++++ .../src/openarchiefbeheer/accounts/models.py | 50 ------------------- .../src/openarchiefbeheer/fixtures/roles.json | 36 ------------- 6 files changed, 23 insertions(+), 113 deletions(-) create mode 100644 backend/src/openarchiefbeheer/accounts/migrations/0006_remove_user_role_delete_role.py delete mode 100644 backend/src/openarchiefbeheer/fixtures/roles.json diff --git a/backend/src/openarchiefbeheer/accounts/admin.py b/backend/src/openarchiefbeheer/accounts/admin.py index c3c41f2b4..d615d288c 100644 --- a/backend/src/openarchiefbeheer/accounts/admin.py +++ b/backend/src/openarchiefbeheer/accounts/admin.py @@ -3,10 +3,9 @@ from django.contrib.auth.admin import UserAdmin as _UserAdmin from django.core.exceptions import PermissionDenied, ValidationError from django.urls import reverse_lazy -from django.utils.translation import gettext_lazy as _ from .forms import PreventPrivilegeEscalationMixin, UserChangeForm -from .models import Role, User +from .models import User from .utils import validate_max_user_permissions @@ -14,7 +13,6 @@ class UserAdmin(_UserAdmin): hijack_success_url = reverse_lazy("root") form = UserChangeForm - list_display = _UserAdmin.list_display + ("role",) def get_form(self, request, obj=None, **kwargs): ModelForm = super().get_form(request, obj, **kwargs) @@ -34,18 +32,3 @@ def user_change_password(self, request, id, form_url=""): raise PermissionDenied from exc return super().user_change_password(request, id, form_url) - - def get_fieldsets(self, request, obj=None): - fieldsets = super().get_fieldsets(request, obj) - return tuple(fieldsets) + ((_("Role"), {"fields": ("role",)}),) - - -@admin.register(Role) -class RoleAdmin(admin.ModelAdmin): - list_display = ( - "name", - "can_start_destruction", - "can_review_destruction", - "can_view_case_details", - "can_review_final_list", - ) diff --git a/backend/src/openarchiefbeheer/accounts/api/serializers.py b/backend/src/openarchiefbeheer/accounts/api/serializers.py index f9978b5a1..097780837 100644 --- a/backend/src/openarchiefbeheer/accounts/api/serializers.py +++ b/backend/src/openarchiefbeheer/accounts/api/serializers.py @@ -1,11 +1,10 @@ from rest_framework import serializers -from ..models import Role, User +from ..models import User -class RoleSerializer(serializers.ModelSerializer): +class RoleSerializer(serializers.Serializer): class Meta: - model = Role fields = ( "name", "can_start_destruction", diff --git a/backend/src/openarchiefbeheer/accounts/managers.py b/backend/src/openarchiefbeheer/accounts/managers.py index a4dab7b94..70d0a45c4 100644 --- a/backend/src/openarchiefbeheer/accounts/managers.py +++ b/backend/src/openarchiefbeheer/accounts/managers.py @@ -32,9 +32,3 @@ def create_superuser(self, username, email, password, **extra_fields): raise ValueError("Superuser must have is_superuser=True.") return self._create_user(username, email, password, **extra_fields) - - def reviewers(self): - return self.select_related("role").filter(role__can_review_destruction=True) - - def archivists(self): - return self.select_related("role").filter(role__can_review_final_list=True) diff --git a/backend/src/openarchiefbeheer/accounts/migrations/0006_remove_user_role_delete_role.py b/backend/src/openarchiefbeheer/accounts/migrations/0006_remove_user_role_delete_role.py new file mode 100644 index 000000000..772f84181 --- /dev/null +++ b/backend/src/openarchiefbeheer/accounts/migrations/0006_remove_user_role_delete_role.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.15 on 2024-09-30 12:55 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0005_add_users_to_groups"), + ] + + operations = [ + migrations.RemoveField( + model_name="user", + name="role", + ), + migrations.DeleteModel( + name="Role", + ), + ] diff --git a/backend/src/openarchiefbeheer/accounts/models.py b/backend/src/openarchiefbeheer/accounts/models.py index 9c9257e36..f67dc0e54 100644 --- a/backend/src/openarchiefbeheer/accounts/models.py +++ b/backend/src/openarchiefbeheer/accounts/models.py @@ -43,13 +43,6 @@ class User(AbstractBaseUser, PermissionsMixin): ), ) date_joined = models.DateTimeField(_("date joined"), default=timezone.now) - role = models.ForeignKey( - "accounts.Role", - on_delete=models.SET_NULL, - blank=True, - null=True, - verbose_name=_("role"), - ) objects = UserManager() @@ -70,46 +63,3 @@ def get_full_name(self): def get_short_name(self): "Returns the short name for the user." return self.first_name - - -class Role(models.Model): - name = models.CharField( - _("name"), max_length=255, unique=True, help_text=_("Name of the role") - ) - can_start_destruction = models.BooleanField( - _("can start destruction"), - default=False, - help_text=_( - "Indicates whether a user can create a list of cases to be deleted." - ), - ) - can_review_final_list = models.BooleanField( - _("can review final list"), - default=False, - help_text=_( - "Indicates whether a user is an 'archivist'. " - "This user can only review lists that have been marked as 'final'." - ), - ) - can_review_destruction = models.BooleanField( - _("can review destruction"), - default=False, - help_text=_( - "Indicates whether a user can review a list of cases to be deleted. " - "They can approve it, reject it or provide feedback." - ), - ) - can_view_case_details = models.BooleanField( - _("can view case details"), - default=False, - help_text=_( - "Indicates whether a user can view the contents of cases in a lists." - ), - ) - - class Meta: - verbose_name = _("role") - verbose_name_plural = _("roles") - - def __str__(self): - return self.name diff --git a/backend/src/openarchiefbeheer/fixtures/roles.json b/backend/src/openarchiefbeheer/fixtures/roles.json deleted file mode 100644 index 796cdb3c1..000000000 --- a/backend/src/openarchiefbeheer/fixtures/roles.json +++ /dev/null @@ -1,36 +0,0 @@ -[ - { - "model": "accounts.role", - "pk": 1, - "fields": { - "name": "Record manager", - "can_start_destruction": true, - "can_review_final_list": false, - "can_review_destruction": false, - "can_view_case_details": false - } - }, - { - "model": "accounts.role", - "pk": 2, - "fields": { - "name": "Reviewer", - "can_start_destruction": false, - "can_review_final_list": false, - "can_review_destruction": true, - "can_view_case_details": false - } - }, - { - "model": "accounts.role", - "pk": 3, - "fields": { - "name": "Admin", - "can_start_destruction": true, - "can_review_final_list": false, - "can_review_destruction": true, - "can_view_case_details": true - } - } -] - \ No newline at end of file