From 6eb8442a59e139f852b88a75b3367aa942a22f5f Mon Sep 17 00:00:00 2001 From: sahil839 Date: Sat, 27 Jun 2020 00:56:57 +0530 Subject: [PATCH] invites: Send user_id of the referrer instead of email in invites dict. We send user_id of the referrer instead of email in the invites dict. Sending user_ids is more robust, as those are an immutable reference to a user, rather than something that can change with time. Updates to the webapp UI to display the inviters for more convenient inspection will come in a future commit. --- static/js/settings_invites.js | 4 +++- static/templates/admin_invites_list.hbs | 2 +- templates/zerver/api/changelog.md | 12 +++++++++--- version.py | 2 +- zerver/lib/actions.py | 4 ++-- zerver/tests/test_signup.py | 13 +++++++------ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js index 74b03ae91d..a2024cec72 100644 --- a/static/js/settings_invites.js +++ b/static/js/settings_invites.js @@ -48,12 +48,14 @@ function populate_invites(invites_data) { item.is_admin = page_params.is_admin; item.disable_buttons = item.invited_as === settings_config.user_role_values.owner.code && !page_params.is_owner; + item.referrer_email = people.get_by_user_id(item.invited_by_user_id).email; return render_admin_invites_list({ invite: item }); }, filter: { element: invites_table.closest(".settings-section").find(".search"), predicate: function (item, value) { - const referrer_email_matched = item.ref.toLowerCase().includes(value); + const referrer_email = people.get_by_user_id(item.invited_by_user_id).email; + const referrer_email_matched = referrer_email.toLowerCase().includes(value); if (item.is_multiuse) { return referrer_email_matched; } diff --git a/static/templates/admin_invites_list.hbs b/static/templates/admin_invites_list.hbs index 2835573c09..b059d69971 100644 --- a/static/templates/admin_invites_list.hbs +++ b/static/templates/admin_invites_list.hbs @@ -13,7 +13,7 @@ {{#if is_admin}} - {{ref}} + {{referrer_email}} {{/if}} diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index f84c429247..8e61ff297b 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -12,9 +12,15 @@ below features are supported. **Feature level 22** -* 'GET /attachments': Rename `name` to `date_sent` for clearer meaning - and change the data types of the new `date_sent` and `create_time` - to integer (previously the implementation could send floats). +* `GET /attachments`: The date when a message using the attachment was + sent is now correctly encoded as `date_sent`, replacing the + confusingly named `name` field. The `date_sent` and `create_time` + fields of attachment objects are now encoded as integers; + (previously the implementation could send floats incorrectly + suggesting that microsecond precision is relevant). +* `GET /invites`: Now encodes the user ID of the person who created + the invitation as `invited_by_user_id`, replacing the previous + `ref` field (which had that user's Zulip display email address). **Feature level 21** diff --git a/version.py b/version.py index 699ee335b0..06d110658c 100644 --- a/version.py +++ b/version.py @@ -29,7 +29,7 @@ DESKTOP_WARNING_VERSION = "5.2.0" # # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md. -API_FEATURE_LEVEL = 21 +API_FEATURE_LEVEL = 22 # 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 diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 4864c69b4e..2fde7f3031 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -5282,7 +5282,7 @@ def do_get_user_invites(user_profile: UserProfile) -> List[Dict[str, Any]]: for invitee in prereg_users: invites.append(dict(email=invitee.email, - ref=invitee.referred_by.email, + invited_by_user_id=invitee.referred_by.id, invited=datetime_to_timestamp(invitee.invited_at), id=invitee.id, invited_as=invitee.invited_as, @@ -5298,7 +5298,7 @@ def do_get_user_invites(user_profile: UserProfile) -> List[Dict[str, Any]]: date_sent__gte=lowest_datetime) for confirmation_obj in multiuse_confirmation_objs: invite = confirmation_obj.content_object - invites.append(dict(ref=invite.referred_by.email, + invites.append(dict(invited_by_user_id=invite.referred_by.id, invited=datetime_to_timestamp(confirmation_obj.date_sent), id=invite.id, link_url=confirmation_url(confirmation_obj.confirmation_key, diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index c6b2118623..6c6388b332 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -1664,12 +1664,13 @@ class InvitationsTestCase(InviteUserBase): result = self.client_get("/json/invites") self.assertEqual(result.status_code, 200) - self.assert_in_success_response( - ["TestOne@zulip.com", hamlet.email], - result) - self.assert_not_in_success_response( - ["TestTwo@zulip.com", "TestThree@zulip.com", "othello@zulip.com", othello.email], - result) + invites = ujson.loads(result.content)["invites"] + self.assertEqual(len(invites), 2) + + self.assertFalse(invites[0]["is_multiuse"]) + self.assertEqual(invites[0]["email"], "TestOne@zulip.com") + self.assertTrue(invites[1]["is_multiuse"]) + self.assertEqual(invites[1]["invited_by_user_id"], hamlet.id) def test_successful_delete_invitation(self) -> None: """