refactor(backend): change naming of function names to avoid the is_ prefix
Following Credo.Check.Readability.PredicateFunctionNames check Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -209,8 +209,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||
@doc """
|
||||
Checks whether actor visibility is public.
|
||||
"""
|
||||
@spec is_public_visibility?(t) :: boolean
|
||||
def is_public_visibility?(%__MODULE__{visibility: visibility}) do
|
||||
@spec public_visibility?(t) :: boolean
|
||||
def public_visibility?(%__MODULE__{visibility: visibility}) do
|
||||
visibility in [:public, :unlisted]
|
||||
end
|
||||
|
||||
|
||||
@@ -710,8 +710,8 @@ defmodule Mobilizon.Actors do
|
||||
@doc """
|
||||
Returns whether the `actor_id` is a confirmed member for the group `parent_id`
|
||||
"""
|
||||
@spec is_member?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def is_member?(actor_id, parent_id) do
|
||||
@spec member?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def member?(actor_id, parent_id) do
|
||||
match?(
|
||||
{:ok, %Member{}},
|
||||
get_member(actor_id, parent_id, @member_roles)
|
||||
@@ -721,8 +721,8 @@ defmodule Mobilizon.Actors do
|
||||
@doc """
|
||||
Returns whether the `actor_id` is a moderator for the group `parent_id`
|
||||
"""
|
||||
@spec is_moderator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def is_moderator?(actor_id, parent_id) do
|
||||
@spec moderator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def moderator?(actor_id, parent_id) do
|
||||
match?(
|
||||
{:ok, %Member{}},
|
||||
get_member(actor_id, parent_id, @moderator_roles)
|
||||
@@ -732,8 +732,8 @@ defmodule Mobilizon.Actors do
|
||||
@doc """
|
||||
Returns whether the `actor_id` is an administrator for the group `parent_id`
|
||||
"""
|
||||
@spec is_administrator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def is_administrator?(actor_id, parent_id) do
|
||||
@spec administrator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def administrator?(actor_id, parent_id) do
|
||||
match?(
|
||||
{:ok, %Member{}},
|
||||
get_member(actor_id, parent_id, @administrator_roles)
|
||||
@@ -922,8 +922,8 @@ defmodule Mobilizon.Actors do
|
||||
@doc """
|
||||
Returns whether the member is the last administrator for a group
|
||||
"""
|
||||
@spec is_only_administrator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def is_only_administrator?(member_id, group_id) do
|
||||
@spec only_administrator?(integer | String.t(), integer | String.t()) :: boolean()
|
||||
def only_administrator?(member_id, group_id) do
|
||||
Member
|
||||
|> where(
|
||||
[m],
|
||||
|
||||
@@ -55,9 +55,10 @@ defmodule Mobilizon.Actors.Member do
|
||||
@doc """
|
||||
Checks whether the member is an administrator (admin or creator) of the group.
|
||||
"""
|
||||
def is_administrator(%__MODULE__{role: :administrator}), do: true
|
||||
def is_administrator(%__MODULE__{role: :creator}), do: true
|
||||
def is_administrator(%__MODULE__{}), do: false
|
||||
@spec administrator?(t()) :: boolean()
|
||||
def administrator?(%__MODULE__{role: :administrator}), do: true
|
||||
def administrator?(%__MODULE__{role: :creator}), do: true
|
||||
def administrator?(%__MODULE__{}), do: false
|
||||
|
||||
@doc false
|
||||
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
||||
|
||||
@@ -515,8 +515,8 @@ defmodule Mobilizon.Events do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@spec is_user_moderator_for_event?(integer | String.t(), integer | String.t()) :: boolean
|
||||
def is_user_moderator_for_event?(user_id, event_id) do
|
||||
@spec user_moderator_for_event?(integer | String.t(), integer | String.t()) :: boolean
|
||||
def user_moderator_for_event?(user_id, event_id) do
|
||||
Participant
|
||||
|> join(:inner, [p], a in Actor, on: p.actor_id == a.id)
|
||||
|> where([p, _a], p.event_id == ^event_id)
|
||||
@@ -1492,14 +1492,14 @@ defmodule Mobilizon.Events do
|
||||
end
|
||||
|
||||
@spec filter_online(Ecto.Query.t(), map()) :: Ecto.Query.t()
|
||||
defp filter_online(query, %{type: :online}), do: is_online_fragment(query, true)
|
||||
defp filter_online(query, %{type: :online}), do: online_fragment_check(query, true)
|
||||
|
||||
defp filter_online(query, %{type: :in_person}), do: is_online_fragment(query, false)
|
||||
defp filter_online(query, %{type: :in_person}), do: online_fragment_check(query, false)
|
||||
|
||||
defp filter_online(query, _), do: query
|
||||
|
||||
@spec is_online_fragment(Ecto.Query.t(), boolean()) :: Ecto.Query.t()
|
||||
defp is_online_fragment(query, value) do
|
||||
@spec online_fragment_check(Ecto.Query.t(), boolean()) :: Ecto.Query.t()
|
||||
defp online_fragment_check(query, value) do
|
||||
where(query, [q], fragment("(?->>'is_online')::bool = ?", q.options, ^value))
|
||||
end
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ defmodule Mobilizon.Events.Participant do
|
||||
We start by fetching the list of organizers and if there's only one of them
|
||||
and that it's the actor requesting leaving the event we return true.
|
||||
"""
|
||||
@spec is_not_only_organizer(integer | String.t(), integer | String.t()) :: boolean
|
||||
def is_not_only_organizer(event_id, actor_id) do
|
||||
@spec not_only_organizer?(integer | String.t(), integer | String.t()) :: boolean
|
||||
def not_only_organizer?(event_id, actor_id) do
|
||||
case Events.list_organizers_participants_for_event(event_id) do
|
||||
[%__MODULE__{actor: %Actor{id: participant_actor_id}}] ->
|
||||
participant_actor_id == actor_id
|
||||
|
||||
@@ -214,7 +214,7 @@ defmodule Mobilizon.Medias do
|
||||
query
|
||||
|> Repo.all(timeout: :infinity)
|
||||
|> Enum.filter(fn %Media{file: %File{url: url}} ->
|
||||
!url_is_also_a_profile_file?(url) && is_all_media_orphan?(url, expiration_date)
|
||||
!url_is_also_a_profile_file?(url) && all_media_orphan?(url, expiration_date)
|
||||
end)
|
||||
|> Enum.chunk_by(fn %Media{file: %File{url: url}} ->
|
||||
url
|
||||
@@ -223,14 +223,14 @@ defmodule Mobilizon.Medias do
|
||||
end)
|
||||
end
|
||||
|
||||
defp is_all_media_orphan?(url, expiration_date) do
|
||||
defp all_media_orphan?(url, expiration_date) do
|
||||
url
|
||||
|> get_all_media_by_url()
|
||||
|> Enum.all?(&is_media_orphan?(&1, expiration_date))
|
||||
|> Enum.all?(&media_orphan?(&1, expiration_date))
|
||||
end
|
||||
|
||||
@spec is_media_orphan?(Media.t(), DateTime.t()) :: boolean()
|
||||
defp is_media_orphan?(%Media{id: media_id}, expiration_date) do
|
||||
@spec media_orphan?(Media.t(), DateTime.t()) :: boolean()
|
||||
defp media_orphan?(%Media{id: media_id}, expiration_date) do
|
||||
media_query =
|
||||
from(m in Media,
|
||||
as: :media,
|
||||
|
||||
Reference in New Issue
Block a user