Add a dropdown on participate menu, disallow listing participations

Now requires quering the person endpoint to know if an actor
participates in an event, organizers can make authenticated requests to
event { participants { } } to see the pending / approved participants.

Also closes #174

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-09-26 16:38:58 +02:00
parent 8a3e606c15
commit 757d2cabec
34 changed files with 655 additions and 439 deletions

View File

@@ -99,8 +99,8 @@ defmodule Mobilizon.EventsTest do
assert event.ends_on == DateTime.from_naive!(~N[2010-04-17 14:00:00Z], "Etc/UTC")
assert event.title == "some title"
assert hd(Events.list_participants_for_event(event.uuid)).actor.id == actor.id
assert hd(Events.list_participants_for_event(event.uuid)).role == :creator
assert hd(Events.list_participants_for_event(event.id)).actor.id == actor.id
assert hd(Events.list_participants_for_event(event.id)).role == :creator
end
test "create_event/1 with invalid data returns error changeset" do

View File

@@ -784,7 +784,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
assert :error == Transmogrifier.handle_incoming(reject_data)
# Organiser is not present since we use factories directly
assert Events.list_participants_for_event(event.uuid) |> Enum.map(& &1.id) ==
assert Events.list_participants_for_event(event.id) |> Enum.map(& &1.id) ==
[]
end
@@ -812,7 +812,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
assert activity.data["actor"] == participant_url
# The only participant left is the organizer
assert Events.list_participants_for_event(event.uuid) |> Enum.map(& &1.id) == [
assert Events.list_participants_for_event(event.id) |> Enum.map(& &1.id) == [
organizer_participation.id
]
end

View File

@@ -106,8 +106,8 @@ defmodule MobilizonWeb.FeedControllerTest do
assert entry.summary in [event1.title, event2.title]
end)
assert entry1.categories == [event1.category, tag1.slug]
assert entry2.categories == [event2.category, tag1.slug, tag2.slug]
assert entry1.categories == [tag1.slug]
assert entry2.categories == [tag1.slug, tag2.slug]
end
test "it returns a 404 page for the actor's public events iCal feed with an actor not publicly visible",
@@ -174,7 +174,7 @@ defmodule MobilizonWeb.FeedControllerTest do
assert entry1.summary == event1.title
assert entry1.categories == [event1.category, tag1.slug, tag2.slug]
assert entry1.categories == [tag1.slug, tag2.slug]
end
end
@@ -311,6 +311,7 @@ defmodule MobilizonWeb.FeedControllerTest do
[entry1] = ExIcal.parse(conn.resp_body)
assert entry1.summary == event1.title
assert entry1.categories == event1.tags |> Enum.map(& &1.slug)
end
test "it returns 404 for an not existing feed", %{conn: conn} do

View File

