streams: Add API for changing stream-level message_retention_days.

This commit adds backend support for setting message_retention_days
while creating streams and updating it for an existing stream. We only
allow organization owners to set/update it for a stream.

'message_retention_days' field for a stream existed previously also, but
there was no way to set it while creating streams or update it for an
exisiting streams using any endpoint.
This commit is contained in:
sahil839
2020-06-14 22:27:02 +05:30
committed by Tim Abbott
parent 98cd52cc3e
commit c488a35f10
9 changed files with 282 additions and 7 deletions

View File

@@ -3613,6 +3613,20 @@ def do_change_stream_description(stream: Stream, new_description: str) -> None:
)
send_event(stream.realm, event, can_access_stream_user_ids(stream))
def do_change_stream_message_retention_days(stream: Stream, message_retention_days: Optional[int]=None) -> None:
stream.message_retention_days = message_retention_days
stream.save(update_fields=['message_retention_days'])
event = dict(
op="update",
type="stream",
property="message_retention_days",
value=message_retention_days,
stream_id=stream.id,
name=stream.name,
)
send_event(stream.realm, event, can_access_stream_user_ids(stream))
def do_create_realm(string_id: str, name: str,
emails_restricted_to_domains: Optional[bool]=None) -> Realm:
if Realm.objects.filter(string_id=string_id).exists():