stream/docs: Add date_created to Stream.API_FIELDS.

The parameter Stream.date_created is now sent down to the clients
for both:

    - client.get_streams()
    - client.list_subscriptions()

API docs updated for stream and subscriptions.

Fixes #15410
This commit is contained in:
Sumanth V Rao 2020-07-25 09:14:12 +05:30 committed by Tim Abbott
parent 1c8f4b936b
commit 9b6de63afe
4 changed files with 20 additions and 5 deletions

View File

@ -4879,8 +4879,6 @@ def gather_subscriptions_helper(user_profile: UserProfile,
all_streams = get_active_streams(user_profile.realm).select_related(
"realm").values(
*Stream.API_FIELDS,
# date_created is used as an input for the stream_weekly_traffic computed field.
"date_created",
# The realm_id and recipient_id are generally not needed in the API.
"realm_id",
"recipient_id",
@ -4934,6 +4932,9 @@ def gather_subscriptions_helper(user_profile: UserProfile,
if field_name == "id":
stream_dict['stream_id'] = stream["id"]
continue
elif field_name == "date_created":
stream_dict['date_created'] = datetime_to_timestamp(stream[field_name])
continue
stream_dict[field_name] = stream[field_name]
# Copy Subscription.API_FIELDS except for "active", which is
@ -4991,6 +4992,9 @@ def gather_subscriptions_helper(user_profile: UserProfile,
if field_name == "id":
stream_dict['stream_id'] = stream["id"]
continue
elif field_name == "date_created":
stream_dict['date_created'] = datetime_to_timestamp(stream[field_name])
continue
stream_dict[field_name] = stream[field_name]
stream_dict['stream_weekly_traffic'] = get_average_weekly_stream_traffic(

View File

@ -38,6 +38,7 @@ basic_stream_fields = [
("rendered_description", check_string),
("stream_id", check_int),
("stream_post_policy", check_int),
("date_created", check_int),
]
subscription_fields: Sequence[Tuple[str, Validator[object]]] = [

View File

@ -1554,8 +1554,6 @@ class Stream(models.Model):
# * is_in_zephyr_realm is a backend-only optimization.
# * "deactivated" streams are filtered from the API entirely.
# * "realm" and "recipient" are not exposed to clients via the API.
# * "date_created" should probably be added here, as it's useful information
# to subscribers.
API_FIELDS = [
"name",
"id",
@ -1566,7 +1564,8 @@ class Stream(models.Model):
"stream_post_policy",
"history_public_to_subscribers",
"first_message_id",
"message_retention_days"
"message_retention_days",
"date_created",
]
@staticmethod
@ -1580,6 +1579,9 @@ class Stream(models.Model):
if field_name == "id":
result['stream_id'] = self.id
continue
elif field_name == "date_created":
result['date_created'] = datetime_to_timestamp(self.date_created)
continue
result[field_name] = getattr(self, field_name)
result['is_announcement_only'] = self.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS
return result

View File

@ -4122,6 +4122,10 @@ components:
The short description of the stream in text/markdown format,
intended to be used to prepopulate UI for editing a stream's
description.
date_created:
type: integer
description: |
The UNIX timestamp for when the stream was created, in UTC seconds.
invite_only:
type: boolean
description: |
@ -4223,6 +4227,10 @@ components:
work correctly. And any client-side security logic for
user-generated message content should be applied when displaying
this HTML as though it were the body of a Zulip message.
date_created:
type: integer
description: |
The UNIX timestamp for when the stream was created, in UTC seconds.
invite_only:
type: boolean
description: |