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.
This commit is contained in:
sahil839 2020-07-15 19:32:35 +05:30 committed by Tim Abbott
parent 88821b960a
commit f046c9c58a
6 changed files with 36 additions and 2 deletions

View File

@ -513,6 +513,7 @@ exports.fixtures = {
push_notifications: false,
stream_weekly_traffic: 40,
wildcard_mentions_notify: false,
role: 20,
subscribers: [5, 8, 13, 21],
},
],

View File

@ -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

View File

@ -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

View File

@ -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)),

View File

@ -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)

View File

@ -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: |