Merge branch 'hide-suspended-groups' into 'master'

Avoid showing suspended broken UI for suspended/deleted groups

Closes #655

See merge request framasoft/mobilizon!896
This commit is contained in:
Thomas Citharel 2021-04-19 08:39:04 +00:00
commit a4a3475f65
5 changed files with 30 additions and 21 deletions

View file

@ -1,3 +1,8 @@
> 1% last 2 Chrome version
last 2 versions last 2 ChromeAndroid version
not dead last 2 Firefox version
last 2 FirefoxAndroid version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR

View file

@ -26,7 +26,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
} }
} }
) do ) do
with {:group, {:ok, %Actor{id: group_id} = group}} <- with {:group, {:ok, %Actor{id: group_id, suspended: false} = group}} <-
{:group, ActivityPub.find_or_make_group_from_nickname(name)}, {:group, ActivityPub.find_or_make_group_from_nickname(name)},
{:actor, %Actor{id: actor_id} = _actor} <- {:actor, Users.get_actor_for_user(user)}, {:actor, %Actor{id: actor_id} = _actor} <- {:actor, Users.get_actor_for_user(user)},
{:member, true} <- {:member, Actors.is_member?(actor_id, group_id)} do {:member, true} <- {:member, Actors.is_member?(actor_id, group_id)} do
@ -44,7 +44,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
end end
def find_group(_parent, %{preferred_username: name}, _resolution) do def find_group(_parent, %{preferred_username: name}, _resolution) do
with {:ok, actor} <- ActivityPub.find_or_make_group_from_nickname(name), with {:ok, %Actor{suspended: false} = actor} <-
ActivityPub.find_or_make_group_from_nickname(name),
%Actor{} = actor <- restrict_fields_for_non_member_request(actor) do %Actor{} = actor <- restrict_fields_for_non_member_request(actor) do
{:ok, actor} {:ok, actor}
else else

View file

@ -58,7 +58,11 @@ defmodule Mix.Tasks.Mobilizon.Users.Modify do
An user has been modified with the following information: An user has been modified with the following information:
- email: #{user.email} - email: #{user.email}
- Role: #{user.role} - Role: #{user.role}
- Activated: #{if user.confirmed_at, do: user.confirmed_at, else: "False"} - account status: #{
if user.confirmed_at,
do: "activated on #{DateTime.to_string(user.confirmed_at)} (UTC)",
else: "disabled"
}
""") """)
else else
{:makes_changes, false} -> {:makes_changes, false} ->

View file

@ -19,8 +19,11 @@ defmodule Mix.Tasks.Mobilizon.Users.Show do
actors <- Users.get_actors_for_user(user) do actors <- Users.get_actors_for_user(user) do
shell_info(""" shell_info("""
Informations for the user #{user.email}: Informations for the user #{user.email}:
- Activated: #{user.confirmed_at} - account status: #{
- Disabled: #{user.disabled} if user.confirmed_at,
do: "Activated on #{DateTime.to_string(user.confirmed_at)} (UTC)",
else: "disabled"
}
- Role: #{user.role} - Role: #{user.role}
#{display_actors(actors)} #{display_actors(actors)}
""") """)

View file

@ -76,16 +76,15 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
describe "show user" do describe "show user" do
test "show existing user" do test "show existing user" do
%User{confirmed_at: confirmed_at, role: role, disabled: disabled} = %User{confirmed_at: confirmed_at, role: role} = user = insert(:user, email: @email)
user = insert(:user, email: @email)
actor1 = insert(:actor, user: user) actor1 = insert(:actor, user: user)
actor2 = insert(:actor, user: user) actor2 = insert(:actor, user: user)
output = output =
"Informations for the user #{@email}:\n - Activated: #{confirmed_at}\n - Disabled: #{ "Informations for the user #{@email}:\n - account status: Activated on #{confirmed_at} (UTC)\n - Role: #{
disabled role
}\n - Role: #{role}\n Identities (2):\n - @#{actor1.preferred_username} / \n - @#{ }\n Identities (2):\n - @#{actor1.preferred_username} / \n - @#{
actor2.preferred_username actor2.preferred_username
} / \n\n\n" } / \n\n\n"
@ -139,30 +138,27 @@ defmodule Mix.Tasks.Mobilizon.UsersTest do
assert output_received == assert output_received ==
"An user has been modified with the following information:\n - email: #{ "An user has been modified with the following information:\n - email: #{
user.email user.email
}\n - Role: #{user.role}\n - Activated: False\n" }\n - Role: #{user.role}\n - account status: disabled\n"
assert {:ok, %User{email: email, confirmed_at: confirmed_at}} = assert {:ok, %User{confirmed_at: confirmed_at}} = Users.get_user_by_email(@email)
Users.get_user_by_email(@email)
assert is_nil(confirmed_at) assert is_nil(confirmed_at)
Modify.run([@email, "--enable"]) Modify.run([@email, "--enable"])
assert_received {:mix_shell, :info, [output_received]} assert_received {:mix_shell, :info, [output_received]}
assert {:ok, %User{email: email, confirmed_at: confirmed_at}} = assert {:ok, %User{confirmed_at: confirmed_at}} = Users.get_user_by_email(@email)
Users.get_user_by_email(@email)
assert output_received == assert output_received ==
"An user has been modified with the following information:\n - email: #{ "An user has been modified with the following information:\n - email: #{
user.email user.email
}\n - Role: #{user.role}\n - Activated: #{confirmed_at}\n" }\n - Role: #{user.role}\n - account status: activated on #{confirmed_at} (UTC)\n"
refute is_nil(confirmed_at) refute is_nil(confirmed_at)
Modify.run([@email, "--enable"]) Modify.run([@email, "--enable"])
assert {:ok, %User{email: email, confirmed_at: confirmed_at}} = assert {:ok, %User{confirmed_at: confirmed_at}} = Users.get_user_by_email(@email)
Users.get_user_by_email(@email)
refute is_nil(confirmed_at) refute is_nil(confirmed_at)
assert_received {:mix_shell, :info, [output_received]} assert_received {:mix_shell, :info, [output_received]}