@@ -129,13 +129,15 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
actor: actor
} do
event = insert(:event, %{organizer_actor: actor})
participant = insert(:participant, %{actor: actor, event: event})
participant2 = insert(:participant, %{event: event})
insert(:participant, %{actor: actor, event: event, role: :creator})
user2 = insert(:user)
actor2 = insert(:actor, user: user2)
participant2 = insert(:participant, %{event: event, actor: actor2, role: :participant})
mutation = """
mutation {
leaveEvent(
actor_id: #{participant.actor.id},
actor_id: #{participant2.actor.id},
event_id: #{event.id}
) {
actor {
@@ -150,40 +152,64 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
res =
conn
|> auth_conn(user)
|> auth_conn(user2)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["leaveEvent"]["event"]["id"] == to_string(event.id)
assert json_response(res, 200)["data"]["leaveEvent"]["actor"]["id"] ==
to_string(participant.actor.id)
to_string(participant2.actor.id)
query = """
{
event(uuid: "#{event.uuid}") {
participants {
role,
actor {
preferredUsername
person(preferredUsername: "#{actor.preferred_username}") {
participations(eventId: "#{event.id}") {
event {
uuid,
title
},
role
}
}
}
}
"""
res =
conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
assert json_response(res, 200)["data"]["event"]["participants"] == [
assert json_response(res, 200)["data"]["person"]["participations"] == [
%{
"actor" => %{
"preferredUsername" => participant2.actor.preferred_username
"event" => %{
"uuid" => event.uuid,
"title" => event.title
},
"role" => "CREATOR"
}
]
query = """
{
person(preferredUsername: "#{actor2.preferred_username}") {
participations(eventId: "#{event.id}") {
event {
uuid,
title
},
role
}
}
}
"""
res =
conn
|> auth_conn(user2)
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
assert json_response(res, 200)["data"]["person"]["participations"] == []
end
test "actor_leave_event/3 should check if the participant is the only creator", %{
@@ -324,17 +350,23 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
assert hd(json_response(res, 200)["errors"])["message"] =~ "Participant not found"
end
test "list_participants_for_event/3 returns participants for an event", context do
test "list_participants_for_event/3 returns participants for an event", %{
conn: conn,
actor: actor,
user: user
} do
event =
@event
|> Map.put(:organizer_actor_id, context.actor.id)
|> Map.put(:organizer_actor_id, actor.id)
{:ok, event} = Events.create_event(event)
query = """
{
event(uuid: "#{event.uuid}") {
participants(roles: "participant,moderator,administrator,creator") {
participants(roles: "participant,moderator,administrator,creator", actor_id: "#{
actor.id
}") {
role,
actor {
preferredUsername
@@ -345,13 +377,16 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
"""
res =
context.conn
conn
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
assert json_response(res, 200)["errors"] == nil
assert json_response(res, 200)["data"]["event"]["participants"] == [
%{
"actor" => %{
"preferredUsername" => context.actor.preferred_username
"preferredUsername" => actor.preferred_username
},
"role" => "CREATOR"
}
@@ -368,7 +403,9 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
query = """
{
event(uuid: "#{event.uuid}") {
participants(page: 1, limit: 1, roles: "participant,moderator,administrator,creator") {
participants(page: 1, limit: 1, roles: "participant,moderator,administrator,creator", actorId: "#{
actor.id
}") {
role,
actor {
preferredUsername
@@ -379,7 +416,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
"""
res =
context.conn
conn
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
sorted_participants =
@@ -402,7 +440,9 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
query = """
{
event(uuid: "#{event.uuid}") {
participants(page: 2, limit: 1, roles: "participant,moderator,administrator,creator") {
participants(page: 2, limit: 1, roles: "participant,moderator,administrator,creator", actorId: "#{
actor.id
}") {
role,
actor {
preferredUsername
@@ -413,7 +453,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
"""
res =
context.conn
conn
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "participants"))
sorted_participants =
@@ -427,7 +468,7 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
assert sorted_participants == [
%{
"actor" => %{
"preferredUsername" => context.actor.preferred_username
"preferredUsername" => actor.preferred_username
},
"role" => "CREATOR"
}

View File

@@ -473,7 +473,9 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
assert hd(json_response(res, 200)["errors"])["message"] == "Person with name riri not found"
end
end
describe "get_current_person/3" do
test "get_current_person/3 can return the events the person is going to", context do
user = insert(:user)
actor = insert(:actor, user: user)
@@ -481,9 +483,11 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
query = """
{
loggedPerson {
goingToEvents {
uuid,
title
participations {
event {
uuid,
title
}
}
}
}
@@ -494,7 +498,7 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
assert json_response(res, 200)["data"]["loggedPerson"]["goingToEvents"] == []
assert json_response(res, 200)["data"]["loggedPerson"]["participations"] == []
event = insert(:event, %{organizer_actor: actor})
insert(:participant, %{actor: actor, event: event})
@@ -504,8 +508,8 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
assert json_response(res, 200)["data"]["loggedPerson"]["goingToEvents"] == [
%{"title" => event.title, "uuid" => event.uuid}
assert json_response(res, 200)["data"]["loggedPerson"]["participations"] == [
%{"event" => %{"title" => event.title, "uuid" => event.uuid}}
]
end
@@ -519,9 +523,11 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
query = """
{
person(preferredUsername: "#{actor.preferred_username}") {
goingToEvents {
uuid,
title
participations {
event {
uuid,
title
}
}
}
}
@@ -532,14 +538,16 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
assert json_response(res, 200)["data"]["person"]["goingToEvents"] == []
assert json_response(res, 200)["data"]["person"]["participations"] == []
query = """
{
person(preferredUsername: "#{actor_from_other_user.preferred_username}") {
goingToEvents {
uuid,
title
participations {
event {
uuid,
title
}
}
}
}
@@ -550,10 +558,45 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
assert json_response(res, 200)["data"]["person"]["goingToEvents"] == nil
assert json_response(res, 200)["data"]["person"]["participations"] == nil
assert hd(json_response(res, 200)["errors"])["message"] ==
"Actor id is not owned by authenticated user"
end
test "find_person/3 can return the participation for an identity on a specific event",
context do
user = insert(:user)
actor = insert(:actor, user: user)
event = insert(:event, organizer_actor: actor)
insert(:participant, event: event, actor: actor)
query = """
{
person(preferredUsername: "#{actor.preferred_username}") {
participations(eventId: "#{event.id}") {
event {
uuid,
title
}
}
}
}
"""
res =
context.conn
|> auth_conn(user)
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
assert json_response(res, 200)["data"]["person"]["participations"] == [
%{
"event" => %{
"uuid" => event.uuid,
"title" => event.title
}
}
]
end
end
end