bug fix: Send stream notifications to all users for public streams.

If a stream is public, we now send notifications to all realm users
if the name or description of the stream changes.  For private
streams, the behavior remains the same.

We do this by introducing a method called
can_access_stream_user_ids().

(showell helped with this fix)

Fixes #2195
This commit is contained in:
Mohsen Ibrahim
2016-11-04 08:02:24 +02:00
committed by Tim Abbott
parent c405b67138
commit 19b01d74fa
2 changed files with 73 additions and 14 deletions

View File

@@ -132,14 +132,26 @@ def active_user_ids(realm):
# type: (Realm) -> List[int]
return [userdict['id'] for userdict in get_active_user_dicts_in_realm(realm)]
def stream_user_ids(stream):
# type: (Stream) -> List[int]
subscriptions = Subscription.objects.filter(recipient__type=Recipient.STREAM,
recipient__type_id=stream.id)
if stream.invite_only:
subscriptions = subscriptions.filter(active=True)
def can_access_stream_user_ids(stream):
# type: (Stream) -> Set[int]
return [sub['user_profile_id'] for sub in subscriptions.values('user_profile_id')]
# return user ids of users who can access the attributes of
# a stream, such as its name/description
if stream.is_public():
return set(active_user_ids(stream.realm))
else:
return private_stream_user_ids(stream)
def private_stream_user_ids(stream):
# type: (Stream) -> Set[int]
# TODO: Find similar queries elsewhere and de-duplicate this code.
subscriptions = Subscription.objects.filter(
recipient__type=Recipient.STREAM,
recipient__type_id=stream.id,
active=True)
return {sub['user_profile_id'] for sub in subscriptions.values('user_profile_id')}
def bot_owner_userids(user_profile):
# type: (UserProfile) -> Sequence[int]
@@ -1927,7 +1939,7 @@ def do_rename_stream(realm, old_name, new_name, log=True):
value=value,
name=old_name
)
send_event(event, stream_user_ids(stream))
send_event(event, can_access_stream_user_ids(stream))
# Even though the token doesn't change, the web client needs to update the
# email forwarding address to display the correctly-escaped new name.
@@ -1942,7 +1954,7 @@ def do_change_stream_description(realm, stream_name, new_description):
event = dict(type='stream', op='update',
property='description', name=stream_name,
value=new_description)
send_event(event, stream_user_ids(stream))
send_event(event, can_access_stream_user_ids(stream))
def do_create_realm(string_id, name, restricted_to_domain=None,
invite_required=None, org_type=None):