Skip to content

Commit

Permalink
remove our implementations of the Role and Permission model
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Jul 22, 2024
1 parent 062efbf commit 8bd1053
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 111 deletions.
6 changes: 3 additions & 3 deletions server/apps/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from apps.profile.models import Profile, RcrainfoProfile, RcrainfoSiteAccess

from .models import Permission, Role, TrakUser
from .models import GroupPermission, TrakUser, UserPermission


class HiddenListView(admin.ModelAdmin):
Expand Down Expand Up @@ -73,5 +73,5 @@ def api_user(self, profile: RcrainfoProfile) -> bool:

admin.site.register(Profile)
admin.site.unregister(DRFToken)
admin.site.register(Permission)
admin.site.register(Role)
admin.site.register(UserPermission)
admin.site.register(GroupPermission)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.6 on 2024-07-22 20:03

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0004_grouppermission_userpermission'),
]

operations = [
migrations.RemoveField(
model_name='role',
name='permissions',
),
migrations.DeleteModel(
name='Permission',
),
migrations.DeleteModel(
name='Role',
),
]
44 changes: 0 additions & 44 deletions server/apps/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.contrib.auth.models import AbstractUser, Group
from django.contrib.auth.models import Permission as DjangoPermission
from django.db import models
from django.utils.translation import gettext_lazy as _
from guardian.models import GroupObjectPermissionAbstract, UserObjectPermissionAbstract


Expand All @@ -22,49 +21,6 @@ class Meta:
)


class Permission(DjangoPermission):
"""Haztrak proxy permission model used for our custom object level permissions."""

class Meta:
proxy = True
verbose_name = "Permission"
verbose_name_plural = "Permissions"
ordering = ["name"]

@property
def app_label(self):
return self.content_type.app_label

@property
def model_name(self):
return self.content_type.model

def __str__(self):
return f"{self.content_type.name} | {self.name}"


class Role(models.Model):
"""A job/function within the system that can assigned to users to grant them permissions."""

class Meta:
verbose_name = _("Role")
verbose_name_plural = _("Roles")
ordering = ["name"]

name = models.CharField(
_("name"),
max_length=150,
unique=True,
)
permissions = models.ManyToManyField(
Permission,
verbose_name=_("permissions"),
)

def __str__(self):
return f"{self.name}"


class UserPermission(UserObjectPermissionAbstract):
"""
User object permission model for Haztrak.
Expand Down
22 changes: 0 additions & 22 deletions server/apps/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from typing import Dict, List, Optional

import pytest
from django.contrib.contenttypes.models import ContentType
from faker import Faker

from apps.core.models import Permission
from apps.rcrasite.models import RcraSiteType


Expand Down Expand Up @@ -42,23 +40,3 @@ def create_quicker_sign(
}

return create_quicker_sign


@pytest.fixture
def permission_factory(faker: Faker):
"""
Factory for creating dynamic permission data
"""

def create_permission(
name: str = faker.word(),
content_type_id: int = faker.random_int(min=1),
) -> Permission:
content_type = ContentType.objects.create(app_label=faker.word(), model=faker.word())
return Permission.objects.create(
name=name,
content_type=content_type,
content_type_id=content_type_id,
)

return create_permission
42 changes: 0 additions & 42 deletions server/apps/core/tests/test_models.py

This file was deleted.

0 comments on commit 8bd1053

Please sign in to comment.