Add group admin profiles
And other fixes Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -789,8 +789,22 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
|
||||
describe "handle incoming delete activities" do
|
||||
test "it works for incoming deletes" do
|
||||
%Actor{url: actor_url} = actor = insert(:actor)
|
||||
%Comment{url: comment_url} = insert(:comment, actor: nil, actor_id: actor.id)
|
||||
%Actor{url: actor_url} =
|
||||
actor = insert(:actor, url: "http://mobilizon.tld/@remote", domain: "mobilizon.tld")
|
||||
|
||||
%Comment{url: comment_url} =
|
||||
insert(:comment,
|
||||
actor: nil,
|
||||
actor_id: actor.id,
|
||||
url: "http://mobilizon.tld/comments/9f3794b8-11a0-4a98-8cb7-475ab332c701"
|
||||
)
|
||||
|
||||
Mock
|
||||
|> expect(:call, fn
|
||||
%{method: :get, url: "http://mobilizon.tld/comments/9f3794b8-11a0-4a98-8cb7-475ab332c701"},
|
||||
_opts ->
|
||||
{:ok, %Tesla.Env{status: 410, body: "Gone"}}
|
||||
end)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
@@ -843,7 +857,9 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
||||
setup :set_mox_from_context
|
||||
|
||||
test "it works for incoming actor deletes" do
|
||||
%Actor{url: url} = actor = insert(:actor, url: "https://framapiaf.org/users/admin")
|
||||
%Actor{url: url} =
|
||||
actor = insert(:actor, url: "https://framapiaf.org/users/admin", domain: "framapiaf.org")
|
||||
|
||||
%Event{url: event1_url} = event1 = insert(:event, organizer_actor: actor)
|
||||
insert(:event, organizer_actor: actor)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
||||
@@ -87,13 +88,8 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
end
|
||||
|
||||
describe "list groups" do
|
||||
test "list_groups/3 returns all public groups", %{conn: conn} do
|
||||
group = insert(:group, visibility: :public)
|
||||
insert(:group, visibility: :unlisted)
|
||||
insert(:group, visibility: :private)
|
||||
|
||||
query = """
|
||||
{
|
||||
@list_groups_query """
|
||||
{
|
||||
groups {
|
||||
elements {
|
||||
preferredUsername,
|
||||
@@ -101,14 +97,49 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
total
|
||||
}
|
||||
}
|
||||
"""
|
||||
"""
|
||||
|
||||
res = AbsintheHelpers.graphql_query(conn, query: query)
|
||||
test "list_groups/3 doesn't returns all groups if not authenticated", %{conn: conn} do
|
||||
insert(:group, visibility: :public)
|
||||
insert(:group, visibility: :unlisted)
|
||||
insert(:group, visibility: :private)
|
||||
|
||||
assert res["data"]["groups"]["total"] == 1
|
||||
res = AbsintheHelpers.graphql_query(conn, query: @list_groups_query)
|
||||
|
||||
assert hd(res["data"]["groups"]["elements"])["preferredUsername"] ==
|
||||
group.preferred_username
|
||||
assert hd(res["errors"])["message"] == "You may not list groups unless moderator."
|
||||
end
|
||||
|
||||
test "list_groups/3 doesn't return all groups if not a moderator", %{conn: conn} do
|
||||
insert(:group, visibility: :public)
|
||||
insert(:group, visibility: :unlisted)
|
||||
insert(:group, visibility: :private)
|
||||
user = insert(:user)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(query: @list_groups_query)
|
||||
|
||||
assert hd(res["errors"])["message"] == "You may not list groups unless moderator."
|
||||
end
|
||||
|
||||
test "list_groups/3 returns all groups if a moderator", %{conn: conn} do
|
||||
group_1 = insert(:group, visibility: :public)
|
||||
group_2 = insert(:group, visibility: :unlisted)
|
||||
group_3 = insert(:group, visibility: :private)
|
||||
user = insert(:user, role: :moderator)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(query: @list_groups_query)
|
||||
|
||||
assert res["data"]["groups"]["total"] == 3
|
||||
|
||||
assert res["data"]["groups"]["elements"]
|
||||
|> Enum.map(& &1["preferredUsername"])
|
||||
|> MapSet.new() ==
|
||||
[group_1, group_2, group_3] |> Enum.map(& &1.preferred_username) |> MapSet.new()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -209,57 +240,70 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
end
|
||||
|
||||
describe "delete a group" do
|
||||
@delete_group_mutation """
|
||||
mutation DeleteGroup($groupId: ID!) {
|
||||
deleteGroup(
|
||||
groupId: $groupId
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
test "delete_group/3 deletes a group", %{conn: conn, user: user, actor: actor} do
|
||||
group = insert(:group)
|
||||
insert(:member, parent: group, actor: actor, role: :administrator)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteGroup(
|
||||
actor_id: #{actor.id},
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @delete_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert json_response(res, 200)["errors"] == nil
|
||||
assert json_response(res, 200)["data"]["deleteGroup"]["id"] == to_string(group.id)
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["deleteGroup"]["id"] == to_string(group.id)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
assert_enqueued(
|
||||
worker: Mobilizon.Service.Workers.Background,
|
||||
args: %{
|
||||
"actor_id" => group.id,
|
||||
"author_id" => actor.id,
|
||||
"op" => "delete_actor",
|
||||
"reserve_username" => true,
|
||||
"suspension" => false
|
||||
}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
||||
# Can't be used right now, probably because we try to run a transaction in a Oban Job while using Ecto Sandbox
|
||||
|
||||
# assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
|
||||
|
||||
# res =
|
||||
# conn
|
||||
# |> auth_conn(user)
|
||||
# |> AbsintheHelpers.graphql_query(
|
||||
# query: @delete_group_mutation,
|
||||
# variables: %{groupId: group.id}
|
||||
# )
|
||||
|
||||
# assert res["data"] == "tt"
|
||||
# assert hd(json_response(res, 200)["errors"])["message"] =~ "not found"
|
||||
end
|
||||
|
||||
test "delete_group/3 should check user authentication", %{conn: conn, actor: actor} do
|
||||
group = insert(:group)
|
||||
insert(:member, parent: group, actor: actor, role: :member)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteGroup(
|
||||
actor_id: #{actor.id},
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @delete_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||
assert hd(res["errors"])["message"] =~ "logged-in"
|
||||
end
|
||||
|
||||
test "delete_group/3 should check the actor is owned by the user", %{
|
||||
@@ -270,49 +314,33 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
group = insert(:group)
|
||||
insert(:member, parent: group, actor: actor, role: :member)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteGroup(
|
||||
actor_id: 159,
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @delete_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
||||
assert hd(res["errors"])["message"] ==
|
||||
"Actor id is not an administrator of the selected group"
|
||||
end
|
||||
|
||||
test "delete_group/3 should check the actor is a member of this group", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
actor: actor
|
||||
user: user
|
||||
} do
|
||||
group = insert(:group)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteGroup(
|
||||
actor_id: #{actor.id},
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @delete_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not a member"
|
||||
assert hd(res["errors"])["message"] =~ "not a member"
|
||||
end
|
||||
|
||||
test "delete_group/3 should check the actor is an administrator of this group", %{
|
||||
@@ -323,23 +351,15 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
group = insert(:group)
|
||||
insert(:member, parent: group, actor: actor, role: :member)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteGroup(
|
||||
actor_id: #{actor.id},
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @delete_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not an administrator"
|
||||
assert hd(res["errors"])["message"] =~ "not an administrator"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -140,6 +140,14 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
||||
end
|
||||
|
||||
describe "Member Resolver to leave from a group" do
|
||||
@leave_group_mutation """
|
||||
mutation LeaveGroup($groupId: ID!) {
|
||||
leaveGroup(groupId: $groupId) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
test "leave_group/3 should delete a member from a group", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
@@ -149,23 +157,16 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
||||
insert(:member, role: :administrator, parent: group)
|
||||
%Member{id: member_id} = insert(:member, %{actor: actor, parent: group})
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
leaveGroup(
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @leave_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert json_response(res, 200)["errors"] == nil
|
||||
assert json_response(res, 200)["data"]["leaveGroup"]["id"] == to_string(member_id)
|
||||
assert res["errors"] == nil
|
||||
assert res["data"]["leaveGroup"]["id"] == to_string(member_id)
|
||||
end
|
||||
|
||||
test "leave_group/3 should check if the member is the only administrator", %{
|
||||
@@ -177,43 +178,29 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
||||
insert(:member, %{actor: actor, role: :creator, parent: group})
|
||||
insert(:member, %{parent: group})
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
leaveGroup(
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @leave_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "only administrator"
|
||||
assert hd(res["errors"])["message"] =~ "only administrator"
|
||||
end
|
||||
|
||||
test "leave_group/3 should check the user is logged in", %{conn: conn, actor: actor} do
|
||||
group = insert(:group)
|
||||
insert(:member, %{actor: actor, parent: group})
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
leaveGroup(
|
||||
group_id: #{group.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @leave_group_mutation,
|
||||
variables: %{groupId: group.id}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||
assert hd(res["errors"])["message"] =~ "logged-in"
|
||||
end
|
||||
|
||||
test "leave_group/3 should check the group exists", %{
|
||||
@@ -224,22 +211,15 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
||||
group = insert(:group)
|
||||
insert(:member, %{actor: actor, parent: group})
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
leaveGroup(
|
||||
group_id: 1042
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @leave_group_mutation,
|
||||
variables: %{groupId: 1042}
|
||||
)
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "Group not found"
|
||||
assert hd(res["errors"])["message"] =~ "Group not found"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -508,7 +508,13 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||
|
||||
assert_enqueued(
|
||||
worker: Workers.Background,
|
||||
args: %{"actor_id" => person_id, "op" => "delete_actor", "reserve_username" => true}
|
||||
args: %{
|
||||
"actor_id" => person_id,
|
||||
"op" => "delete_actor",
|
||||
"author_id" => nil,
|
||||
"suspension" => false,
|
||||
"reserve_username" => true
|
||||
}
|
||||
)
|
||||
|
||||
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
|
||||
|
||||
@@ -367,7 +367,13 @@ defmodule Mobilizon.ActorsTest do
|
||||
|
||||
assert_enqueued(
|
||||
worker: Workers.Background,
|
||||
args: %{"actor_id" => actor.id, "op" => "delete_actor", "reserve_username" => true}
|
||||
args: %{
|
||||
"actor_id" => actor.id,
|
||||
"op" => "delete_actor",
|
||||
"author_id" => nil,
|
||||
"suspension" => false,
|
||||
"reserve_username" => true
|
||||
}
|
||||
)
|
||||
|
||||
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
|
||||
|
||||
Reference in New Issue
Block a user