Merge branch 'bugfix/1395-email-activation' into 'develop'
Bugfix/1395 email activation Closes #1395 See merge request pleroma/pleroma!1965
This commit is contained in:
commit
22554ac5ca
6 changed files with 36 additions and 4 deletions
|
@ -71,7 +71,7 @@ defmodule Pleroma.Plugs.OAuthPlug do
|
||||||
)
|
)
|
||||||
|
|
||||||
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
||||||
with %Token{user: %{deactivated: false} = user} = token_record <- Repo.one(query) do
|
with %Token{user: user} = token_record <- Repo.one(query) do
|
||||||
{:ok, user, token_record}
|
{:ok, user, token_record}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,9 +10,13 @@ defmodule Pleroma.Plugs.UserEnabledPlug do
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(%{assigns: %{user: %User{deactivated: true}}} = conn, _) do
|
def call(%{assigns: %{user: %User{} = user}} = conn, _) do
|
||||||
conn
|
if User.auth_active?(user) do
|
||||||
|> assign(:user, nil)
|
conn
|
||||||
|
else
|
||||||
|
conn
|
||||||
|
|> assign(:user, nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, _) do
|
def call(conn, _) do
|
||||||
|
|
|
@ -124,6 +124,9 @@ defmodule Pleroma.User do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Returns if the user should be allowed to authenticate"
|
||||||
|
def auth_active?(%User{deactivated: true}), do: false
|
||||||
|
|
||||||
def auth_active?(%User{confirmation_pending: true}),
|
def auth_active?(%User{confirmation_pending: true}),
|
||||||
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.Router do
|
||||||
pipeline :oauth do
|
pipeline :oauth do
|
||||||
plug(:fetch_session)
|
plug(:fetch_session)
|
||||||
plug(Pleroma.Plugs.OAuthPlug)
|
plug(Pleroma.Plugs.OAuthPlug)
|
||||||
|
plug(Pleroma.Plugs.UserEnabledPlug)
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
|
|
|
@ -16,6 +16,23 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do
|
||||||
assert ret_conn == conn
|
assert ret_conn == conn
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
|
||||||
|
%{conn: conn} do
|
||||||
|
old = Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
|
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||||
|
|
||||||
|
user = insert(:user, confirmation_pending: true)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> UserEnabledPlug.call(%{})
|
||||||
|
|
||||||
|
assert conn.assigns.user == nil
|
||||||
|
|
||||||
|
Pleroma.Config.put([:instance, :account_activation_required], old)
|
||||||
|
end
|
||||||
|
|
||||||
test "with a user that is deactivated, it removes that user", %{conn: conn} do
|
test "with a user that is deactivated, it removes that user", %{conn: conn} do
|
||||||
user = insert(:user, deactivated: true)
|
user = insert(:user, deactivated: true)
|
||||||
|
|
||||||
|
|
|
@ -1195,6 +1195,13 @@ defmodule Pleroma.UserTest do
|
||||||
refute User.auth_active?(local_user)
|
refute User.auth_active?(local_user)
|
||||||
assert User.auth_active?(confirmed_user)
|
assert User.auth_active?(confirmed_user)
|
||||||
assert User.auth_active?(remote_user)
|
assert User.auth_active?(remote_user)
|
||||||
|
|
||||||
|
# also shows unactive for deactivated users
|
||||||
|
|
||||||
|
deactivated_but_confirmed =
|
||||||
|
insert(:user, local: true, confirmation_pending: false, deactivated: true)
|
||||||
|
|
||||||
|
refute User.auth_active?(deactivated_but_confirmed)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "superuser?/1" do
|
describe "superuser?/1" do
|
||||||
|
|
Loading…
Reference in a new issue