forked from github/plane
dev: update workspace slug validation
This commit is contained in:
parent
f5c42d550e
commit
5314518fb2
@ -21,6 +21,22 @@ class WorkSpaceSerializer(BaseSerializer):
|
|||||||
total_members = serializers.IntegerField(read_only=True)
|
total_members = serializers.IntegerField(read_only=True)
|
||||||
total_issues = serializers.IntegerField(read_only=True)
|
total_issues = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
def validated(self, data):
|
||||||
|
if data.get("slug") in [
|
||||||
|
"404",
|
||||||
|
"accounts",
|
||||||
|
"api",
|
||||||
|
"create-workspace",
|
||||||
|
"god-mode",
|
||||||
|
"installations",
|
||||||
|
"invitations",
|
||||||
|
"onboarding",
|
||||||
|
"profile",
|
||||||
|
"spaces",
|
||||||
|
"workspace-invitations",
|
||||||
|
]:
|
||||||
|
raise serializers.ValidationError({"slug": "Slug is not valid"})
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workspace
|
model = Workspace
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
19
apiserver/plane/db/migrations/0052_alter_workspace_slug.py
Normal file
19
apiserver/plane/db/migrations/0052_alter_workspace_slug.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.5 on 2023-11-23 14:57
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import plane.db.models.workspace
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('db', '0051_fileasset_is_deleted'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='workspace',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=48, unique=True, validators=[plane.db.models.workspace.slug_validator]),
|
||||||
|
),
|
||||||
|
]
|
@ -1,6 +1,7 @@
|
|||||||
# Django imports
|
# Django imports
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from . import BaseModel
|
from . import BaseModel
|
||||||
@ -50,7 +51,7 @@ def get_default_props():
|
|||||||
"state": True,
|
"state": True,
|
||||||
"sub_issue_count": True,
|
"sub_issue_count": True,
|
||||||
"updated_on": True,
|
"updated_on": True,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +64,23 @@ def get_issue_props():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def slug_validator(value):
|
||||||
|
if value in [
|
||||||
|
"404",
|
||||||
|
"accounts",
|
||||||
|
"api",
|
||||||
|
"create-workspace",
|
||||||
|
"god-mode",
|
||||||
|
"installations",
|
||||||
|
"invitations",
|
||||||
|
"onboarding",
|
||||||
|
"profile",
|
||||||
|
"spaces",
|
||||||
|
"workspace-invitations",
|
||||||
|
]:
|
||||||
|
raise ValidationError("Slug is not valid")
|
||||||
|
|
||||||
|
|
||||||
class Workspace(BaseModel):
|
class Workspace(BaseModel):
|
||||||
name = models.CharField(max_length=80, verbose_name="Workspace Name")
|
name = models.CharField(max_length=80, verbose_name="Workspace Name")
|
||||||
logo = models.URLField(verbose_name="Logo", blank=True, null=True)
|
logo = models.URLField(verbose_name="Logo", blank=True, null=True)
|
||||||
@ -71,7 +89,7 @@ class Workspace(BaseModel):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="owner_workspace",
|
related_name="owner_workspace",
|
||||||
)
|
)
|
||||||
slug = models.SlugField(max_length=48, db_index=True, unique=True)
|
slug = models.SlugField(max_length=48, db_index=True, unique=True, validators=[slug_validator,])
|
||||||
organization_size = models.CharField(max_length=20, blank=True, null=True)
|
organization_size = models.CharField(max_length=20, blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user