Fix credo style reports following it's update
Mainly transform `with` into `case` Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -25,9 +25,10 @@ defmodule MobilizonWeb.API.Search do
|
||||
# Some URLs could be domain.tld/@username, so keep this condition above handle_search? function
|
||||
url_search?(search) ->
|
||||
# If this is not an actor, skip
|
||||
with %{:total => total, :elements => [%Actor{}] = elements} <- process_from_url(search) do
|
||||
{:ok, %{total: total, elements: elements}}
|
||||
else
|
||||
case process_from_url(search) do
|
||||
%{:total => total, :elements => [%Actor{}] = elements} ->
|
||||
{:ok, %{total: total, elements: elements}}
|
||||
|
||||
_ ->
|
||||
{:ok, %{total: 0, elements: []}}
|
||||
end
|
||||
@@ -55,9 +56,10 @@ defmodule MobilizonWeb.API.Search do
|
||||
|
||||
url_search?(search) ->
|
||||
# If this is not an event, skip
|
||||
with {total = total, [%Event{} = elements]} <- process_from_url(search) do
|
||||
{:ok, %{total: total, elements: elements}}
|
||||
else
|
||||
case process_from_url(search) do
|
||||
{total = total, [%Event{} = elements]} ->
|
||||
{:ok, %{total: total, elements: elements}}
|
||||
|
||||
_ ->
|
||||
{:ok, %{total: 0, elements: []}}
|
||||
end
|
||||
@@ -70,9 +72,10 @@ defmodule MobilizonWeb.API.Search do
|
||||
# If the search string is an username
|
||||
@spec process_from_username(String.t()) :: %{total: integer(), elements: [Actor.t()]}
|
||||
defp process_from_username(search) do
|
||||
with {:ok, actor} <- ActivityPub.find_or_make_actor_from_nickname(search) do
|
||||
%{total: 1, elements: [actor]}
|
||||
else
|
||||
case ActivityPub.find_or_make_actor_from_nickname(search) do
|
||||
{:ok, actor} ->
|
||||
%{total: 1, elements: [actor]}
|
||||
|
||||
{:error, _err} ->
|
||||
Logger.debug(fn -> "Unable to find or make actor '#{search}'" end)
|
||||
%{total: 0, elements: []}
|
||||
@@ -85,9 +88,10 @@ defmodule MobilizonWeb.API.Search do
|
||||
elements: [Actor.t() | Event.t() | Comment.t()]
|
||||
}
|
||||
defp process_from_url(search) do
|
||||
with {:ok, object} <- ActivityPub.fetch_object_from_url(search) do
|
||||
%{total: 1, elements: [object]}
|
||||
else
|
||||
case ActivityPub.fetch_object_from_url(search) do
|
||||
{:ok, object} ->
|
||||
%{total: 1, elements: [object]}
|
||||
|
||||
{:error, _err} ->
|
||||
Logger.debug(fn -> "Unable to find or make object from URL '#{search}'" end)
|
||||
%{total: 0, elements: []}
|
||||
|
||||
@@ -15,7 +15,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
action_fallback(:errors)
|
||||
|
||||
def following(conn, %{"name" => name, "page" => page}) do
|
||||
with {page, ""} = Integer.parse(page),
|
||||
with {page, ""} <- Integer.parse(page),
|
||||
%Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
@@ -32,7 +32,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
end
|
||||
|
||||
def followers(conn, %{"name" => name, "page" => page}) do
|
||||
with {page, ""} = Integer.parse(page),
|
||||
with {page, ""} <- Integer.parse(page),
|
||||
%Actor{} = actor <- Actors.get_local_actor_by_name_with_everything(name) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
@@ -49,7 +49,7 @@ defmodule MobilizonWeb.ActivityPubController do
|
||||
end
|
||||
|
||||
def outbox(conn, %{"name" => name, "page" => page}) do
|
||||
with {page, ""} = Integer.parse(page),
|
||||
with {page, ""} <- Integer.parse(page),
|
||||
%Actor{} = actor <- Actors.get_local_actor_by_name(name) do
|
||||
conn
|
||||
|> put_resp_header("content-type", "application/activity+json")
|
||||
|
||||
@@ -7,60 +7,60 @@ defmodule MobilizonWeb.FeedController do
|
||||
action_fallback(MobilizonWeb.FallbackController)
|
||||
|
||||
def actor(conn, %{"name" => name, "format" => "atom"}) do
|
||||
with {status, data} when status in [:ok, :commit] <-
|
||||
Cachex.fetch(:feed, "actor_" <> name) do
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
else
|
||||
case Cachex.fetch(:feed, "actor_" <> name) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def actor(conn, %{"name" => name, "format" => "ics"}) do
|
||||
with {status, data} when status in [:ok, :commit] <-
|
||||
Cachex.fetch(:ics, "actor_" <> name) do
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
else
|
||||
case Cachex.fetch(:ics, "actor_" <> name) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def event(conn, %{"uuid" => uuid, "format" => "ics"}) do
|
||||
with {status, data} when status in [:ok, :commit] <-
|
||||
Cachex.fetch(:ics, "event_" <> uuid) do
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
else
|
||||
case Cachex.fetch(:ics, "event_" <> uuid) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def going(conn, %{"token" => token, "format" => "ics"}) do
|
||||
with {status, data} when status in [:ok, :commit] <-
|
||||
Cachex.fetch(:ics, "token_" <> token) do
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
else
|
||||
case Cachex.fetch(:ics, "token_" <> token) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
conn
|
||||
|> put_resp_content_type("text/calendar")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
end
|
||||
|
||||
def going(conn, %{"token" => token, "format" => "atom"}) do
|
||||
with {status, data} when status in [:ok, :commit] <-
|
||||
Cachex.fetch(:feed, "token_" <> token) do
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
else
|
||||
case Cachex.fetch(:feed, "token_" <> token) do
|
||||
{status, data} when status in [:ok, :commit] ->
|
||||
conn
|
||||
|> put_resp_content_type("application/atom+xml")
|
||||
|> send_resp(200, data)
|
||||
|
||||
_err ->
|
||||
{:error, :not_found}
|
||||
end
|
||||
|
||||
@@ -176,11 +176,12 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
# and that it's the actor requesting leaving the event we return true
|
||||
@spec check_that_participant_is_not_only_organizer(integer(), integer()) :: boolean()
|
||||
defp check_that_participant_is_not_only_organizer(event_id, actor_id) do
|
||||
with [%Participant{actor: %Actor{id: participant_actor_id}}] <-
|
||||
Mobilizon.Events.list_organizers_participants_for_event(event_id) do
|
||||
participant_actor_id == actor_id
|
||||
else
|
||||
_ -> false
|
||||
case Mobilizon.Events.list_organizers_participants_for_event(event_id) do
|
||||
[%Participant{actor: %Actor{id: participant_actor_id}}] ->
|
||||
participant_actor_id == actor_id
|
||||
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -218,17 +218,18 @@ defmodule MobilizonWeb.Resolvers.Group do
|
||||
# and that it's the actor requesting leaving the group we return true
|
||||
@spec check_that_member_is_not_only_administrator(integer(), integer()) :: boolean()
|
||||
defp check_that_member_is_not_only_administrator(group_id, actor_id) do
|
||||
with [
|
||||
%Member{
|
||||
actor: %Actor{
|
||||
id: member_actor_id
|
||||
}
|
||||
}
|
||||
] <-
|
||||
Member.list_administrator_members_for_group(group_id) do
|
||||
actor_id == member_actor_id
|
||||
else
|
||||
_ -> false
|
||||
case Member.list_administrator_members_for_group(group_id) do
|
||||
[
|
||||
%Member{
|
||||
actor: %Actor{
|
||||
id: member_actor_id
|
||||
}
|
||||
}
|
||||
] ->
|
||||
actor_id == member_actor_id
|
||||
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,10 +35,17 @@ defmodule MobilizonWeb.Resolvers.Picture do
|
||||
|
||||
@spec do_fetch_picture(String.t()) :: {:ok, Picture.t()} | {:error, :not_found}
|
||||
defp do_fetch_picture(picture_id) do
|
||||
with %Picture{id: id, file: file} = _pic <- Media.get_picture(picture_id) do
|
||||
{:ok,
|
||||
%{name: file.name, url: file.url, id: id, content_type: file.content_type, size: file.size}}
|
||||
else
|
||||
case Media.get_picture(picture_id) do
|
||||
%Picture{id: id, file: file} = _pic ->
|
||||
{:ok,
|
||||
%{
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
id: id,
|
||||
content_type: file.content_type,
|
||||
size: file.size
|
||||
}}
|
||||
|
||||
_err ->
|
||||
{:error, "Picture with ID #{picture_id} was not found"}
|
||||
end
|
||||
|
||||
@@ -94,7 +94,9 @@ defmodule MobilizonWeb.Upload do
|
||||
{:same_host, true} <- {:same_host, host == MobilizonWeb.Endpoint.host()} do
|
||||
MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path)
|
||||
else
|
||||
%URI{} = _uri -> {:error, "URL doesn't match pattern"}
|
||||
%URI{} = _uri ->
|
||||
{:error, "URL doesn't match pattern"}
|
||||
|
||||
{:same_host, _} ->
|
||||
Logger.error("Media can't be deleted because its URL doesn't match current host")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user