mirror of https://github.com/zulip/zulip.git
register: Pass the configuration objects for group settings in response.
This commit adds code to pass configuration objects for group permission settings in register response to clients such that we do need to duplicate that data in clients and can avoid future bugs due to inconsistency. The "server_supported_permission_settings" field is included in the response if "realm" is present in "fetch_event_types", as this is what we do for other server-related fields.
This commit is contained in:
parent
e458b73a01
commit
47c8e369cf
|
@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.
|
|||
|
||||
## Changes in Zulip 8.0
|
||||
|
||||
**Feature level 221**
|
||||
|
||||
* [`POST /register`](/api/register-queue): Added `server_supported_permission_settings`
|
||||
field in the response which contains configuration data for various permission
|
||||
settings.
|
||||
|
||||
**Feature level 220**
|
||||
|
||||
* [`GET /events`](/api/get-events): Stream creation events for web-public
|
||||
|
|
|
@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
|
|||
# Changes should be accompanied by documentation explaining what the
|
||||
# new level means in api_docs/changelog.md, as well as "**Changes**"
|
||||
# entries in the endpoint's documentation in `zulip.yaml`.
|
||||
API_FEATURE_LEVEL = 220
|
||||
API_FEATURE_LEVEL = 221
|
||||
|
||||
# Bump the minor PROVISION_VERSION to indicate that folks should provision
|
||||
# only when going from an old version of the code to a newer version. Bump
|
||||
|
|
|
@ -51,7 +51,10 @@ from zerver.lib.subscription_info import gather_subscriptions_helper, get_web_pu
|
|||
from zerver.lib.timestamp import datetime_to_timestamp
|
||||
from zerver.lib.timezone import canonicalize_timezone
|
||||
from zerver.lib.topic import TOPIC_NAME
|
||||
from zerver.lib.user_groups import user_groups_in_realm_serialized
|
||||
from zerver.lib.user_groups import (
|
||||
get_server_supported_permission_settings,
|
||||
user_groups_in_realm_serialized,
|
||||
)
|
||||
from zerver.lib.user_status import get_user_status_dict
|
||||
from zerver.lib.user_topics import get_topic_mutes, get_user_topics
|
||||
from zerver.lib.users import (
|
||||
|
@ -382,6 +385,8 @@ def fetch_initial_state_data(
|
|||
state[
|
||||
"server_typing_started_wait_period_milliseconds"
|
||||
] = settings.TYPING_STARTED_WAIT_PERIOD_MILLISECONDS
|
||||
|
||||
state["server_supported_permission_settings"] = get_server_supported_permission_settings()
|
||||
if want("realm_user_settings_defaults"):
|
||||
realm_user_default = RealmUserDefault.objects.get(realm=realm)
|
||||
state["realm_user_settings_defaults"] = {}
|
||||
|
|
|
@ -291,3 +291,10 @@ class GroupPermissionSetting:
|
|||
default_group_name: str
|
||||
id_field_name: str
|
||||
default_for_system_groups: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class ServerSupportedPermissionSettings:
|
||||
realm: Dict[str, GroupPermissionSetting]
|
||||
stream: Dict[str, GroupPermissionSetting]
|
||||
group: Dict[str, GroupPermissionSetting]
|
||||
|
|
|
@ -10,11 +10,12 @@ from django_cte import With
|
|||
from django_stubs_ext import ValuesQuerySet
|
||||
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.types import GroupPermissionSetting
|
||||
from zerver.lib.types import GroupPermissionSetting, ServerSupportedPermissionSettings
|
||||
from zerver.models import (
|
||||
GroupGroupMembership,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
Stream,
|
||||
SystemGroups,
|
||||
UserGroup,
|
||||
UserGroupMembership,
|
||||
|
@ -540,3 +541,23 @@ def get_system_user_group_for_user(user_profile: UserProfile) -> UserGroup:
|
|||
name=system_user_group_name, realm=user_profile.realm, is_system_group=True
|
||||
)
|
||||
return system_user_group
|
||||
|
||||
|
||||
def get_server_supported_permission_settings() -> ServerSupportedPermissionSettings:
|
||||
realm_permission_group_settings: Dict[str, GroupPermissionSetting] = {}
|
||||
for permission_name, permission_config in Realm.REALM_PERMISSION_GROUP_SETTINGS.items():
|
||||
realm_permission_group_settings[permission_name] = permission_config
|
||||
|
||||
stream_permission_group_settings: Dict[str, GroupPermissionSetting] = {}
|
||||
for permission_name, permission_config in Stream.stream_permission_group_settings.items():
|
||||
stream_permission_group_settings[permission_name] = permission_config
|
||||
|
||||
group_permission_settings: Dict[str, GroupPermissionSetting] = {}
|
||||
for permission_name, permission_config in UserGroup.GROUP_PERMISSION_SETTINGS.items():
|
||||
group_permission_settings[permission_name] = permission_config
|
||||
|
||||
return ServerSupportedPermissionSettings(
|
||||
realm=realm_permission_group_settings,
|
||||
stream=stream_permission_group_settings,
|
||||
group=group_permission_settings,
|
||||
)
|
||||
|
|
|
@ -15154,6 +15154,37 @@ paths:
|
|||
nullable: true
|
||||
avatar_version: {}
|
||||
profile_data: {}
|
||||
server_supported_permission_settings:
|
||||
description: |
|
||||
Present if `realm` is present in `fetch_event_types`.
|
||||
|
||||
Configuration for various group permission settings.
|
||||
|
||||
We consider this part of the Zulip API to be unstable
|
||||
and may change significantly in future versions.
|
||||
|
||||
**Changes**: New in Zulip 8.0 (feature level 221).
|
||||
type: object
|
||||
additionalProperties: false
|
||||
properties:
|
||||
realm:
|
||||
type: object
|
||||
description: |
|
||||
Configuration for realm level group permission settings.
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/GroupPermissionSetting"
|
||||
stream:
|
||||
type: object
|
||||
description: |
|
||||
Configuration for stream level group permission settings.
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/GroupPermissionSetting"
|
||||
group:
|
||||
type: object
|
||||
description: |
|
||||
Configuration for group level group permission settings.
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/GroupPermissionSetting"
|
||||
example:
|
||||
{
|
||||
"last_event_id": -1,
|
||||
|
@ -19250,6 +19281,49 @@ components:
|
|||
- rendered_content
|
||||
- scheduled_delivery_timestamp
|
||||
- failed
|
||||
GroupPermissionSetting:
|
||||
description: |
|
||||
Configuration for a group permission setting specifying the groups
|
||||
to which the setting can be set to and the default values for the
|
||||
setting.
|
||||
additionalProperties: false
|
||||
type: object
|
||||
properties:
|
||||
require_system_group:
|
||||
type: boolean
|
||||
description: |
|
||||
Whether the setting can only be set to a system user group.
|
||||
allow_internet_group:
|
||||
type: boolean
|
||||
description: |
|
||||
Whether the setting can be set to `role:internet` system group.
|
||||
allow_owners_group:
|
||||
type: boolean
|
||||
description: |
|
||||
Whether the setting can be set to `role:owners` system group.
|
||||
allow_nobody_group:
|
||||
type: boolean
|
||||
description: |
|
||||
Whether the setting can be set to `role:nobody` system group.
|
||||
allow_everyone_group:
|
||||
type: boolean
|
||||
description: |
|
||||
Whether the setting can be set to `role:everyone` system group.
|
||||
default_group_name:
|
||||
type: string
|
||||
description: |
|
||||
Name of the default group for the setting.
|
||||
id_field_name:
|
||||
type: string
|
||||
description: |
|
||||
Name for the field used to pass the group ID for the setting.
|
||||
default_for_system_groups:
|
||||
type: string
|
||||
nullable: true
|
||||
description: |
|
||||
Name of the default group for the setting for system groups.
|
||||
|
||||
This is non-null only for group-level settings.
|
||||
User:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/UserBase"
|
||||
|
|
|
@ -202,6 +202,7 @@ class HomeTest(ZulipTestCase):
|
|||
"server_presence_offline_threshold_seconds",
|
||||
"server_presence_ping_interval_seconds",
|
||||
"server_sentry_dsn",
|
||||
"server_supported_permission_settings",
|
||||
"server_timestamp",
|
||||
"server_typing_started_expiry_period_milliseconds",
|
||||
"server_typing_started_wait_period_milliseconds",
|
||||
|
|
Loading…
Reference in New Issue