From 4cce94b667bf73ff06737ca77acb84aa032c22ad Mon Sep 17 00:00:00 2001 From: Shashank Singh <21bec103@iiitdmj.ac.in> Date: Thu, 18 Apr 2024 17:38:47 +0000 Subject: [PATCH] invites: Add option to receive notification on accepted invitations. Previously, when a referrer's invitation to Zulip was accepted, they got a notification from notification-bot indicating their invitation has been accepted. This commit adds an option for referrer to decide whether he wants to receive the direct notification from the notification-bot. Fixes: #20398 --- api_docs/changelog.md | 7 +++ version.py | 2 +- web/src/invite.ts | 5 ++ web/src/settings_invites.ts | 2 + web/templates/invite_user_modal.hbs | 7 +++ zerver/actions/create_user.py | 1 + zerver/actions/invites.py | 3 ++ ...egistrationuser_notify_referrer_on_join.py | 17 +++++++ zerver/models/prereg_users.py | 1 + zerver/openapi/zulip.yaml | 23 +++++++++ zerver/tests/test_invite.py | 49 ++++++++++++++++++- zerver/views/invite.py | 4 ++ 12 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 zerver/migrations/0542_preregistrationuser_notify_referrer_on_join.py diff --git a/api_docs/changelog.md b/api_docs/changelog.md index e8956a4885..a6776042b2 100644 --- a/api_docs/changelog.md +++ b/api_docs/changelog.md @@ -20,6 +20,13 @@ format used by the Zulip server that they are interacting with. ## Changes in Zulip 9.0 +**Feature level 267** + +* [`GET /invites`](/api/get-invites),[`POST /invites`](/api/send-invites): Added + `notify_referrer_on_join` parameter, indicating whether the referrer has opted + to receive a direct message from the notification bot whenever a user joins + via this invitation. + **Feature level 266** * `PATCH /realm`, [`POST /register`](/api/register-queue), diff --git a/version.py b/version.py index b52d4bcb55..76d75e88e4 100644 --- a/version.py +++ b/version.py @@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3" # Changes should be accompanied by documentation explaining what the # new level means in api_docs/changelog.md, as well as "**Changes**" # entries in the endpoint's documentation in `zulip.yaml`. -API_FEATURE_LEVEL = 266 +API_FEATURE_LEVEL = 267 # 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/web/src/invite.ts b/web/src/invite.ts index 115acb3d6a..a7870f2693 100644 --- a/web/src/invite.ts +++ b/web/src/invite.ts @@ -47,6 +47,7 @@ function reset_error_messages(): void { function get_common_invitation_data(): { csrfmiddlewaretoken: string; invite_as: number; + notify_referrer_on_join: boolean; stream_ids: string; invite_expires_in_minutes: string; invitee_emails: string; @@ -56,6 +57,7 @@ function get_common_invitation_data(): { $("select:not([multiple])#invite_as").val()!, 10, ); + const notify_referrer_on_join = $("#receive-invite-acceptance-notification").is(":checked"); const raw_expires_in = $("select:not([multiple])#expires_in").val()!; // See settings_config.expires_in_values for why we do this conversion. let expires_in: number | null; @@ -82,6 +84,7 @@ function get_common_invitation_data(): { const data = { csrfmiddlewaretoken: csrf_token, invite_as, + notify_referrer_on_join, stream_ids: JSON.stringify(stream_ids), invite_expires_in_minutes: JSON.stringify(expires_in), invitee_emails: pills @@ -459,9 +462,11 @@ function open_invite_user_modal(e: JQuery.ClickEvent): void switch (key) { case "invite-email-tab": $("#invitee_emails_container").show(); + $("#receive-invite-acceptance-notification-container").show(); break; case "invite-link-tab": $("#invitee_emails_container").hide(); + $("#receive-invite-acceptance-notification-container").hide(); break; } toggle_invite_submit_button(key); diff --git a/web/src/settings_invites.ts b/web/src/settings_invites.ts index be1a095a90..6d71d40ebd 100644 --- a/web/src/settings_invites.ts +++ b/web/src/settings_invites.ts @@ -26,6 +26,7 @@ export const invite_schema = z.intersection( expiry_date: z.number().nullable(), id: z.number(), invited_as: z.number(), + notify_referrer_on_join: z.boolean(), }), z.discriminatedUnion("is_multiuse", [ z.object({ @@ -46,6 +47,7 @@ type Invite = z.output & { disable_buttons?: boolean; referrer_name?: string; img_src?: string; + notify_referrer_on_join?: boolean; }; const meta = { diff --git a/web/templates/invite_user_modal.hbs b/web/templates/invite_user_modal.hbs index 3af93231e8..d9ae432f94 100644 --- a/web/templates/invite_user_modal.hbs +++ b/web/templates/invite_user_modal.hbs @@ -26,6 +26,13 @@ +
+ +