Skip to content

Commit d3fd91d

Browse files
committed
ADCM-5652 Removed validate_object_type
Since `parametrized_by_type` is created internally, validation is removed and put on user to create it correctly
1 parent 94cb163 commit d3fd91d

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

python/rbac/migrations/0001_initial.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,13 @@
1212

1313
# Generated by Django 3.2.9 on 2022-01-28 13:12
1414

15-
from django.core.exceptions import ValidationError
1615
from django.db import connection, migrations, models
1716
import django.db.models.deletion
1817
import django.contrib.auth.models
1918

2019
types = {"cluster", "service", "component", "provider", "host"}
2120

2221

23-
def validate(value):
24-
if not isinstance(value, list):
25-
raise ValidationError("Not a valid list.")
26-
27-
if not all(v in types for v in value):
28-
raise ValidationError("Not a valid object type.")
29-
30-
3122
def upgrade_users(apps, schema_editor):
3223
query = """
3324
INSERT INTO "rbac_user" ("user_ptr_id", "profile", "built_in")
@@ -143,7 +134,7 @@ class Migration(migrations.Migration):
143134
("any_category", models.BooleanField(default=False)),
144135
(
145136
"parametrized_by_type",
146-
models.JSONField(default=list, validators=[validate]),
137+
models.JSONField(default=list),
147138
),
148139
(
149140
"bundle",

python/rbac/models.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from django.db.transaction import atomic
4242
from guardian.models import GroupObjectPermission
4343
from guardian.shortcuts import get_perms_for_model
44-
from rest_framework.exceptions import ValidationError
4544

4645
from rbac.utils import get_query_tuple_str
4746

@@ -65,14 +64,6 @@ class RoleTypes(TextChoices):
6564
HIDDEN = "hidden", "hidden"
6665

6766

68-
def validate_object_type(value):
69-
if not isinstance(value, list):
70-
raise ValidationError("Not a valid list.")
71-
72-
if not all(v in ObjectType.values for v in value):
73-
raise ValidationError("Not a valid object type.")
74-
75-
7667
class User(AuthUser):
7768
profile = JSONField(default=str)
7869
built_in = BooleanField(default=False, null=False)
@@ -118,7 +109,8 @@ class Role(Model):
118109
type = CharField(max_length=1000, choices=RoleTypes.choices, null=False, default=RoleTypes.ROLE)
119110
category = ManyToManyField(ProductCategory)
120111
any_category = BooleanField(default=False)
121-
parametrized_by_type = JSONField(default=list, null=False, validators=[validate_object_type])
112+
# should be a list of `ObjectType` strings
113+
parametrized_by_type = JSONField(default=list, null=False)
122114
__obj__ = None
123115

124116
class Meta:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy