From f046c9c58a24a8ad5cae8c79a71100648e29ec05 Mon Sep 17 00:00:00 2001 From: sahil839 Date: Wed, 15 Jul 2020 19:32:35 +0530 Subject: [PATCH] streams: Add role field to Subscription objects passed to clients. This commit adds "role" field to the Subscription objects passed to clients. This is important preparation for being able to work on the frontend for this feature. --- frontend_tests/node_tests/lib/events.js | 1 + templates/zerver/api/changelog.md | 13 +++++++++++++ version.py | 2 +- zerver/lib/event_schema.py | 3 ++- zerver/models.py | 6 ++++++ zerver/openapi/zulip.yaml | 13 +++++++++++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/lib/events.js b/frontend_tests/node_tests/lib/events.js index 5149a81755..95755a17f4 100644 --- a/frontend_tests/node_tests/lib/events.js +++ b/frontend_tests/node_tests/lib/events.js @@ -513,6 +513,7 @@ exports.fixtures = { push_notifications: false, stream_weekly_traffic: 40, wildcard_mentions_notify: false, + role: 20, subscribers: [5, 8, 13, 21], }, ], diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 727af3f291..b4fd13ecf9 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -10,6 +10,19 @@ below features are supported. ## Changes in Zulip 4.0 +**Feature level 31** + +* [`GET users/me/subscriptions`](/api/get-subscriptions): Added a + `role` field to Subscription objects representing whether the user + is a stream administrator. + +* [`GET /events`](/api/get-events): Added `role` field to + Subscription objects sent in `subscriptions` events. + +Note that as of this feature level, stream administrators are a +partially completed feature. In particular, it is impossible for a +user to be a stream administrator at this feature level. + **Feature Level 30** * [`GET users/me/subscriptions`](/api/get-subscriptions), [`GET diff --git a/version.py b/version.py index 2caf75048c..f49ea4a08c 100644 --- a/version.py +++ b/version.py @@ -29,7 +29,7 @@ DESKTOP_WARNING_VERSION = "5.2.0" # # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md. -API_FEATURE_LEVEL = 30 +API_FEATURE_LEVEL = 31 # 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 diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 9a68f8338d..414f97648c 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -22,7 +22,7 @@ from zerver.lib.validator import ( check_url, equals, ) -from zerver.models import Realm, Stream, UserProfile +from zerver.models import Realm, Stream, Subscription, UserProfile # These fields are used for "stream" events, and are included in the # larger "subscription" events that also contain personal settings. @@ -50,6 +50,7 @@ subscription_fields: Sequence[Tuple[str, Validator[object]]] = [ ("email_notifications", check_none_or(check_bool)), ("in_home_view", check_bool), ("is_muted", check_bool), + ("role", check_int_in(Subscription.ROLE_TYPES)), ("pin_to_top", check_bool), ("push_notifications", check_none_or(check_bool)), ("stream_weekly_traffic", check_none_or(check_int)), diff --git a/zerver/models.py b/zerver/models.py index 3da326e1f3..57452c0f9e 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -2252,6 +2252,11 @@ class Subscription(models.Model): ROLE_STREAM_ADMINISTRATOR = 20 ROLE_MEMBER = 50 + ROLE_TYPES = [ + ROLE_STREAM_ADMINISTRATOR, + ROLE_MEMBER, + ] + role: int = models.PositiveSmallIntegerField(default=ROLE_MEMBER, db_index=True) # Whether this user had muted this stream. @@ -2304,6 +2309,7 @@ class Subscription(models.Model): "email_notifications", "push_notifications", "wildcard_mentions_notify", + "role", ] @cache_with_key(user_profile_by_id_cache_key, timeout=3600*24*7) diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 7687234f20..42e5e0658e 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -4513,6 +4513,7 @@ paths: "name": "Denmark", "pin_to_top": false, "push_notifications": false, + "role": 20, "stream_id": 1, "subscribers": [7, 10, 11, 12, 14], }, @@ -4527,6 +4528,7 @@ paths: "name": "Scotland", "pin_to_top": false, "push_notifications": false, + "role": 50, "stream_id": 3, "subscribers": [7, 11, 12, 14], }, @@ -8751,6 +8753,17 @@ components: description: | Whether the stream has been configured to allow unauthenticated access to its message history from the web. + role: + type: integer + description: | + The user's role within the stream (distinct from the user's + [organization-level role](/help/roles-and-permissions)). + Valid values are: + + * 20 => Stream administrator. + * 50 => Subscriber. + + **Changes**: New in Zulip 4.0 (feature level 31). color: type: string description: |