mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
models: Add ORG_TYPE_IDS constant field to Realm.
This commit adds ORG_TYPE_IDS constant field to Realm class such that it can be used when we want to validate the org_type passed in request. This was previously defined in realm.py, but we move it inside Realm class such that we can use it at other places as well.
This commit is contained in:
@@ -623,6 +623,8 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ORG_TYPE_IDS: List[int] = [t["id"] for t in ORG_TYPES.values()]
|
||||||
|
|
||||||
org_type = models.PositiveSmallIntegerField(
|
org_type = models.PositiveSmallIntegerField(
|
||||||
default=ORG_TYPES["unspecified"]["id"],
|
default=ORG_TYPES["unspecified"]["id"],
|
||||||
choices=[(t["id"], t["name"]) for t in ORG_TYPES.values()],
|
choices=[(t["id"], t["name"]) for t in ORG_TYPES.values()],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, Optional, Union
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
@@ -40,8 +40,6 @@ from zerver.lib.validator import (
|
|||||||
from zerver.models import Realm, RealmReactivationStatus, RealmUserDefault, UserProfile
|
from zerver.models import Realm, RealmReactivationStatus, RealmUserDefault, UserProfile
|
||||||
from zerver.views.user_settings import check_settings_values
|
from zerver.views.user_settings import check_settings_values
|
||||||
|
|
||||||
ORG_TYPE_IDS: List[int] = [t["id"] for t in Realm.ORG_TYPES.values()]
|
|
||||||
|
|
||||||
|
|
||||||
@require_realm_admin
|
@require_realm_admin
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
@@ -137,7 +135,7 @@ def update_realm(
|
|||||||
str_validator=check_capped_string(Realm.MAX_REALM_SUBDOMAIN_LENGTH),
|
str_validator=check_capped_string(Realm.MAX_REALM_SUBDOMAIN_LENGTH),
|
||||||
default=None,
|
default=None,
|
||||||
),
|
),
|
||||||
org_type: Optional[int] = REQ(json_validator=check_int_in(ORG_TYPE_IDS), default=None),
|
org_type: Optional[int] = REQ(json_validator=check_int_in(Realm.ORG_TYPE_IDS), default=None),
|
||||||
enable_spectator_access: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
enable_spectator_access: Optional[bool] = REQ(json_validator=check_bool, default=None),
|
||||||
want_advertise_in_communities_directory: Optional[bool] = REQ(
|
want_advertise_in_communities_directory: Optional[bool] = REQ(
|
||||||
json_validator=check_bool, default=None
|
json_validator=check_bool, default=None
|
||||||
|
|||||||
Reference in New Issue
Block a user