mirror of https://github.com/zulip/zulip.git
subscription: Add role field to Subscription class.
This commit adds role field to the Subscription class. Currently, there are two option of roles - STREAM_ADMINISTRATOR and MEMBER. We also add a property 'is_stream_admin' for checking whether the user is stream admin or not.
This commit is contained in:
parent
9f9daeea5b
commit
78da9fd3ab
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.13 on 2020-06-10 18:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('zerver', '0298_fix_realmauditlog_format'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='subscription',
|
||||||
|
name='role',
|
||||||
|
field=models.PositiveSmallIntegerField(db_index=True, default=50),
|
||||||
|
),
|
||||||
|
]
|
|
@ -2243,6 +2243,11 @@ class Subscription(models.Model):
|
||||||
# resubscribes.
|
# resubscribes.
|
||||||
active: bool = models.BooleanField(default=True)
|
active: bool = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
ROLE_STREAM_ADMINISTRATOR = 20
|
||||||
|
ROLE_MEMBER = 50
|
||||||
|
|
||||||
|
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: Optional[bool] = models.BooleanField(null=True, default=False)
|
is_muted: Optional[bool] = models.BooleanField(null=True, default=False)
|
||||||
|
|
||||||
|
@ -2265,6 +2270,10 @@ class Subscription(models.Model):
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"<Subscription: {self.user_profile} -> {self.recipient}>"
|
return f"<Subscription: {self.user_profile} -> {self.recipient}>"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_stream_admin(self) -> bool:
|
||||||
|
return self.role == Subscription.ROLE_STREAM_ADMINISTRATOR
|
||||||
|
|
||||||
# Subscription fields included whenever a Subscription object is provided to
|
# Subscription fields included whenever a Subscription object is provided to
|
||||||
# Zulip clients via the API. A few details worth noting:
|
# Zulip clients via the API. A few details worth noting:
|
||||||
# * These fields will generally be merged with Stream.API_FIELDS
|
# * These fields will generally be merged with Stream.API_FIELDS
|
||||||
|
|
Loading…
Reference in New Issue