models: Remove "role" field from Subscription.

This commit removes "role" field from subscription
objects since we are not moving forward with stream
administrator concept and instead working on new
permssions model as per #19525.
This commit is contained in:
Sahil Batra 2022-07-05 20:12:29 +05:30 committed by Tim Abbott
parent 83383090f9
commit 093a74bd54
11 changed files with 35 additions and 50 deletions

View File

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

View File

@ -24,6 +24,9 @@ format used by the Zulip server that they are interacting with.
* [`POST /register`](/api/register-queue), `PATCH /realm`: Removed * [`POST /register`](/api/register-queue), `PATCH /realm`: Removed
stream administrators option from `wildcard_mention_policy` setting. stream administrators option from `wildcard_mention_policy` setting.
* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
[`GET /users/me/subscriptions`](/api/get-subscriptions): Removed
`role` field from subscription objects.
**Feature level 132** **Feature level 132**

View File

@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3"
# Changes should be accompanied by documentation explaining what the # Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md, as well as # new level means in templates/zerver/api/changelog.md, as well as
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`. # "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
API_FEATURE_LEVEL = 132 API_FEATURE_LEVEL = 133
# Bump the minor PROVISION_VERSION to indicate that folks should provision # 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 # only when going from an old version of the code to a newer version. Bump

View File

@ -281,7 +281,6 @@ def send_subscription_add_events(
is_muted=subscription.is_muted, is_muted=subscription.is_muted,
pin_to_top=subscription.pin_to_top, pin_to_top=subscription.pin_to_top,
push_notifications=subscription.push_notifications, push_notifications=subscription.push_notifications,
role=subscription.role,
wildcard_mentions_notify=subscription.wildcard_mentions_notify, wildcard_mentions_notify=subscription.wildcard_mentions_notify,
# Computed fields not present in Subscription.API_FIELDS # Computed fields not present in Subscription.API_FIELDS
email_address=stream_info.email_address, email_address=stream_info.email_address,

View File

@ -45,7 +45,7 @@ from zerver.lib.data_types import (
make_checker, make_checker,
) )
from zerver.lib.topic import ORIG_TOPIC, TOPIC_LINKS, TOPIC_NAME from zerver.lib.topic import ORIG_TOPIC, TOPIC_LINKS, TOPIC_NAME
from zerver.models import Realm, RealmUserDefault, Stream, Subscription, UserProfile from zerver.models import Realm, RealmUserDefault, Stream, UserProfile
# These fields are used for "stream" events, and are included in the # These fields are used for "stream" events, and are included in the
# larger "subscription" events that also contain personal settings. # larger "subscription" events that also contain personal settings.
@ -75,7 +75,6 @@ subscription_fields: Sequence[Tuple[str, object]] = [
("is_muted", bool), ("is_muted", bool),
("pin_to_top", bool), ("pin_to_top", bool),
("push_notifications", OptionalType(bool)), ("push_notifications", OptionalType(bool)),
("role", EnumType(Subscription.ROLE_TYPES)),
("stream_weekly_traffic", OptionalType(int)), ("stream_weekly_traffic", OptionalType(int)),
# We may try to remove subscribers from some events in # We may try to remove subscribers from some events in
# the future for clients that don't want subscriber # the future for clients that don't want subscriber

View File

@ -64,7 +64,6 @@ def get_web_public_subs(realm: Realm) -> SubscriptionInfo:
is_muted = False is_muted = False
pin_to_top = False pin_to_top = False
push_notifications = True push_notifications = True
role = Subscription.ROLE_MEMBER
stream_weekly_traffic = get_average_weekly_stream_traffic( stream_weekly_traffic = get_average_weekly_stream_traffic(
stream.id, stream.date_created, {} stream.id, stream.date_created, {}
) )
@ -90,7 +89,6 @@ def get_web_public_subs(realm: Realm) -> SubscriptionInfo:
pin_to_top=pin_to_top, pin_to_top=pin_to_top,
push_notifications=push_notifications, push_notifications=push_notifications,
rendered_description=rendered_description, rendered_description=rendered_description,
role=role,
stream_id=stream_id, stream_id=stream_id,
stream_post_policy=stream_post_policy, stream_post_policy=stream_post_policy,
stream_weekly_traffic=stream_weekly_traffic, stream_weekly_traffic=stream_weekly_traffic,
@ -133,7 +131,6 @@ def build_stream_dict_for_sub(
email_notifications = sub_dict["email_notifications"] email_notifications = sub_dict["email_notifications"]
push_notifications = sub_dict["push_notifications"] push_notifications = sub_dict["push_notifications"]
wildcard_mentions_notify = sub_dict["wildcard_mentions_notify"] wildcard_mentions_notify = sub_dict["wildcard_mentions_notify"]
role = sub_dict["role"]
# Backwards-compatibility for clients that haven't been # Backwards-compatibility for clients that haven't been
# updated for the in_home_view => is_muted API migration. # updated for the in_home_view => is_muted API migration.
@ -174,7 +171,6 @@ def build_stream_dict_for_sub(
pin_to_top=pin_to_top, pin_to_top=pin_to_top,
push_notifications=push_notifications, push_notifications=push_notifications,
rendered_description=rendered_description, rendered_description=rendered_description,
role=role,
stream_id=stream_id, stream_id=stream_id,
stream_post_policy=stream_post_policy, stream_post_policy=stream_post_policy,
stream_weekly_traffic=stream_weekly_traffic, stream_weekly_traffic=stream_weekly_traffic,

View File

@ -166,7 +166,6 @@ class RawSubscriptionDict(TypedDict):
pin_to_top: bool pin_to_top: bool
push_notifications: Optional[bool] push_notifications: Optional[bool]
recipient_id: int recipient_id: int
role: int
wildcard_mentions_notify: Optional[bool] wildcard_mentions_notify: Optional[bool]
@ -196,7 +195,6 @@ class SubscriptionStreamDict(TypedDict):
pin_to_top: bool pin_to_top: bool
push_notifications: Optional[bool] push_notifications: Optional[bool]
rendered_description: str rendered_description: str
role: int
stream_id: int stream_id: int
stream_post_policy: int stream_post_policy: int
stream_weekly_traffic: Optional[int] stream_weekly_traffic: Optional[int]
@ -255,7 +253,6 @@ class APISubscriptionDict(APIStreamDict):
is_muted: bool is_muted: bool
pin_to_top: bool pin_to_top: bool
push_notifications: Optional[bool] push_notifications: Optional[bool]
role: int
wildcard_mentions_notify: Optional[bool] wildcard_mentions_notify: Optional[bool]
# Computed fields not specified in `Subscription.API_FIELDS` # Computed fields not specified in `Subscription.API_FIELDS`
email_address: str email_address: str

View File

@ -0,0 +1,17 @@
# Generated by Django 3.2.13 on 2022-07-05 12:44
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("zerver", "0395_alter_realm_wildcard_mention_policy"),
]
operations = [
migrations.RemoveField(
model_name="subscription",
name="role",
),
]

View File

@ -3562,16 +3562,6 @@ class Subscription(models.Model):
# we may be creating Subscription objects for a user that's deactivated. # we may be creating Subscription objects for a user that's deactivated.
is_user_active: bool = models.BooleanField() is_user_active: bool = models.BooleanField()
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. # Whether this user had muted this stream.
is_muted: bool = models.BooleanField(default=False) is_muted: bool = models.BooleanField(default=False)
@ -3623,7 +3613,6 @@ class Subscription(models.Model):
"is_muted", "is_muted",
"pin_to_top", "pin_to_top",
"push_notifications", "push_notifications",
"role",
"wildcard_mentions_notify", "wildcard_mentions_notify",
] ]

View File

@ -608,6 +608,9 @@ paths:
description: | description: |
A list of dictionaries where each dictionary contains A list of dictionaries where each dictionary contains
information about one of the subscribed streams. information about one of the subscribed streams.
**Changes**: Removed `role` field from the dictionary
in Zulip 6.0 (feature level 133).
items: items:
$ref: "#/components/schemas/Subscriptions" $ref: "#/components/schemas/Subscriptions"
additionalProperties: false additionalProperties: false
@ -6966,6 +6969,9 @@ paths:
description: | description: |
A list of dictionaries where each dictionary contains A list of dictionaries where each dictionary contains
information about one of the subscribed streams. information about one of the subscribed streams.
**Changes**: Removed `role` field from the dictionary
in Zulip 6.0 (feature level 133).
items: items:
$ref: "#/components/schemas/Subscriptions" $ref: "#/components/schemas/Subscriptions"
example: example:
@ -6985,7 +6991,6 @@ paths:
"name": "Denmark", "name": "Denmark",
"pin_to_top": false, "pin_to_top": false,
"push_notifications": false, "push_notifications": false,
"role": 20,
"stream_id": 1, "stream_id": 1,
"subscribers": [7, 10, 11, 12, 14], "subscribers": [7, 10, 11, 12, 14],
}, },
@ -7000,7 +7005,6 @@ paths:
"name": "Scotland", "name": "Scotland",
"pin_to_top": false, "pin_to_top": false,
"push_notifications": false, "push_notifications": false,
"role": 50,
"stream_id": 3, "stream_id": 3,
"subscribers": [7, 11, 12, 14], "subscribers": [7, 11, 12, 14],
}, },
@ -9557,6 +9561,9 @@ paths:
A array of dictionaries where each dictionary describes the properties A array of dictionaries where each dictionary describes the properties
of a stream the user is subscribed to (as well as that user's of a stream the user is subscribed to (as well as that user's
personal per-stream settings). personal per-stream settings).
**Changes**: Removed `role` field from the dictionary
in Zulip 6.0 (feature level 133).
unsubscribed: unsubscribed:
type: array type: array
items: items:
@ -9570,6 +9577,9 @@ paths:
Unlike `never_subscribed`, the user might have messages in their personal Unlike `never_subscribed`, the user might have messages in their personal
message history that were sent to these streams. message history that were sent to these streams.
**Changes**: Removed `role` field from the dictionary
in Zulip 6.0 (feature level 133).
never_subscribed: never_subscribed:
type: array type: array
items: items:
@ -15102,20 +15112,6 @@ components:
description: | description: |
Whether the stream has been configured to allow unauthenticated Whether the stream has been configured to allow unauthenticated
access to its message history from the web. access to its message history from the web.
role:
type: integer
enum:
- 20
- 50
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: color:
type: string type: string
description: | description: |

View File

@ -29,7 +29,6 @@ from zerver.actions.streams import (
bulk_add_subscriptions, bulk_add_subscriptions,
bulk_remove_subscriptions, bulk_remove_subscriptions,
do_change_stream_post_policy, do_change_stream_post_policy,
do_change_subscription_property,
do_deactivate_stream, do_deactivate_stream,
) )
from zerver.actions.users import do_change_user_role, do_deactivate_user from zerver.actions.users import do_change_user_role, do_deactivate_user
@ -1601,13 +1600,8 @@ class StreamAdminTest(ZulipTestCase):
user_profile = self.example_user("hamlet") user_profile = self.example_user("hamlet")
self.login_user(user_profile) self.login_user(user_profile)
stream = self.subscribe(user_profile, "stream_name1") self.subscribe(user_profile, "stream_name1")
sub = get_subscription("stream_name1", user_profile)
do_change_user_role(user_profile, UserProfile.ROLE_MEMBER, acting_user=None) do_change_user_role(user_profile, UserProfile.ROLE_MEMBER, acting_user=None)
do_change_subscription_property(
user_profile, sub, stream, "role", Subscription.ROLE_MEMBER, acting_user=None
)
stream_id = get_stream("stream_name1", user_profile.realm).id stream_id = get_stream("stream_name1", user_profile.realm).id
result = self.client_patch( result = self.client_patch(
@ -1658,12 +1652,8 @@ class StreamAdminTest(ZulipTestCase):
self.login_user(user_profile) self.login_user(user_profile)
stream = self.subscribe(user_profile, "stream_name1") stream = self.subscribe(user_profile, "stream_name1")
sub = get_subscription("stream_name1", user_profile)
do_change_user_role(user_profile, UserProfile.ROLE_MEMBER, acting_user=None) do_change_user_role(user_profile, UserProfile.ROLE_MEMBER, acting_user=None)
do_change_subscription_property(
user_profile, sub, stream, "role", Subscription.ROLE_MEMBER, acting_user=None
)
do_set_realm_property(user_profile.realm, "waiting_period_threshold", 10, acting_user=None) do_set_realm_property(user_profile.realm, "waiting_period_threshold", 10, acting_user=None)