Skip to content

Commit

Permalink
🔥 [#390] Remove role model
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Oct 1, 2024
1 parent 776aab3 commit 473b04e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 113 deletions.
19 changes: 1 addition & 18 deletions backend/src/openarchiefbeheer/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
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


@admin.register(User)
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)
Expand All @@ -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",
)
5 changes: 2 additions & 3 deletions backend/src/openarchiefbeheer/accounts/api/serializers.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 0 additions & 6 deletions backend/src/openarchiefbeheer/accounts/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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",
),
]
50 changes: 0 additions & 50 deletions backend/src/openarchiefbeheer/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
36 changes: 0 additions & 36 deletions backend/src/openarchiefbeheer/fixtures/roles.json

This file was deleted.

0 comments on commit 473b04e

Please sign in to comment.