forked from potsda.mn/mobilizon
Split GraphQL as separate context
This commit is contained in:
parent
a7acf17a4a
commit
ba3ad713c0
|
@ -1,6 +1,6 @@
|
||||||
defmodule MobilizonWeb.Schema.Utils do
|
defmodule Mobilizon.GraphQL.Helpers.Error do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Helper functions for MobilizonWeb.Schema
|
Helper functions for Mobilizon.GraphQL
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle_errors(fun) do
|
def handle_errors(fun) do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Address do
|
defmodule Mobilizon.GraphQL.Resolvers.Address do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the comment-related GraphQL calls
|
Handles the comment-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
|
@ -11,10 +11,12 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||||
@doc """
|
@doc """
|
||||||
Search an address
|
Search an address
|
||||||
"""
|
"""
|
||||||
@spec search(map(), map(), map()) :: {:ok, list(Address.t())}
|
@spec search(map, map, map) :: {:ok, [Address.t()]}
|
||||||
def search(_parent, %{query: query, locale: locale, page: _page, limit: _limit}, %{
|
def search(
|
||||||
context: %{ip: ip}
|
_parent,
|
||||||
}) do
|
%{query: query, locale: locale, page: _page, limit: _limit},
|
||||||
|
%{context: %{ip: ip}}
|
||||||
|
) do
|
||||||
geolix = Geolix.lookup(ip)
|
geolix = Geolix.lookup(ip)
|
||||||
|
|
||||||
country_code =
|
country_code =
|
||||||
|
@ -31,7 +33,7 @@ defmodule MobilizonWeb.Resolvers.Address do
|
||||||
@doc """
|
@doc """
|
||||||
Reverse geocode some coordinates
|
Reverse geocode some coordinates
|
||||||
"""
|
"""
|
||||||
@spec reverse_geocode(map(), map(), map()) :: {:ok, list(Address.t())}
|
@spec reverse_geocode(map, map, map) :: {:ok, [Address.t()]}
|
||||||
def reverse_geocode(
|
def reverse_geocode(
|
||||||
_parent,
|
_parent,
|
||||||
%{longitude: longitude, latitude: latitude, zoom: zoom, locale: locale},
|
%{longitude: longitude, latitude: latitude, zoom: zoom, locale: locale},
|
|
@ -1,13 +1,13 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Admin do
|
defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the report-related GraphQL calls.
|
Handles the report-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Mobilizon.Users.Guards
|
import Mobilizon.Users.Guards
|
||||||
|
|
||||||
alias Mobilizon.Admin.ActionLog
|
|
||||||
alias Mobilizon.Actors
|
alias Mobilizon.Actors
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
|
alias Mobilizon.Admin.ActionLog
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.{Event, Comment}
|
alias Mobilizon.Events.{Event, Comment}
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
|
@ -68,36 +68,28 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp transform_action_log(Note, :create, %ActionLog{
|
defp transform_action_log(Note, :create, %ActionLog{changes: changes}) do
|
||||||
changes: changes
|
|
||||||
}) do
|
|
||||||
%{
|
%{
|
||||||
action: :note_creation,
|
action: :note_creation,
|
||||||
object: convert_changes_to_struct(Note, changes)
|
object: convert_changes_to_struct(Note, changes)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp transform_action_log(Note, :delete, %ActionLog{
|
defp transform_action_log(Note, :delete, %ActionLog{changes: changes}) do
|
||||||
changes: changes
|
|
||||||
}) do
|
|
||||||
%{
|
%{
|
||||||
action: :note_deletion,
|
action: :note_deletion,
|
||||||
object: convert_changes_to_struct(Note, changes)
|
object: convert_changes_to_struct(Note, changes)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp transform_action_log(Event, :delete, %ActionLog{
|
defp transform_action_log(Event, :delete, %ActionLog{changes: changes}) do
|
||||||
changes: changes
|
|
||||||
}) do
|
|
||||||
%{
|
%{
|
||||||
action: :event_deletion,
|
action: :event_deletion,
|
||||||
object: convert_changes_to_struct(Event, changes)
|
object: convert_changes_to_struct(Event, changes)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp transform_action_log(Comment, :delete, %ActionLog{
|
defp transform_action_log(Comment, :delete, %ActionLog{changes: changes}) do
|
||||||
changes: changes
|
|
||||||
}) do
|
|
||||||
%{
|
%{
|
||||||
action: :comment_deletion,
|
action: :comment_deletion,
|
||||||
object: convert_changes_to_struct(Comment, changes)
|
object: convert_changes_to_struct(Comment, changes)
|
||||||
|
@ -118,9 +110,7 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_dashboard(_parent, _args, %{
|
def get_dashboard(_parent, _args, %{context: %{current_user: %User{role: role}}})
|
||||||
context: %{current_user: %User{role: role}}
|
|
||||||
})
|
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
last_public_event_published =
|
last_public_event_published =
|
||||||
case Events.list_events(1, 1, :inserted_at, :desc) do
|
case Events.list_events(1, 1, :inserted_at, :desc) do
|
||||||
|
@ -142,9 +132,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
{:error, "You need to be logged-in and an administrator to access dashboard statistics"}
|
{:error, "You need to be logged-in and an administrator to access dashboard statistics"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_relay_followers(_parent, %{page: page, limit: limit}, %{
|
def list_relay_followers(
|
||||||
context: %{current_user: %User{role: role}}
|
_parent,
|
||||||
})
|
%{page: page, limit: limit},
|
||||||
|
%{context: %{current_user: %User{role: role}}}
|
||||||
|
)
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
with %Actor{} = relay_actor <- Relay.get_actor() do
|
with %Actor{} = relay_actor <- Relay.get_actor() do
|
||||||
%Page{} =
|
%Page{} =
|
||||||
|
@ -154,9 +146,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_relay_followings(_parent, %{page: page, limit: limit}, %{
|
def list_relay_followings(
|
||||||
context: %{current_user: %User{role: role}}
|
_parent,
|
||||||
})
|
%{page: page, limit: limit},
|
||||||
|
%{context: %{current_user: %User{role: role}}}
|
||||||
|
)
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
with %Actor{} = relay_actor <- Relay.get_actor() do
|
with %Actor{} = relay_actor <- Relay.get_actor() do
|
||||||
%Page{} =
|
%Page{} =
|
||||||
|
@ -188,9 +182,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept_subscription(_parent, %{address: address}, %{
|
def accept_subscription(
|
||||||
context: %{current_user: %User{role: role}}
|
_parent,
|
||||||
})
|
%{address: address},
|
||||||
|
%{context: %{current_user: %User{role: role}}}
|
||||||
|
)
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
case Relay.accept(address) do
|
case Relay.accept(address) do
|
||||||
{:ok, _activity, follow} ->
|
{:ok, _activity, follow} ->
|
||||||
|
@ -201,9 +197,11 @@ defmodule MobilizonWeb.Resolvers.Admin do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject_subscription(_parent, %{address: address}, %{
|
def reject_subscription(
|
||||||
context: %{current_user: %User{role: role}}
|
_parent,
|
||||||
})
|
%{address: address},
|
||||||
|
%{context: %{current_user: %User{role: role}}}
|
||||||
|
)
|
||||||
when is_admin(role) do
|
when is_admin(role) do
|
||||||
case Relay.reject(address) do
|
case Relay.reject(address) do
|
||||||
{:ok, _activity, follow} ->
|
{:ok, _activity, follow} ->
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Comment do
|
defmodule Mobilizon.GraphQL.Resolvers.Comment do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the comment-related GraphQL calls.
|
Handles the comment-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -17,9 +17,11 @@ defmodule MobilizonWeb.Resolvers.Comment do
|
||||||
{:ok, Events.get_thread_replies(thread_id)}
|
{:ok, Events.get_thread_replies(thread_id)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_comment(_parent, %{actor_id: actor_id} = args, %{
|
def create_comment(
|
||||||
context: %{current_user: %User{} = user}
|
_parent,
|
||||||
}) do
|
%{actor_id: actor_id} = args,
|
||||||
|
%{context: %{current_user: %User{} = user}}
|
||||||
|
) do
|
||||||
with {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
|
with {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
|
||||||
{:ok, _, %CommentModel{} = comment} <-
|
{:ok, _, %CommentModel{} = comment} <-
|
||||||
Comments.create_comment(args) do
|
Comments.create_comment(args) do
|
||||||
|
@ -34,9 +36,11 @@ defmodule MobilizonWeb.Resolvers.Comment do
|
||||||
{:error, "You are not allowed to create a comment if not connected"}
|
{:error, "You are not allowed to create a comment if not connected"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_comment(_parent, %{actor_id: actor_id, comment_id: comment_id}, %{
|
def delete_comment(
|
||||||
context: %{current_user: %User{role: role} = user}
|
_parent,
|
||||||
}) do
|
%{actor_id: actor_id, comment_id: comment_id},
|
||||||
|
%{context: %{current_user: %User{role: role} = user}}
|
||||||
|
) do
|
||||||
with {actor_id, ""} <- Integer.parse(actor_id),
|
with {actor_id, ""} <- Integer.parse(actor_id),
|
||||||
{:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
|
{:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
|
||||||
%CommentModel{} = comment <- Events.get_comment_with_preload(comment_id) do
|
%CommentModel{} = comment <- Events.get_comment_with_preload(comment_id) do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Config do
|
defmodule Mobilizon.GraphQL.Resolvers.Config do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the config-related GraphQL calls.
|
Handles the config-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -10,9 +10,7 @@ defmodule MobilizonWeb.Resolvers.Config do
|
||||||
@doc """
|
@doc """
|
||||||
Gets config.
|
Gets config.
|
||||||
"""
|
"""
|
||||||
def get_config(_parent, _params, %{
|
def get_config(_parent, _params, %{context: %{ip: ip}}) do
|
||||||
context: %{ip: ip}
|
|
||||||
}) do
|
|
||||||
geolix = Geolix.lookup(ip)
|
geolix = Geolix.lookup(ip)
|
||||||
|
|
||||||
country_code =
|
country_code =
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Event do
|
defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the event-related GraphQL calls.
|
Handles the event-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -8,10 +8,11 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
|
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Person
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub.Activity
|
alias Mobilizon.Federation.ActivityPub.Activity
|
||||||
|
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
alias MobilizonWeb.Resolvers.Person
|
|
||||||
|
|
||||||
# We limit the max number of events that can be retrieved
|
# We limit the max number of events that can be retrieved
|
||||||
@event_max_limit 100
|
@event_max_limit 100
|
||||||
|
@ -40,8 +41,9 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp find_private_event(_parent, %{uuid: uuid}, _resolution),
|
defp find_private_event(_parent, %{uuid: uuid}, _resolution) do
|
||||||
do: {:error, "Event with UUID #{uuid} not found"}
|
{:error, "Event with UUID #{uuid} not found"}
|
||||||
|
end
|
||||||
|
|
||||||
def find_event(parent, %{uuid: uuid} = args, resolution) do
|
def find_event(parent, %{uuid: uuid} = args, resolution) do
|
||||||
case {:has_event, Mobilizon.Events.get_public_event_by_uuid_with_preload(uuid)} do
|
case {:has_event, Mobilizon.Events.get_public_event_by_uuid_with_preload(uuid)} do
|
||||||
|
@ -216,11 +218,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||||
def update_participation(
|
def update_participation(
|
||||||
_parent,
|
_parent,
|
||||||
%{id: participation_id, moderator_actor_id: moderator_actor_id, role: new_role},
|
%{id: participation_id, moderator_actor_id: moderator_actor_id, role: new_role},
|
||||||
%{
|
%{context: %{current_user: user}}
|
||||||
context: %{
|
|
||||||
current_user: user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) do
|
) do
|
||||||
# Check that moderator provided is rightly authenticated
|
# Check that moderator provided is rightly authenticated
|
||||||
with {:is_owned, moderator_actor} <- User.owns_actor(user, moderator_actor_id),
|
with {:is_owned, moderator_actor} <- User.owns_actor(user, moderator_actor_id),
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.FeedToken do
|
defmodule Mobilizon.GraphQL.Resolvers.FeedToken do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the feed tokens-related GraphQL calls.
|
Handles the feed tokens-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -13,10 +13,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
|
||||||
@doc """
|
@doc """
|
||||||
Create an feed token for an user and a defined actor
|
Create an feed token for an user and a defined actor
|
||||||
"""
|
"""
|
||||||
@spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()} | {:error, String.t()}
|
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()} | {:error, String.t()}
|
||||||
def create_feed_token(_parent, %{actor_id: actor_id}, %{
|
def create_feed_token(
|
||||||
context: %{current_user: %User{id: id} = user}
|
_parent,
|
||||||
}) do
|
%{actor_id: actor_id},
|
||||||
|
%{context: %{current_user: %User{id: id} = user}}
|
||||||
|
) do
|
||||||
with {:is_owned, %Actor{}} <- User.owns_actor(user, actor_id),
|
with {:is_owned, %Actor{}} <- User.owns_actor(user, actor_id),
|
||||||
{:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id, "actor_id" => actor_id}) do
|
{:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id, "actor_id" => actor_id}) do
|
||||||
{:ok, feed_token}
|
{:ok, feed_token}
|
||||||
|
@ -29,16 +31,14 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
|
||||||
@doc """
|
@doc """
|
||||||
Create an feed token for an user
|
Create an feed token for an user
|
||||||
"""
|
"""
|
||||||
@spec create_feed_token(any(), map(), map()) :: {:ok, FeedToken.t()}
|
@spec create_feed_token(any, map, map) :: {:ok, FeedToken.t()}
|
||||||
def create_feed_token(_parent, %{}, %{
|
def create_feed_token(_parent, %{}, %{context: %{current_user: %User{id: id}}}) do
|
||||||
context: %{current_user: %User{id: id}}
|
|
||||||
}) do
|
|
||||||
with {:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id}) do
|
with {:ok, feed_token} <- Events.create_feed_token(%{"user_id" => id}) do
|
||||||
{:ok, feed_token}
|
{:ok, feed_token}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec create_feed_token(any(), map(), map()) :: {:error, String.t()}
|
@spec create_feed_token(any, map, map) :: {:error, String.t()}
|
||||||
def create_feed_token(_parent, _args, %{}) do
|
def create_feed_token(_parent, _args, %{}) do
|
||||||
{:error, "You are not allowed to create a feed token if not connected"}
|
{:error, "You are not allowed to create a feed token if not connected"}
|
||||||
end
|
end
|
||||||
|
@ -46,10 +46,12 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
|
||||||
@doc """
|
@doc """
|
||||||
Delete a feed token
|
Delete a feed token
|
||||||
"""
|
"""
|
||||||
@spec delete_feed_token(any(), map(), map()) :: {:ok, map()} | {:error, String.t()}
|
@spec delete_feed_token(any, map, map) :: {:ok, map} | {:error, String.t()}
|
||||||
def delete_feed_token(_parent, %{token: token}, %{
|
def delete_feed_token(
|
||||||
context: %{current_user: %User{id: id} = _user}
|
_parent,
|
||||||
}) do
|
%{token: token},
|
||||||
|
%{context: %{current_user: %User{id: id} = _user}}
|
||||||
|
) do
|
||||||
with {:ok, token} <- Ecto.UUID.cast(token),
|
with {:ok, token} <- Ecto.UUID.cast(token),
|
||||||
{:no_token, %FeedToken{actor: actor, user: %User{} = user} = feed_token} <-
|
{:no_token, %FeedToken{actor: actor, user: %User{} = user} = feed_token} <-
|
||||||
{:no_token, Events.get_feed_token(token)},
|
{:no_token, Events.get_feed_token(token)},
|
||||||
|
@ -73,7 +75,7 @@ defmodule MobilizonWeb.Resolvers.FeedToken do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec delete_feed_token(any(), map(), map()) :: {:error, String.t()}
|
@spec delete_feed_token(any, map, map) :: {:error, String.t()}
|
||||||
def delete_feed_token(_parent, _args, %{}) do
|
def delete_feed_token(_parent, _args, %{}) do
|
||||||
{:error, "You are not allowed to delete a feed token if not connected"}
|
{:error, "You are not allowed to delete a feed token if not connected"}
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Group do
|
defmodule Mobilizon.GraphQL.Resolvers.Group do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the group-related GraphQL calls.
|
Handles the group-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -7,10 +7,11 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||||
alias Mobilizon.Actors.{Actor, Member}
|
alias Mobilizon.Actors.{Actor, Member}
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Person
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub
|
alias Mobilizon.Federation.ActivityPub
|
||||||
|
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
alias MobilizonWeb.Resolvers.Person
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
|
@ -42,11 +43,7 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||||
@doc """
|
@doc """
|
||||||
Create a new group. The creator is automatically added as admin
|
Create a new group. The creator is automatically added as admin
|
||||||
"""
|
"""
|
||||||
def create_group(
|
def create_group(_parent, args, %{context: %{current_user: user}}) do
|
||||||
_parent,
|
|
||||||
args,
|
|
||||||
%{context: %{current_user: user}}
|
|
||||||
) do
|
|
||||||
with creator_actor_id <- Map.get(args, :creator_actor_id),
|
with creator_actor_id <- Map.get(args, :creator_actor_id),
|
||||||
{:is_owned, %Actor{} = creator_actor} <- User.owns_actor(user, creator_actor_id),
|
{:is_owned, %Actor{} = creator_actor} <- User.owns_actor(user, creator_actor_id),
|
||||||
args <- Map.put(args, :creator_actor, creator_actor),
|
args <- Map.put(args, :creator_actor, creator_actor),
|
||||||
|
@ -180,7 +177,7 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||||
# We check that the actor asking to leave the group is not it's only administrator
|
# We check that the actor asking to leave the group is not it's only administrator
|
||||||
# We start by fetching the list of administrator or creators and if there's only one of them
|
# We start by fetching the list of administrator or creators and if there's only one of them
|
||||||
# and that it's the actor requesting leaving the group we return true
|
# and that it's the actor requesting leaving the group we return true
|
||||||
@spec check_that_member_is_not_last_administrator(integer(), integer()) :: boolean()
|
@spec check_that_member_is_not_last_administrator(integer, integer) :: boolean
|
||||||
defp check_that_member_is_not_last_administrator(group_id, actor_id) do
|
defp check_that_member_is_not_last_administrator(group_id, actor_id) do
|
||||||
case Actors.list_administrator_members_for_group(group_id) do
|
case Actors.list_administrator_members_for_group(group_id) do
|
||||||
[%Member{actor: %Actor{id: member_actor_id}}] ->
|
[%Member{actor: %Actor{id: member_actor_id}}] ->
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Member do
|
defmodule Mobilizon.GraphQL.Resolvers.Member do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the member-related GraphQL calls
|
Handles the member-related GraphQL calls
|
||||||
"""
|
"""
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Person do
|
defmodule Mobilizon.GraphQL.Resolvers.Person do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the person-related GraphQL calls
|
Handles the person-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
|
@ -191,9 +191,11 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||||
@doc """
|
@doc """
|
||||||
Returns the participation for a specific event
|
Returns the participation for a specific event
|
||||||
"""
|
"""
|
||||||
def person_participations(%Actor{id: actor_id}, %{event_id: event_id}, %{
|
def person_participations(
|
||||||
context: %{current_user: user}
|
%Actor{id: actor_id},
|
||||||
}) do
|
%{event_id: event_id},
|
||||||
|
%{context: %{current_user: user}}
|
||||||
|
) do
|
||||||
with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id),
|
with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id),
|
||||||
{:no_participant, {:ok, %Participant{} = participant}} <-
|
{:no_participant, {:ok, %Participant{} = participant}} <-
|
||||||
{:no_participant, Events.get_participant(event_id, actor_id)} do
|
{:no_participant, Events.get_participant(event_id, actor_id)} do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Picture do
|
defmodule Mobilizon.GraphQL.Resolvers.Picture do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the picture-related GraphQL calls
|
Handles the picture-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +44,7 @@ defmodule MobilizonWeb.Resolvers.Picture do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec upload_picture(map(), map(), map()) :: {:ok, Picture.t()} | {:error, any()}
|
@spec upload_picture(map, map, map) :: {:ok, Picture.t()} | {:error, any}
|
||||||
def upload_picture(
|
def upload_picture(
|
||||||
_parent,
|
_parent,
|
||||||
%{file: %Plug.Upload{} = file, actor_id: actor_id} = args,
|
%{file: %Plug.Upload{} = file, actor_id: actor_id} = args,
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Report do
|
defmodule Mobilizon.GraphQL.Resolvers.Report do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the report-related GraphQL calls.
|
Handles the report-related GraphQL calls.
|
||||||
"""
|
"""
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Search do
|
defmodule Mobilizon.GraphQL.Resolvers.Search do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the event-related GraphQL calls
|
Handles the event-related GraphQL calls
|
||||||
"""
|
"""
|
|
@ -1,10 +1,9 @@
|
||||||
defmodule MobilizonWeb.Resolvers.Tag do
|
defmodule Mobilizon.GraphQL.Resolvers.Tag do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the tag-related GraphQL calls
|
Handles the tag-related GraphQL calls
|
||||||
"""
|
"""
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.{Event, Tag}
|
||||||
alias Mobilizon.Events.Tag
|
|
||||||
|
|
||||||
def list_tags(_parent, %{page: page, limit: limit}, _resolution) do
|
def list_tags(_parent, %{page: page, limit: limit}, _resolution) do
|
||||||
tags = Mobilizon.Events.list_tags(page, limit)
|
tags = Mobilizon.Events.list_tags(page, limit)
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.User do
|
defmodule Mobilizon.GraphQL.Resolvers.User do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Handles the user-related GraphQL calls.
|
Handles the user-related GraphQL calls.
|
||||||
"""
|
"""
|
||||||
|
@ -24,15 +24,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
@doc """
|
@doc """
|
||||||
Return current logged-in user
|
Return current logged-in user
|
||||||
"""
|
"""
|
||||||
def get_current_user(
|
def get_current_user(_parent, _args, %{context: %{current_user: user}}) do
|
||||||
_parent,
|
|
||||||
_args,
|
|
||||||
%{
|
|
||||||
context: %{
|
|
||||||
current_user: user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) do
|
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,13 +38,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
def list_and_count_users(
|
def list_and_count_users(
|
||||||
_parent,
|
_parent,
|
||||||
%{page: page, limit: limit, sort: sort, direction: direction},
|
%{page: page, limit: limit, sort: sort, direction: direction},
|
||||||
%{
|
%{context: %{current_user: %User{role: role}}}
|
||||||
context: %{
|
|
||||||
current_user: %User{
|
|
||||||
role: role
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
when is_moderator(role) do
|
when is_moderator(role) do
|
||||||
total = Task.async(&Users.count_users/0)
|
total = Task.async(&Users.count_users/0)
|
||||||
|
@ -61,8 +47,9 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
{:ok, %{total: Task.await(total), elements: Task.await(elements)}}
|
{:ok, %{total: Task.await(total), elements: Task.await(elements)}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_and_count_users(_parent, _args, _resolution),
|
def list_and_count_users(_parent, _args, _resolution) do
|
||||||
do: {:error, "You need to have admin access to list users"}
|
{:error, "You need to have admin access to list users"}
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Login an user. Returns a token and the user
|
Login an user. Returns a token and the user
|
||||||
|
@ -87,13 +74,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
@doc """
|
@doc """
|
||||||
Refresh a token
|
Refresh a token
|
||||||
"""
|
"""
|
||||||
def refresh_token(
|
def refresh_token(_parent, %{refresh_token: refresh_token}, _context) do
|
||||||
_parent,
|
|
||||||
%{
|
|
||||||
refresh_token: refresh_token
|
|
||||||
},
|
|
||||||
_context
|
|
||||||
) do
|
|
||||||
with {:ok, user, _claims} <- Auth.Guardian.resource_from_token(refresh_token),
|
with {:ok, user, _claims} <- Auth.Guardian.resource_from_token(refresh_token),
|
||||||
{:ok, _old, {exchanged_token, _claims}} <-
|
{:ok, _old, {exchanged_token, _claims}} <-
|
||||||
Auth.Guardian.exchange(refresh_token, ["access", "refresh"], "access"),
|
Auth.Guardian.exchange(refresh_token, ["access", "refresh"], "access"),
|
||||||
|
@ -106,8 +87,9 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_token(_parent, _params, _context),
|
def refresh_token(_parent, _params, _context) do
|
||||||
do: {:error, "You need to have an existing token to get a refresh token"}
|
{:error, "You need to have an existing token to get a refresh token"}
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Register an user:
|
Register an user:
|
||||||
|
@ -115,7 +97,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
- create the user
|
- create the user
|
||||||
- send a validation email to the user
|
- send a validation email to the user
|
||||||
"""
|
"""
|
||||||
@spec create_user(any(), map(), any()) :: tuple()
|
@spec create_user(any, map, any) :: tuple
|
||||||
def create_user(_parent, args, _resolution) do
|
def create_user(_parent, args, _resolution) do
|
||||||
with :registration_ok <- check_registration_config(args),
|
with :registration_ok <- check_registration_config(args),
|
||||||
{:ok, %User{} = user} <- Users.register(args) do
|
{:ok, %User{} = user} <- Users.register(args) do
|
||||||
|
@ -133,7 +115,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec check_registration_config(map()) :: atom()
|
@spec check_registration_config(map) :: atom
|
||||||
defp check_registration_config(%{email: email}) do
|
defp check_registration_config(%{email: email}) do
|
||||||
cond do
|
cond do
|
||||||
Config.instance_registrations_open?() ->
|
Config.instance_registrations_open?() ->
|
||||||
|
@ -176,6 +158,7 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
error ->
|
error ->
|
||||||
Logger.info("Unable to validate user with token #{token}")
|
Logger.info("Unable to validate user with token #{token}")
|
||||||
Logger.debug(inspect(error))
|
Logger.debug(inspect(error))
|
||||||
|
|
||||||
{:error, "Unable to validate user"}
|
{:error, "Unable to validate user"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -253,9 +236,11 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of events for all of this user's identities are going to
|
Returns the list of events for all of this user's identities are going to
|
||||||
"""
|
"""
|
||||||
def user_participations(%User{id: user_id}, args, %{
|
def user_participations(
|
||||||
context: %{current_user: %User{id: logged_user_id}}
|
%User{id: user_id},
|
||||||
}) do
|
args,
|
||||||
|
%{context: %{current_user: %User{id: logged_user_id}}}
|
||||||
|
) do
|
||||||
with true <- user_id == logged_user_id,
|
with true <- user_id == logged_user_id,
|
||||||
participations <-
|
participations <-
|
||||||
Events.list_participations_for_user(
|
Events.list_participations_for_user(
|
||||||
|
@ -272,9 +257,11 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of draft events for the current user
|
Returns the list of draft events for the current user
|
||||||
"""
|
"""
|
||||||
def user_drafted_events(%User{id: user_id}, args, %{
|
def user_drafted_events(
|
||||||
context: %{current_user: %User{id: logged_user_id}}
|
%User{id: user_id},
|
||||||
}) do
|
args,
|
||||||
|
%{context: %{current_user: %User{id: logged_user_id}}}
|
||||||
|
) do
|
||||||
with {:same_user, true} <- {:same_user, user_id == logged_user_id},
|
with {:same_user, true} <- {:same_user, user_id == logged_user_id},
|
||||||
events <-
|
events <-
|
||||||
Events.list_drafts_for_user(user_id, Map.get(args, :page), Map.get(args, :limit)) do
|
Events.list_drafts_for_user(user_id, Map.get(args, :page), Map.get(args, :limit)) do
|
||||||
|
@ -282,17 +269,17 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_password(_parent, %{old_password: old_password, new_password: new_password}, %{
|
def change_password(
|
||||||
context: %{current_user: %User{password_hash: old_password_hash} = user}
|
_parent,
|
||||||
}) do
|
%{old_password: old_password, new_password: new_password},
|
||||||
|
%{context: %{current_user: %User{password_hash: old_password_hash} = user}}
|
||||||
|
) do
|
||||||
with {:current_password, true} <-
|
with {:current_password, true} <-
|
||||||
{:current_password, Argon2.verify_pass(old_password, old_password_hash)},
|
{:current_password, Argon2.verify_pass(old_password, old_password_hash)},
|
||||||
{:same_password, false} <- {:same_password, old_password == new_password},
|
{:same_password, false} <- {:same_password, old_password == new_password},
|
||||||
{:ok, %User{} = user} <-
|
{:ok, %User{} = user} <-
|
||||||
user
|
user
|
||||||
|> User.password_change_changeset(%{
|
|> User.password_change_changeset(%{"password" => new_password})
|
||||||
"password" => new_password
|
|
||||||
})
|
|
||||||
|> Repo.update() do
|
|> Repo.update() do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema do
|
defmodule Mobilizon.GraphQL.Schema do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
GraphQL schema representation.
|
GraphQL schema representation.
|
||||||
"""
|
"""
|
||||||
|
@ -8,24 +8,25 @@ defmodule MobilizonWeb.Schema do
|
||||||
alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users}
|
alias Mobilizon.{Actors, Addresses, Events, Media, Reports, Users}
|
||||||
alias Mobilizon.Actors.{Actor, Follower, Member}
|
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||||
alias Mobilizon.Events.{Comment, Event, Participant}
|
alias Mobilizon.Events.{Comment, Event, Participant}
|
||||||
|
alias Mobilizon.GraphQL.Schema
|
||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.Custom.UUID)
|
|
||||||
import_types(MobilizonWeb.Schema.Custom.Point)
|
|
||||||
import_types(Absinthe.Type.Custom)
|
import_types(Absinthe.Type.Custom)
|
||||||
import_types(Absinthe.Plug.Types)
|
import_types(Absinthe.Plug.Types)
|
||||||
|
import_types(Schema.Custom.UUID)
|
||||||
|
import_types(Schema.Custom.Point)
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.UserType)
|
import_types(Schema.UserType)
|
||||||
import_types(MobilizonWeb.Schema.PictureType)
|
import_types(Schema.PictureType)
|
||||||
import_types(MobilizonWeb.Schema.ActorInterface)
|
import_types(Schema.ActorInterface)
|
||||||
import_types(MobilizonWeb.Schema.Actors.PersonType)
|
import_types(Schema.Actors.PersonType)
|
||||||
import_types(MobilizonWeb.Schema.Actors.GroupType)
|
import_types(Schema.Actors.GroupType)
|
||||||
import_types(MobilizonWeb.Schema.Actors.ApplicationType)
|
import_types(Schema.Actors.ApplicationType)
|
||||||
import_types(MobilizonWeb.Schema.CommentType)
|
import_types(Schema.CommentType)
|
||||||
import_types(MobilizonWeb.Schema.SearchType)
|
import_types(Schema.SearchType)
|
||||||
import_types(MobilizonWeb.Schema.ConfigType)
|
import_types(Schema.ConfigType)
|
||||||
import_types(MobilizonWeb.Schema.ReportType)
|
import_types(Schema.ReportType)
|
||||||
import_types(MobilizonWeb.Schema.AdminType)
|
import_types(Schema.AdminType)
|
||||||
|
|
||||||
@desc "A struct containing the id of the deleted object"
|
@desc "A struct containing the id of the deleted object"
|
||||||
object :deleted_object do
|
object :deleted_object do
|
|
@ -1,12 +1,14 @@
|
||||||
defmodule MobilizonWeb.Schema.ActorInterface do
|
defmodule Mobilizon.GraphQL.Schema.ActorInterface do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Actor
|
Schema representation for Actor
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
alias Mobilizon.Actors.Actor
|
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.Actors.FollowerType)
|
alias Mobilizon.Actors.Actor
|
||||||
import_types(MobilizonWeb.Schema.EventType)
|
alias Mobilizon.GraphQL.Schema
|
||||||
|
|
||||||
|
import_types(Schema.Actors.FollowerType)
|
||||||
|
import_types(Schema.EventType)
|
||||||
|
|
||||||
@desc "An ActivityPub actor"
|
@desc "An ActivityPub actor"
|
||||||
interface :actor do
|
interface :actor do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Actors.ApplicationType do
|
defmodule Mobilizon.GraphQL.Schema.Actors.ApplicationType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Group.
|
Schema representation for Group.
|
||||||
"""
|
"""
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Actors.FollowerType do
|
defmodule Mobilizon.GraphQL.Schema.Actors.FollowerType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Follower
|
Schema representation for Follower
|
||||||
"""
|
"""
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Actors.GroupType do
|
defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Group.
|
Schema representation for Group.
|
||||||
"""
|
"""
|
||||||
|
@ -8,10 +8,10 @@ defmodule MobilizonWeb.Schema.Actors.GroupType do
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.{Group, Member}
|
||||||
|
alias Mobilizon.GraphQL.Schema
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers.{Group, Member}
|
import_types(Schema.Actors.MemberType)
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.Actors.MemberType)
|
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a group of actors
|
Represents a group of actors
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.Actors.MemberType do
|
defmodule Mobilizon.GraphQL.Schema.Actors.MemberType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Member
|
Schema representation for Member
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers
|
alias Mobilizon.GraphQL.Resolvers.Group
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a member of a group
|
Represents a member of a group
|
||||||
|
@ -27,7 +27,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do
|
||||||
arg(:group_id, non_null(:id))
|
arg(:group_id, non_null(:id))
|
||||||
arg(:actor_id, non_null(:id))
|
arg(:actor_id, non_null(:id))
|
||||||
|
|
||||||
resolve(&Resolvers.Group.join_group/3)
|
resolve(&Group.join_group/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Leave an event"
|
@desc "Leave an event"
|
||||||
|
@ -35,7 +35,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do
|
||||||
arg(:group_id, non_null(:id))
|
arg(:group_id, non_null(:id))
|
||||||
arg(:actor_id, non_null(:id))
|
arg(:actor_id, non_null(:id))
|
||||||
|
|
||||||
resolve(&Resolvers.Group.leave_group/3)
|
resolve(&Group.leave_group/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,14 +1,17 @@
|
||||||
defmodule MobilizonWeb.Schema.Actors.PersonType do
|
defmodule Mobilizon.GraphQL.Schema.Actors.PersonType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Person
|
Schema representation for Person
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
||||||
alias Mobilizon.Events
|
|
||||||
alias MobilizonWeb.Resolvers.Person
|
|
||||||
import MobilizonWeb.Schema.Utils
|
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.Events.FeedTokenType)
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
import Mobilizon.GraphQL.Helpers.Error
|
||||||
|
|
||||||
|
alias Mobilizon.Events
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Person
|
||||||
|
alias Mobilizon.GraphQL.Schema
|
||||||
|
|
||||||
|
import_types(Schema.Events.FeedTokenType)
|
||||||
|
|
||||||
@desc """
|
@desc """
|
||||||
Represents a person identity
|
Represents a person identity
|
|
@ -1,9 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.AddressType do
|
defmodule Mobilizon.GraphQL.Schema.AddressType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Address
|
Schema representation for Address
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
alias MobilizonWeb.Resolvers
|
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Address
|
||||||
|
|
||||||
object :address do
|
object :address do
|
||||||
field(:geom, :point, description: "The geocoordinates for the point where this address is")
|
field(:geom, :point, description: "The geocoordinates for the point where this address is")
|
||||||
|
@ -52,7 +53,7 @@ defmodule MobilizonWeb.Schema.AddressType do
|
||||||
arg(:page, :integer, default_value: 1)
|
arg(:page, :integer, default_value: 1)
|
||||||
arg(:limit, :integer, default_value: 10)
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
|
||||||
resolve(&Resolvers.Address.search/3)
|
resolve(&Address.search/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Reverse geocode coordinates"
|
@desc "Reverse geocode coordinates"
|
||||||
|
@ -62,7 +63,7 @@ defmodule MobilizonWeb.Schema.AddressType do
|
||||||
arg(:zoom, :integer, default_value: 15)
|
arg(:zoom, :integer, default_value: 15)
|
||||||
arg(:locale, :string, default_value: "en")
|
arg(:locale, :string, default_value: "en")
|
||||||
|
|
||||||
resolve(&Resolvers.Address.reverse_geocode/3)
|
resolve(&Address.reverse_geocode/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.AdminType do
|
defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for ActionLog.
|
Schema representation for ActionLog.
|
||||||
"""
|
"""
|
||||||
|
@ -8,7 +8,7 @@ defmodule MobilizonWeb.Schema.AdminType do
|
||||||
alias Mobilizon.Events.{Event, Comment}
|
alias Mobilizon.Events.{Event, Comment}
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers.Admin
|
alias Mobilizon.GraphQL.Resolvers.Admin
|
||||||
|
|
||||||
@desc "An action log"
|
@desc "An action log"
|
||||||
object :action_log do
|
object :action_log do
|
|
@ -1,12 +1,14 @@
|
||||||
defmodule MobilizonWeb.Schema.CommentType do
|
defmodule Mobilizon.GraphQL.Schema.CommentType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Comment
|
Schema representation for Comment
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
alias MobilizonWeb.Resolvers.Comment
|
|
||||||
alias Mobilizon.{Actors, Events}
|
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
|
||||||
|
alias Mobilizon.{Actors, Events}
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Comment
|
||||||
|
|
||||||
@desc "A comment"
|
@desc "A comment"
|
||||||
object :comment do
|
object :comment do
|
||||||
interfaces([:action_log_object])
|
interfaces([:action_log_object])
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.ConfigType do
|
defmodule Mobilizon.GraphQL.Schema.ConfigType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for User
|
Schema representation for User
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers.Config
|
alias Mobilizon.GraphQL.Resolvers.Config
|
||||||
|
|
||||||
@desc "A config object"
|
@desc "A config object"
|
||||||
object :config do
|
object :config do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Custom.Point do
|
defmodule Mobilizon.GraphQL.Schema.Custom.Point do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
The geom scalar type allows Geo.PostGIS.Geometry strings to be passed in and out.
|
The geom scalar type allows Geo.PostGIS.Geometry strings to be passed in and out.
|
||||||
Requires `{:geo, "~> 3.0"},` package: https://github.com/elixir-ecto/ecto
|
Requires `{:geo, "~> 3.0"},` package: https://github.com/elixir-ecto/ecto
|
||||||
|
@ -15,7 +15,7 @@ defmodule MobilizonWeb.Schema.Custom.Point do
|
||||||
parse(&decode/1)
|
parse(&decode/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error
|
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error
|
||||||
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
|
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
|
||||||
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
|
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
|
||||||
with [_, _] = lonlat <- String.split(value, ";", trim: true),
|
with [_, _] = lonlat <- String.split(value, ";", trim: true),
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Custom.UUID do
|
defmodule Mobilizon.GraphQL.Schema.Custom.UUID do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
The UUID4 scalar type allows UUID compliant strings to be passed in and out.
|
The UUID4 scalar type allows UUID compliant strings to be passed in and out.
|
||||||
Requires `{ :ecto, ">= 0.0.0" }` package: https://github.com/elixir-ecto/ecto
|
Requires `{ :ecto, ">= 0.0.0" }` package: https://github.com/elixir-ecto/ecto
|
||||||
|
@ -18,7 +18,7 @@ defmodule MobilizonWeb.Schema.Custom.UUID do
|
||||||
parse(&decode/1)
|
parse(&decode/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term()} | :error
|
@spec decode(Absinthe.Blueprint.Input.String.t()) :: {:ok, term} | :error
|
||||||
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
|
@spec decode(Absinthe.Blueprint.Input.Null.t()) :: {:ok, nil}
|
||||||
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
|
defp decode(%Absinthe.Blueprint.Input.String{value: value}) do
|
||||||
UUID.cast(value)
|
UUID.cast(value)
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.EventType do
|
defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Event.
|
Schema representation for Event.
|
||||||
"""
|
"""
|
||||||
|
@ -6,15 +6,15 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
import MobilizonWeb.Schema.Utils
|
import Mobilizon.GraphQL.Helpers.Error
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Addresses, Events}
|
alias Mobilizon.{Actors, Addresses, Events}
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.{Event, Picture, Tag}
|
||||||
|
alias Mobilizon.GraphQL.Schema
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers.{Event, Picture, Tag}
|
import_types(Schema.AddressType)
|
||||||
|
import_types(Schema.Events.ParticipantType)
|
||||||
import_types(MobilizonWeb.Schema.AddressType)
|
import_types(Schema.TagType)
|
||||||
import_types(MobilizonWeb.Schema.Events.ParticipantType)
|
|
||||||
import_types(MobilizonWeb.Schema.TagType)
|
|
||||||
|
|
||||||
@desc "An event"
|
@desc "An event"
|
||||||
object :event do
|
object :event do
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Events.FeedTokenType do
|
defmodule Mobilizon.GraphQL.Schema.Events.FeedTokenType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Participant.
|
Schema representation for Participant.
|
||||||
"""
|
"""
|
||||||
|
@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Users}
|
alias Mobilizon.{Actors, Users}
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.FeedToken
|
||||||
alias MobilizonWeb.Resolvers
|
|
||||||
|
|
||||||
@desc "Represents a participant to an event"
|
@desc "Represents a participant to an event"
|
||||||
object :feed_token do
|
object :feed_token do
|
||||||
|
@ -41,14 +40,14 @@ defmodule MobilizonWeb.Schema.Events.FeedTokenType do
|
||||||
field :create_feed_token, :feed_token do
|
field :create_feed_token, :feed_token do
|
||||||
arg(:actor_id, :id)
|
arg(:actor_id, :id)
|
||||||
|
|
||||||
resolve(&Resolvers.FeedToken.create_feed_token/3)
|
resolve(&FeedToken.create_feed_token/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Delete a feed token"
|
@desc "Delete a feed token"
|
||||||
field :delete_feed_token, :deleted_feed_token do
|
field :delete_feed_token, :deleted_feed_token do
|
||||||
arg(:token, non_null(:string))
|
arg(:token, non_null(:string))
|
||||||
|
|
||||||
resolve(&Resolvers.FeedToken.delete_feed_token/3)
|
resolve(&FeedToken.delete_feed_token/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Participant.
|
Schema representation for Participant.
|
||||||
"""
|
"""
|
||||||
|
@ -8,8 +8,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Events}
|
alias Mobilizon.{Actors, Events}
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Event
|
||||||
alias MobilizonWeb.Resolvers
|
|
||||||
|
|
||||||
@desc "Represents a participant to an event"
|
@desc "Represents a participant to an event"
|
||||||
object :participant do
|
object :participant do
|
||||||
|
@ -54,7 +53,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||||
arg(:event_id, non_null(:id))
|
arg(:event_id, non_null(:id))
|
||||||
arg(:actor_id, non_null(:id))
|
arg(:actor_id, non_null(:id))
|
||||||
|
|
||||||
resolve(&Resolvers.Event.actor_join_event/3)
|
resolve(&Event.actor_join_event/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Leave an event"
|
@desc "Leave an event"
|
||||||
|
@ -62,7 +61,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||||
arg(:event_id, non_null(:id))
|
arg(:event_id, non_null(:id))
|
||||||
arg(:actor_id, non_null(:id))
|
arg(:actor_id, non_null(:id))
|
||||||
|
|
||||||
resolve(&Resolvers.Event.actor_leave_event/3)
|
resolve(&Event.actor_leave_event/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Accept a participation"
|
@desc "Accept a participation"
|
||||||
|
@ -71,7 +70,7 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||||
arg(:role, non_null(:participant_role_enum))
|
arg(:role, non_null(:participant_role_enum))
|
||||||
arg(:moderator_actor_id, non_null(:id))
|
arg(:moderator_actor_id, non_null(:id))
|
||||||
|
|
||||||
resolve(&Resolvers.Event.update_participation/3)
|
resolve(&Event.update_participation/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,9 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.PictureType do
|
defmodule Mobilizon.GraphQL.Schema.PictureType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Pictures
|
Schema representation for Pictures
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
alias MobilizonWeb.Resolvers.Picture
|
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Picture
|
||||||
|
|
||||||
@desc "A picture"
|
@desc "A picture"
|
||||||
object :picture do
|
object :picture do
|
|
@ -1,12 +1,13 @@
|
||||||
defmodule MobilizonWeb.Schema.ReportType do
|
defmodule Mobilizon.GraphQL.Schema.ReportType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for User
|
Schema representation for User
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
||||||
alias Mobilizon.Reports
|
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers.Report
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
|
||||||
|
alias Mobilizon.Reports
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Report
|
||||||
|
|
||||||
@desc "A report object"
|
@desc "A report object"
|
||||||
object :report do
|
object :report do
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.SearchType do
|
defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Search
|
Schema representation for Search
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
|
|
||||||
alias MobilizonWeb.Resolvers
|
alias Mobilizon.GraphQL.Resolvers.Search
|
||||||
|
|
||||||
@desc "Search persons result"
|
@desc "Search persons result"
|
||||||
object :persons do
|
object :persons do
|
||||||
|
@ -31,7 +31,7 @@ defmodule MobilizonWeb.Schema.SearchType do
|
||||||
arg(:page, :integer, default_value: 1)
|
arg(:page, :integer, default_value: 1)
|
||||||
arg(:limit, :integer, default_value: 10)
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
|
||||||
resolve(&Resolvers.Search.search_persons/3)
|
resolve(&Search.search_persons/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Search groups"
|
@desc "Search groups"
|
||||||
|
@ -40,7 +40,7 @@ defmodule MobilizonWeb.Schema.SearchType do
|
||||||
arg(:page, :integer, default_value: 1)
|
arg(:page, :integer, default_value: 1)
|
||||||
arg(:limit, :integer, default_value: 10)
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
|
||||||
resolve(&Resolvers.Search.search_groups/3)
|
resolve(&Search.search_groups/3)
|
||||||
end
|
end
|
||||||
|
|
||||||
@desc "Search events"
|
@desc "Search events"
|
||||||
|
@ -49,7 +49,7 @@ defmodule MobilizonWeb.Schema.SearchType do
|
||||||
arg(:page, :integer, default_value: 1)
|
arg(:page, :integer, default_value: 1)
|
||||||
arg(:limit, :integer, default_value: 10)
|
arg(:limit, :integer, default_value: 10)
|
||||||
|
|
||||||
resolve(&Resolvers.Search.search_events/3)
|
resolve(&Search.search_events/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Schema.SortType do
|
defmodule Mobilizon.GraphQL.Schema.SortType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Allows sorting a collection of elements
|
Allows sorting a collection of elements
|
||||||
"""
|
"""
|
|
@ -1,9 +1,10 @@
|
||||||
defmodule MobilizonWeb.Schema.TagType do
|
defmodule Mobilizon.GraphQL.Schema.TagType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for Tags
|
Schema representation for Tags
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
alias MobilizonWeb.Resolvers
|
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.Tag
|
||||||
|
|
||||||
@desc "A tag"
|
@desc "A tag"
|
||||||
object :tag do
|
object :tag do
|
||||||
|
@ -14,7 +15,7 @@ defmodule MobilizonWeb.Schema.TagType do
|
||||||
field(
|
field(
|
||||||
:related,
|
:related,
|
||||||
list_of(:tag),
|
list_of(:tag),
|
||||||
resolve: &Resolvers.Tag.get_related_tags/3,
|
resolve: &Tag.get_related_tags/3,
|
||||||
description: "Related tags to this tag"
|
description: "Related tags to this tag"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -24,7 +25,7 @@ defmodule MobilizonWeb.Schema.TagType do
|
||||||
field :tags, non_null(list_of(:tag)) do
|
field :tags, non_null(list_of(:tag)) do
|
||||||
arg(:page, :integer, default_value: 1)
|
arg(:page, :integer, default_value: 1)
|
||||||
arg(:limit, :integer, default_value: 10)
|
arg(:limit, :integer, default_value: 10)
|
||||||
resolve(&Resolvers.Tag.list_tags/3)
|
resolve(&Tag.list_tags/3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,14 +1,17 @@
|
||||||
defmodule MobilizonWeb.Schema.UserType do
|
defmodule Mobilizon.GraphQL.Schema.UserType do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Schema representation for User
|
Schema representation for User
|
||||||
"""
|
"""
|
||||||
use Absinthe.Schema.Notation
|
use Absinthe.Schema.Notation
|
||||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
|
||||||
alias Mobilizon.Events
|
|
||||||
alias MobilizonWeb.Resolvers.User
|
|
||||||
import MobilizonWeb.Schema.Utils
|
|
||||||
|
|
||||||
import_types(MobilizonWeb.Schema.SortType)
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||||
|
import Mobilizon.GraphQL.Helpers.Error
|
||||||
|
|
||||||
|
alias Mobilizon.Events
|
||||||
|
alias Mobilizon.GraphQL.Resolvers.User
|
||||||
|
alias Mobilizon.GraphQL.Schema
|
||||||
|
|
||||||
|
import_types(Schema.SortType)
|
||||||
|
|
||||||
@desc "A local user of Mobilizon"
|
@desc "A local user of Mobilizon"
|
||||||
object :user do
|
object :user do
|
|
@ -53,7 +53,9 @@ defmodule MobilizonWeb.API.Events do
|
||||||
defp process_picture(%{picture: picture}, %Actor{id: actor_id}) do
|
defp process_picture(%{picture: picture}, %Actor{id: actor_id}) do
|
||||||
%{
|
%{
|
||||||
file:
|
file:
|
||||||
picture |> Map.get(:file) |> Utils.make_picture_data(description: Map.get(picture, :name)),
|
picture
|
||||||
|
|> Map.get(:file)
|
||||||
|
|> Utils.make_picture_data(description: Map.get(picture, :name)),
|
||||||
actor_id: actor_id
|
actor_id: actor_id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,7 +52,7 @@ defmodule MobilizonWeb.Router do
|
||||||
pipe_through(:graphql)
|
pipe_through(:graphql)
|
||||||
|
|
||||||
forward("/", Absinthe.Plug,
|
forward("/", Absinthe.Plug,
|
||||||
schema: MobilizonWeb.Schema,
|
schema: Mobilizon.GraphQL.Schema,
|
||||||
analyze_complexity: true,
|
analyze_complexity: true,
|
||||||
max_complexity: 200
|
max_complexity: 200
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.AddressResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.AddressTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
describe "Address Resolver" do
|
describe "Address Resolver" do
|
||||||
test "search/3 search for addresses", %{conn: conn} do
|
test "search/3 search for addresses", %{conn: conn} do
|
||||||
address = insert(:address, description: "10 rue Jangot, Lyon")
|
address = insert(:address, description: "10 rue Jangot, Lyon")
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
@ -10,7 +10,7 @@ defmodule MobilizonWeb.Resolvers.AdminResolverTest do
|
||||||
|
|
||||||
alias Mobilizon.Federation.ActivityPub.Relay
|
alias Mobilizon.Federation.ActivityPub.Relay
|
||||||
|
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
alias MobilizonWeb.API
|
alias MobilizonWeb.API
|
||||||
|
|
||||||
describe "Resolver: List the action logs" do
|
describe "Resolver: List the action logs" do
|
|
@ -1,8 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.CommentResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
@comment %{text: "I love this event"}
|
@comment %{text: "I love this event"}
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
|
@ -1,8 +1,9 @@
|
||||||
defmodule MobilizonWeb.Resolvers.ConfigResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
use Bamboo.Test
|
use Bamboo.Test
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
describe "Resolver: Get config" do
|
describe "Resolver: Get config" do
|
||||||
test "get_config/3 returns the instance config", context do
|
test "get_config/3 returns the instance config", context do
|
||||||
query = """
|
query = """
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
defmodule MobilizonWeb.Resolvers.EventTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
use Bamboo.Test
|
use Bamboo.Test
|
||||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||||
|
@ -8,7 +8,9 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Service.Workers
|
alias Mobilizon.Service.Workers
|
||||||
|
|
||||||
alias MobilizonWeb.{AbsintheHelpers, Email}
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
|
alias MobilizonWeb.Email
|
||||||
|
|
||||||
@event %{
|
@event %{
|
||||||
description: "some body",
|
description: "some body",
|
|
@ -1,8 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.FeedTokenResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.FeedTokenTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
actor = insert(:actor, user: user, preferred_username: "test")
|
actor = insert(:actor, user: user, preferred_username: "test")
|
|
@ -1,8 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
defmodule MobilizonWeb.Resolvers.GroupTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
@non_existent_username "nonexistent"
|
@non_existent_username "nonexistent"
|
||||||
@new_group_params %{groupname: "new group"}
|
@new_group_params %{groupname: "new group"}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.MemberResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.MemberTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
|
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
actor = insert(:actor, user: user, preferred_username: "test")
|
actor = insert(:actor, user: user, preferred_username: "test")
|
|
@ -1,10 +1,14 @@
|
||||||
defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
use Bamboo.Test
|
use Bamboo.Test
|
||||||
alias Mobilizon.Events
|
|
||||||
alias MobilizonWeb.{AbsintheHelpers, Email}
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.Events
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
|
alias MobilizonWeb.Email
|
||||||
|
|
||||||
@event %{
|
@event %{
|
||||||
description: "some body",
|
description: "some body",
|
||||||
title: "some title",
|
title: "some title",
|
|
@ -1,13 +1,13 @@
|
||||||
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
|
||||||
use MobilizonWeb.ConnCase
|
|
||||||
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
use Oban.Testing, repo: Mobilizon.Storage.Repo
|
||||||
|
use MobilizonWeb.ConnCase
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Service.Workers
|
alias Mobilizon.Service.Workers
|
||||||
|
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
@non_existent_username "nonexistent"
|
@non_existent_username "nonexistent"
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
defmodule MobilizonWeb.Resolvers.PictureResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
use Bamboo.Test
|
use Bamboo.Test
|
||||||
alias Mobilizon.Media.Picture
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.Media.Picture
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
actor = insert(:actor, user: user)
|
actor = insert(:actor, user: user)
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule MobilizonWeb.Resolvers.ReportResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
@ -8,7 +8,7 @@ defmodule MobilizonWeb.Resolvers.ReportResolverTest do
|
||||||
alias Mobilizon.Reports.{Note, Report}
|
alias Mobilizon.Reports.{Note, Report}
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
describe "Resolver: Report a content" do
|
describe "Resolver: Report a content" do
|
||||||
test "create_report/3 creates a report", %{conn: conn} do
|
test "create_report/3 creates a report", %{conn: conn} do
|
|
@ -1,10 +1,11 @@
|
||||||
defmodule MobilizonWeb.Resolvers.SearchResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.SearchTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
alias Mobilizon.Service.Workers
|
alias Mobilizon.Service.Workers
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
setup %{conn: conn} do
|
setup %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
|
@ -1,8 +1,10 @@
|
||||||
defmodule MobilizonWeb.Resolvers.TagResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.TagTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
alias MobilizonWeb.AbsintheHelpers
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
describe "Tag Resolver" do
|
describe "Tag Resolver" do
|
||||||
test "list_tags/3 returns the list of tags", context do
|
test "list_tags/3 returns the list of tags", context do
|
||||||
tag1 = insert(:tag)
|
tag1 = insert(:tag)
|
|
@ -1,15 +1,16 @@
|
||||||
defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
defmodule Mobilizon.GraphQL.Resolvers.UserTest do
|
||||||
use MobilizonWeb.ConnCase
|
use MobilizonWeb.ConnCase
|
||||||
|
use Bamboo.Test
|
||||||
|
|
||||||
import Mobilizon.Factory
|
import Mobilizon.Factory
|
||||||
|
|
||||||
use Bamboo.Test
|
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Config, Users}
|
alias Mobilizon.{Actors, Config, Users}
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
alias MobilizonWeb.{AbsintheHelpers, Email}
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||||
|
|
||||||
|
alias MobilizonWeb.Email
|
||||||
|
|
||||||
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
||||||
@valid_single_actor_params %{preferred_username: "test2", keys: "yolo"}
|
@valid_single_actor_params %{preferred_username: "test2", keys: "yolo"}
|
|
@ -1,10 +1,12 @@
|
||||||
defmodule MobilizonWeb.AbsintheHelpers do
|
defmodule Mobilizon.GraphQL.AbsintheHelpers do
|
||||||
use Phoenix.ConnTest
|
|
||||||
@endpoint MobilizonWeb.Endpoint
|
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Absinthe helpers for tests
|
Absinthe helpers for tests
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
use Phoenix.ConnTest
|
||||||
|
|
||||||
|
@endpoint MobilizonWeb.Endpoint
|
||||||
|
|
||||||
def query_skeleton(query, query_name) do
|
def query_skeleton(query, query_name) do
|
||||||
%{
|
%{
|
||||||
"operationName" => "#{query_name}",
|
"operationName" => "#{query_name}",
|
||||||
|
@ -23,10 +25,7 @@ defmodule MobilizonWeb.AbsintheHelpers do
|
||||||
|
|
||||||
def graphql_query(conn, options) do
|
def graphql_query(conn, options) do
|
||||||
conn
|
conn
|
||||||
|> post(
|
|> post("/api", build_query(options[:query], Keyword.get(options, :variables, %{})))
|
||||||
"/api",
|
|
||||||
build_query(options[:query], Keyword.get(options, :variables, %{}))
|
|
||||||
)
|
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue