From 9d997a74d6bad60bf6a9483ef34249d6cac91447 Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Wed, 25 Sep 2024 16:56:33 +0200 Subject: [PATCH] Implement user notes in CRM and HelpScout integration (#4611) * Implement user notes in CRM and HelpScout integration * Update HS tests * Make slight markup and styling changes --- extra/lib/plausible/help_scout.ex | 1 + extra/lib/plausible_web/views/help_scout_view.ex | 15 +++++++++++++++ lib/plausible/auth/user.ex | 6 +++++- lib/plausible/auth/user_admin.ex | 3 ++- .../controllers/help_scout_controller_test.exs | 8 +++++--- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/extra/lib/plausible/help_scout.ex b/extra/lib/plausible/help_scout.ex index 15698a96b7..9cc5a7d428 100644 --- a/extra/lib/plausible/help_scout.ex +++ b/extra/lib/plausible/help_scout.ex @@ -88,6 +88,7 @@ defmodule Plausible.HelpScout do {:ok, %{ email: user.email, + notes: user.notes, status_label: status_label(user), status_link: Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :auth, :user, user.id), diff --git a/extra/lib/plausible_web/views/help_scout_view.ex b/extra/lib/plausible_web/views/help_scout_view.ex index fbbd6f19d8..8a3b8c1bc2 100644 --- a/extra/lib/plausible_web/views/help_scout_view.ex +++ b/extra/lib/plausible_web/views/help_scout_view.ex @@ -42,6 +42,17 @@ defmodule PlausibleWeb.HelpScoutView do

Owner of <%= @sites_count %> sites

+

+ + +
+

+ Notes +

+ +
+ <%= Phoenix.HTML.Format.text_to_html(@notes, escape: true) %> +
<% end %> @@ -140,6 +151,10 @@ defmodule PlausibleWeb.HelpScoutView do margin-bottom: 1.25em; font-weight: bold; } + + .notes .value { + font-weight: normal; + } diff --git a/lib/plausible/auth/user.ex b/lib/plausible/auth/user.ex index 539fc09043..4fe35b9f32 100644 --- a/lib/plausible/auth/user.ex +++ b/lib/plausible/auth/user.ex @@ -35,6 +35,9 @@ defmodule Plausible.Auth.User do field :previous_email, :string field :accept_traffic_until, :date + # Field for purely informational purposes in CRM context + field :notes, :string + # A field only used as a manual override - allow subscribing # to any plan, even when exceeding its pageview limit field :allow_next_upgrade_override, :boolean @@ -113,7 +116,8 @@ defmodule Plausible.Auth.User do :theme, :trial_expiry_date, :allow_next_upgrade_override, - :accept_traffic_until + :accept_traffic_until, + :notes ]) |> validate_required([:email, :name, :email_verified]) |> maybe_bump_accept_traffic_until() diff --git a/lib/plausible/auth/user_admin.ex b/lib/plausible/auth/user_admin.ex index 21eec38e95..baf107d2a9 100644 --- a/lib/plausible/auth/user_admin.ex +++ b/lib/plausible/auth/user_admin.ex @@ -20,7 +20,8 @@ defmodule Plausible.Auth.UserAdmin do allow_next_upgrade_override: nil, accept_traffic_until: %{ help_text: "Change will take up to 15 minutes to propagate" - } + }, + notes: %{type: :textarea, rows: 6} ] end diff --git a/test/plausible_web/controllers/help_scout_controller_test.exs b/test/plausible_web/controllers/help_scout_controller_test.exs index 51d16fb1d6..cda615f6cb 100644 --- a/test/plausible_web/controllers/help_scout_controller_test.exs +++ b/test/plausible_web/controllers/help_scout_controller_test.exs @@ -104,9 +104,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do end end - describe "shows/2" do + describe "show/2" do test "returns details on success", %{conn: conn} do - user = insert(:user, email: "hs.match@plausible.test") + user = insert(:user, email: "hs.match@plausible.test", notes: "Some note\nwith new line") conn = conn @@ -115,7 +115,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do "/helpscout/show?conversation_id=123&customer_id=500&email=hs.match@plausible.test" ) - assert html_response(conn, 200) =~ "/crm/auth/user/#{user.id}" + assert html = html_response(conn, 200) + assert html =~ "/crm/auth/user/#{user.id}" + assert html =~ "Some note
\nwith new line" end test "returns error when cookie is missing", %{conn: conn} do