From 388fc39d5e85b9bbb5d69ca4bc22ee8c6e1f6132 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 25 Jun 2021 11:33:00 +0300 Subject: [PATCH] Fix error with multiple invitations The /activate page would error out when the user had more than 1 invitation. Will work as expected now. Fixes #1147 --- lib/plausible_web/controllers/auth_controller.ex | 8 ++++++-- lib/plausible_web/templates/auth/activate.html.eex | 2 +- lib/plausible_web/templates/site/settings_people.html.eex | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index dfb878709..8849792a2 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -134,7 +134,11 @@ defmodule PlausibleWeb.AuthController do def activate_form(conn, _params) do user = conn.assigns[:current_user] - invitation = Repo.get_by(Plausible.Auth.Invitation, email: user.email) + + has_invitation = Repo.exists?( + from i in Plausible.Auth.Invitation, + where: i.email == ^user.email + ) has_code = Repo.exists?( @@ -144,7 +148,7 @@ defmodule PlausibleWeb.AuthController do render(conn, "activate.html", has_pin: has_code, - invitation: invitation, + has_invitation: has_invitation, layout: {PlausibleWeb.LayoutView, "focus.html"} ) end diff --git a/lib/plausible_web/templates/auth/activate.html.eex b/lib/plausible_web/templates/auth/activate.html.eex index d009f67f5..723b77ea8 100644 --- a/lib/plausible_web/templates/auth/activate.html.eex +++ b/lib/plausible_web/templates/auth/activate.html.eex @@ -47,7 +47,7 @@ <% end %> - <%= if !@invitation do %> + <%= if !@has_invitation do %> diff --git a/lib/plausible_web/templates/site/settings_people.html.eex b/lib/plausible_web/templates/site/settings_people.html.eex index 5918bd428..a67cfd9e4 100644 --- a/lib/plausible_web/templates/site/settings_people.html.eex +++ b/lib/plausible_web/templates/site/settings_people.html.eex @@ -7,7 +7,7 @@ <% end %>
-