forked from potsda.mn/mobilizon
Move API under GraphQL context
This commit is contained in:
parent
ba3ad713c0
commit
b3f8d52bc9
|
@ -30,7 +30,8 @@ defmodule Mobilizon.Federation.ActivityPub do
|
|||
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||
alias Mobilizon.Federation.WebFinger
|
||||
|
||||
alias MobilizonWeb.API.Utils, as: APIUtils
|
||||
alias Mobilizon.GraphQL.API.Utils, as: APIUtils
|
||||
|
||||
alias MobilizonWeb.Email.{Admin, Mailer}
|
||||
|
||||
require Logger
|
||||
|
|
|
@ -15,7 +15,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
|
|||
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier}
|
||||
alias Mobilizon.Federation.WebFinger
|
||||
|
||||
alias MobilizonWeb.API.Follows
|
||||
alias Mobilizon.GraphQL.API.Follows
|
||||
|
||||
require Logger
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
defmodule MobilizonWeb.API.Comments do
|
||||
defmodule Mobilizon.GraphQL.API.Comments do
|
||||
@moduledoc """
|
||||
API for Comments.
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events.Comment
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
|
@ -12,8 +13,7 @@ defmodule MobilizonWeb.API.Comments do
|
|||
|
||||
Creates a comment from an actor
|
||||
"""
|
||||
@spec create_comment(map()) ::
|
||||
{:ok, Activity.t(), Comment.t()} | any()
|
||||
@spec create_comment(map) :: {:ok, Activity.t(), Comment.t()} | any
|
||||
def create_comment(args) do
|
||||
ActivityPub.create(:comment, args, true)
|
||||
end
|
||||
|
@ -23,8 +23,7 @@ defmodule MobilizonWeb.API.Comments do
|
|||
|
||||
Deletes a comment from an actor
|
||||
"""
|
||||
@spec delete_comment(Comment.t()) ::
|
||||
{:ok, Activity.t(), Comment.t()} | any()
|
||||
@spec delete_comment(Comment.t()) :: {:ok, Activity.t(), Comment.t()} | any
|
||||
def delete_comment(%Comment{} = comment) do
|
||||
ActivityPub.delete(comment, true)
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Events do
|
||||
defmodule Mobilizon.GraphQL.API.Events do
|
||||
@moduledoc """
|
||||
API for Events.
|
||||
"""
|
||||
|
@ -12,7 +12,7 @@ defmodule MobilizonWeb.API.Events do
|
|||
@doc """
|
||||
Create an event
|
||||
"""
|
||||
@spec create_event(map()) :: {:ok, Activity.t(), Event.t()} | any()
|
||||
@spec create_event(map) :: {:ok, Activity.t(), Event.t()} | any
|
||||
def create_event(args) do
|
||||
with organizer_actor <- Map.get(args, :organizer_actor),
|
||||
args <-
|
||||
|
@ -27,7 +27,7 @@ defmodule MobilizonWeb.API.Events do
|
|||
@doc """
|
||||
Update an event
|
||||
"""
|
||||
@spec update_event(map(), Event.t()) :: {:ok, Activity.t(), Event.t()} | any()
|
||||
@spec update_event(map, Event.t()) :: {:ok, Activity.t(), Event.t()} | any
|
||||
def update_event(args, %Event{} = event) do
|
||||
with organizer_actor <- Map.get(args, :organizer_actor),
|
||||
args <-
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Follows do
|
||||
defmodule Mobilizon.GraphQL.API.Follows do
|
||||
@moduledoc """
|
||||
Common API for following, unfollowing, accepting and rejecting stuff.
|
||||
"""
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Groups do
|
||||
defmodule Mobilizon.GraphQL.API.Groups do
|
||||
@moduledoc """
|
||||
API for Groups.
|
||||
"""
|
||||
|
@ -12,7 +12,7 @@ defmodule MobilizonWeb.API.Groups do
|
|||
@doc """
|
||||
Create a group
|
||||
"""
|
||||
@spec create_group(map()) :: {:ok, Activity.t(), Actor.t()} | any()
|
||||
@spec create_group(map) :: {:ok, Activity.t(), Actor.t()} | any
|
||||
def create_group(args) do
|
||||
with preferred_username <-
|
||||
args |> Map.get(:preferred_username) |> HtmlSanitizeEx.strip_tags() |> String.trim(),
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Participations do
|
||||
defmodule Mobilizon.GraphQL.API.Participations do
|
||||
@moduledoc """
|
||||
Common API to join events and groups.
|
||||
"""
|
||||
|
@ -27,11 +27,13 @@ defmodule MobilizonWeb.API.Participations do
|
|||
@doc """
|
||||
Update participation status
|
||||
"""
|
||||
def update(%Participant{} = participation, %Actor{} = moderator, :participant),
|
||||
do: accept(participation, moderator)
|
||||
def update(%Participant{} = participation, %Actor{} = moderator, :participant) do
|
||||
accept(participation, moderator)
|
||||
end
|
||||
|
||||
def update(%Participant{} = participation, %Actor{} = moderator, :rejected),
|
||||
do: reject(participation, moderator)
|
||||
def update(%Participant{} = participation, %Actor{} = moderator, :rejected) do
|
||||
reject(participation, moderator)
|
||||
end
|
||||
|
||||
defp accept(
|
||||
%Participant{} = participation,
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Reports do
|
||||
defmodule Mobilizon.GraphQL.API.Reports do
|
||||
@moduledoc """
|
||||
API for Reports.
|
||||
"""
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Search do
|
||||
defmodule Mobilizon.GraphQL.API.Search do
|
||||
@moduledoc """
|
||||
API for search.
|
||||
"""
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.Utils do
|
||||
defmodule Mobilizon.GraphQL.API.Utils do
|
||||
@moduledoc """
|
||||
Utils for API.
|
||||
"""
|
||||
|
@ -10,11 +10,7 @@ defmodule MobilizonWeb.API.Utils do
|
|||
Creates HTML content from text and mentions
|
||||
"""
|
||||
@spec make_content_html(String.t(), list(), String.t()) :: String.t()
|
||||
def make_content_html(
|
||||
text,
|
||||
additional_tags,
|
||||
content_type
|
||||
) do
|
||||
def make_content_html(text, additional_tags, content_type) do
|
||||
with {text, mentions, tags} <- format_input(text, content_type, []) do
|
||||
{text, mentions, additional_tags ++ Enum.map(tags, fn {_, tag} -> tag end)}
|
||||
end
|
||||
|
@ -24,9 +20,7 @@ defmodule MobilizonWeb.API.Utils do
|
|||
text
|
||||
|> Formatter.html_escape("text/plain")
|
||||
|> Formatter.linkify(options)
|
||||
|> (fn {text, mentions, tags} ->
|
||||
{String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags}
|
||||
end).()
|
||||
|> (fn {text, mentions, tags} -> {String.replace(text, ~r/\r?\n/, "<br>"), mentions, tags} end).()
|
||||
end
|
||||
|
||||
def format_input(text, "text/html", options) do
|
|
@ -9,7 +9,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Comment do
|
|||
alias Mobilizon.Events.Comment, as: CommentModel
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Comments
|
||||
alias Mobilizon.GraphQL.API.Comments
|
||||
|
||||
require Logger
|
||||
|
||||
|
|
|
@ -8,12 +8,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
alias Mobilizon.Events.{Event, Participant, EventParticipantStats}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.GraphQL.API
|
||||
alias Mobilizon.GraphQL.Resolvers.Person
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Activity
|
||||
|
||||
alias MobilizonWeb.API
|
||||
|
||||
# We limit the max number of events that can be retrieved
|
||||
@event_max_limit 100
|
||||
@number_of_related_events 3
|
||||
|
@ -231,7 +230,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
{:actor_approve_permission,
|
||||
Mobilizon.Events.moderator_for_event?(participation.event.id, moderator_actor_id)},
|
||||
{:ok, _activity, participation} <-
|
||||
MobilizonWeb.API.Participations.update(participation, moderator_actor, new_role) do
|
||||
API.Participations.update(participation, moderator_actor, new_role) do
|
||||
{:ok, participation}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
|
@ -268,7 +267,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
{:is_owned, %Actor{} = organizer_actor} <- User.owns_actor(user, organizer_actor_id),
|
||||
args_with_organizer <- Map.put(args, :organizer_actor, organizer_actor),
|
||||
{:ok, %Activity{data: %{"object" => %{"type" => "Event"}}}, %Event{} = event} <-
|
||||
MobilizonWeb.API.Events.create_event(args_with_organizer) do
|
||||
API.Events.create_event(args_with_organizer) do
|
||||
{:ok, event}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
|
@ -302,7 +301,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
User.owns_actor(user, organizer_actor_id),
|
||||
args <- Map.put(args, :organizer_actor, organizer_actor),
|
||||
{:ok, %Activity{data: %{"object" => %{"type" => "Event"}}}, %Event{} = event} <-
|
||||
MobilizonWeb.API.Events.update_event(args, event) do
|
||||
API.Events.update_event(args, event) do
|
||||
{:ok, event}
|
||||
else
|
||||
{:error, :event_not_found} ->
|
||||
|
@ -360,7 +359,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
end
|
||||
|
||||
defp do_delete_event(event, federate \\ true) when is_boolean(federate) do
|
||||
with {:ok, _activity, event} <- MobilizonWeb.API.Events.delete_event(event) do
|
||||
with {:ok, _activity, event} <- API.Events.delete_event(event) do
|
||||
{:ok, %{id: event.id}}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,12 +7,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||
alias Mobilizon.Actors.{Actor, Member}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.GraphQL.API
|
||||
alias Mobilizon.GraphQL.Resolvers.Person
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
|
||||
alias MobilizonWeb.API
|
||||
|
||||
require Logger
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Member do
|
|||
@moduledoc """
|
||||
Handles the member-related GraphQL calls
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Picture do
|
|||
@moduledoc """
|
||||
Handles the picture-related GraphQL calls
|
||||
"""
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Media
|
||||
alias Mobilizon.Media.Picture
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
|||
alias Mobilizon.Reports.{Note, Report}
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias MobilizonWeb.API.Reports, as: ReportsAPI
|
||||
alias Mobilizon.GraphQL.API
|
||||
|
||||
def list_reports(
|
||||
_parent,
|
||||
|
@ -50,7 +50,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
|||
%{context: %{current_user: user}} = _resolution
|
||||
) do
|
||||
with {:is_owned, %Actor{}} <- User.owns_actor(user, reporter_id),
|
||||
{:ok, _, %Report{} = report} <- ReportsAPI.report(args) do
|
||||
{:ok, _, %Report{} = report} <- API.Reports.report(args) do
|
||||
{:ok, report}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
|
@ -76,8 +76,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
|||
when is_moderator(role) do
|
||||
with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, moderator_id),
|
||||
%Report{} = report <- Mobilizon.Reports.get_report(report_id),
|
||||
{:ok, %Report{} = report} <-
|
||||
MobilizonWeb.API.Reports.update_report_status(actor, report, status) do
|
||||
{:ok, %Report{} = report} <- API.Reports.update_report_status(actor, report, status) do
|
||||
{:ok, report}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
|
@ -101,8 +100,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
|||
with {:is_owned, %Actor{}} <- User.owns_actor(user, moderator_id),
|
||||
%Report{} = report <- Reports.get_report(report_id),
|
||||
%Actor{} = moderator <- Actors.get_local_actor_with_preload(moderator_id),
|
||||
{:ok, %Note{} = note} <-
|
||||
MobilizonWeb.API.Reports.create_report_note(report, moderator, content) do
|
||||
{:ok, %Note{} = note} <- API.Reports.create_report_note(report, moderator, content) do
|
||||
{:ok, note}
|
||||
end
|
||||
end
|
||||
|
@ -116,8 +114,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Report do
|
|||
with {:is_owned, %Actor{}} <- User.owns_actor(user, moderator_id),
|
||||
%Note{} = note <- Reports.get_note(note_id),
|
||||
%Actor{} = moderator <- Actors.get_local_actor_with_preload(moderator_id),
|
||||
{:ok, %Note{} = note} <-
|
||||
MobilizonWeb.API.Reports.delete_report_note(note, moderator) do
|
||||
{:ok, %Note{} = note} <- API.Reports.delete_report_note(note, moderator) do
|
||||
{:ok, %{id: note.id}}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
|
|||
@moduledoc """
|
||||
Handles the event-related GraphQL calls
|
||||
"""
|
||||
alias MobilizonWeb.API.Search
|
||||
|
||||
alias Mobilizon.GraphQL.API.Search
|
||||
|
||||
@doc """
|
||||
Search persons
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Tag do
|
|||
@moduledoc """
|
||||
Handles the tag-related GraphQL calls
|
||||
"""
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Tag}
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@ defmodule Mix.Tasks.Mobilizon.MoveParticipantStats do
|
|||
|
||||
use Mix.Task
|
||||
|
||||
alias Mobilizon.Storage.Repo
|
||||
import Ecto.Query
|
||||
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Events.ParticipantRole
|
||||
import Ecto.Query
|
||||
alias Mobilizon.Storage.Repo
|
||||
|
||||
require Logger
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ defmodule Mix.Tasks.Mobilizon.Relay do
|
|||
use Mix.Task
|
||||
|
||||
alias Mix.Tasks.Mobilizon.Common
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
|
||||
@shortdoc "Manages remote relays"
|
||||
|
|
|
@ -5,10 +5,11 @@ defmodule Mix.Tasks.Mobilizon.Toot do
|
|||
|
||||
use Mix.Task
|
||||
|
||||
alias MobilizonWeb.API.Comments
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
alias Mobilizon.GraphQL.API.Comments
|
||||
|
||||
require Logger
|
||||
|
||||
@shortdoc "Toot to an user"
|
||||
|
|
|
@ -20,7 +20,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
|
|||
alias Mobilizon.Federation.ActivityPub.{Activity, Relay, Transmogrifier}
|
||||
alias Mobilizon.Federation.ActivityStream.{Convertible}
|
||||
|
||||
alias MobilizonWeb.API
|
||||
alias Mobilizon.GraphQL.API
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.ReportTest do
|
||||
defmodule Mobilizon.GraphQL.API.ReportTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
import Mobilizon.Factory
|
||||
|
@ -9,9 +9,9 @@ defmodule MobilizonWeb.API.ReportTest do
|
|||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.{Activity, Relay}
|
||||
alias Mobilizon.GraphQL.API.Reports
|
||||
|
||||
alias MobilizonWeb.API.Reports
|
||||
alias Mobilizon.Federation.ActivityPub.{Activity, Relay}
|
||||
|
||||
describe "reports" do
|
||||
test "creates a report on a event" do
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MobilizonWeb.API.SearchTest do
|
||||
defmodule Mobilizon.GraphQL.API.SearchTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
import Mock
|
||||
|
@ -9,9 +9,9 @@ defmodule MobilizonWeb.API.SearchTest do
|
|||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.GraphQL.API.Search
|
||||
|
||||
alias MobilizonWeb.API.Search
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
|
||||
test "search an user by username" do
|
||||
with_mock ActivityPub,
|
|
@ -10,8 +10,8 @@ defmodule Mobilizon.GraphQL.Resolvers.AdminTest do
|
|||
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
|
||||
alias Mobilizon.GraphQL.API
|
||||
alias Mobilizon.GraphQL.AbsintheHelpers
|
||||
alias MobilizonWeb.API
|
||||
|
||||
describe "Resolver: List the action logs" do
|
||||
@note_content "This a note on a report"
|
||||
|
|
Loading…
Reference in a new issue