@@ -189,12 +189,6 @@ defmodule Mobilizon.Activities do
|
||||
Repo.preload(activity, @activity_preloads)
|
||||
end
|
||||
|
||||
@spec object_types :: list(String.t())
|
||||
def object_types, do: @object_type
|
||||
|
||||
@spec subjects :: list(String.t())
|
||||
def subjects, do: @subjects
|
||||
|
||||
@spec activity_types :: list(String.t())
|
||||
def activity_types, do: @activity_types
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@spec get_actor_with_preload!(integer | String.t(), boolean) :: Actor.t()
|
||||
def get_actor_with_preload!(id, include_suspended \\ false) do
|
||||
@spec get_actor_with_preload!(integer | String.t()) :: Actor.t()
|
||||
def get_actor_with_preload!(id) do
|
||||
id
|
||||
|> actor_with_preload_query(include_suspended)
|
||||
|> actor_with_preload_query(false)
|
||||
|> Repo.one!()
|
||||
end
|
||||
|
||||
@@ -100,14 +100,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@spec get_remote_actor_with_preload(integer | String.t(), boolean()) :: Actor.t() | nil
|
||||
def get_remote_actor_with_preload(id, include_suspended \\ false) do
|
||||
id
|
||||
|> actor_with_preload_query(include_suspended)
|
||||
|> filter_external()
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an actor by its URL (ActivityPub ID). The `:preload` option allows to
|
||||
preload the followers relation.
|
||||
@@ -131,11 +123,9 @@ defmodule Mobilizon.Actors do
|
||||
New function to replace `Mobilizon.Actors.get_actor_by_url/1` with
|
||||
better signature
|
||||
"""
|
||||
@spec get_actor_by_url_2(String.t(), boolean) :: Actor.t() | nil
|
||||
def get_actor_by_url_2(url, preload \\ false) do
|
||||
Actor
|
||||
|> Repo.get_by(url: url)
|
||||
|> preload_followers(preload)
|
||||
@spec get_actor_by_url_2(String.t()) :: Actor.t() | nil
|
||||
def get_actor_by_url_2(url) do
|
||||
Repo.get_by(Actor, url: url)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -495,16 +485,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a local group by its title.
|
||||
"""
|
||||
@spec get_local_group_by_title(String.t()) :: Actor.t() | nil
|
||||
def get_local_group_by_title(title) do
|
||||
group_query()
|
||||
|> filter_by_name([title])
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a group by its actor id.
|
||||
"""
|
||||
@@ -575,11 +555,6 @@ defmodule Mobilizon.Actors do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a group.
|
||||
"""
|
||||
def delete_group!(%Actor{type: :Group} = group), do: Repo.delete!(group)
|
||||
|
||||
@doc """
|
||||
Counts the local groups
|
||||
"""
|
||||
@@ -599,15 +574,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Lists the groups.
|
||||
"""
|
||||
@spec list_groups(integer | nil, integer | nil) :: Page.t()
|
||||
def list_groups(page \\ nil, limit \\ nil) do
|
||||
groups_query()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Lists the groups.
|
||||
"""
|
||||
@@ -620,10 +586,10 @@ defmodule Mobilizon.Actors do
|
||||
@doc """
|
||||
Lists the groups.
|
||||
"""
|
||||
@spec list_external_groups(non_neg_integer()) :: list(Actor.t())
|
||||
def list_external_groups(limit \\ 100) when limit > 0 do
|
||||
@spec list_external_groups :: list(Actor.t())
|
||||
def list_external_groups do
|
||||
external_groups_query()
|
||||
|> limit(^limit)
|
||||
|> limit(100)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@@ -833,30 +799,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@spec list_local_members_for_group(Actor.t(), integer | nil, integer | nil) ::
|
||||
Page.t(Member.t())
|
||||
def list_local_members_for_group(
|
||||
%Actor{id: group_id, type: :Group} = _group,
|
||||
page \\ nil,
|
||||
limit \\ nil
|
||||
) do
|
||||
group_id
|
||||
|> group_internal_member_query()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@spec list_remote_members_for_group(Actor.t(), integer | nil, integer | nil) ::
|
||||
Page.t(Member.t())
|
||||
def list_remote_members_for_group(
|
||||
%Actor{id: group_id, type: :Group} = _group,
|
||||
page \\ nil,
|
||||
limit \\ nil
|
||||
) do
|
||||
group_id
|
||||
|> group_external_member_query()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a paginated list of members for a group.
|
||||
"""
|
||||
@@ -888,17 +830,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a paginated list of administrator members for a group.
|
||||
"""
|
||||
@spec list_administrator_members_for_group(integer | String.t(), integer | nil, integer | nil) ::
|
||||
Page.t()
|
||||
def list_administrator_members_for_group(id, page \\ nil, limit \\ nil) do
|
||||
id
|
||||
|> administrator_members_for_group_query()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the complete list of administrator members for a group.
|
||||
"""
|
||||
@@ -1012,12 +943,6 @@ defmodule Mobilizon.Actors do
|
||||
@spec delete_bot(Bot.t()) :: {:ok, Bot.t()} | {:error, Ecto.Changeset.t()}
|
||||
def delete_bot(%Bot{} = bot), do: Repo.delete(bot)
|
||||
|
||||
@doc """
|
||||
Returns the list of bots.
|
||||
"""
|
||||
@spec list_bots :: [Bot.t()]
|
||||
def list_bots, do: Repo.all(Bot)
|
||||
|
||||
@doc """
|
||||
Gets a single follower.
|
||||
"""
|
||||
@@ -1105,17 +1030,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.delete()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of followers for an actor.
|
||||
If actor A and C both follow actor B, actor B's followers are A and C.
|
||||
"""
|
||||
@spec list_followers_actors_for_actor(Actor.t()) :: [Actor.t()]
|
||||
def list_followers_actors_for_actor(%Actor{id: actor_id}) do
|
||||
actor_id
|
||||
|> follower_actors_for_actor_query()
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of external followers for an actor.
|
||||
"""
|
||||
@@ -1177,17 +1091,6 @@ defmodule Mobilizon.Actors do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of followings for an actor.
|
||||
If actor A follows actor B and C, actor A's followings are B and C.
|
||||
"""
|
||||
@spec list_followings_for_actor(Actor.t()) :: [Follower.t()]
|
||||
def list_followings_for_actor(%Actor{id: actor_id}) do
|
||||
actor_id
|
||||
|> followings_actors_for_actor_query()
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the number of followings for an actor
|
||||
"""
|
||||
@@ -1485,16 +1388,6 @@ defmodule Mobilizon.Actors do
|
||||
|> select([_m, a], a)
|
||||
end
|
||||
|
||||
@spec group_external_member_query(integer()) :: Ecto.Query.t()
|
||||
defp group_external_member_query(group_id) do
|
||||
Member
|
||||
|> where([m], m.parent_id == ^group_id)
|
||||
|> join(:inner, [m], a in Actor, on: m.actor_id == a.id)
|
||||
|> where([_m, a], not is_nil(a.domain))
|
||||
|> preload([m], [:parent, :actor])
|
||||
|> select([m, _a], m)
|
||||
end
|
||||
|
||||
@spec group_internal_member_actor_query(integer(), list()) :: Ecto.Query.t()
|
||||
defp group_internal_member_actor_query(group_id, role) do
|
||||
Member
|
||||
|
||||
@@ -223,10 +223,6 @@ defmodule Mobilizon.Config do
|
||||
:confirmation_required
|
||||
]
|
||||
|
||||
@spec anonymous_participation_email_captcha_required? :: boolean
|
||||
def anonymous_participation_email_captcha_required?,
|
||||
do: anonymous_config()[:participation][:validation][:captcha][:enabled]
|
||||
|
||||
@spec anonymous_event_creation? :: boolean
|
||||
def anonymous_event_creation?,
|
||||
do: anonymous_config()[:event_creation][:allowed]
|
||||
@@ -265,9 +261,6 @@ defmodule Mobilizon.Config do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec oauth_consumer_enabled? :: boolean()
|
||||
def oauth_consumer_enabled?, do: oauth_consumer_strategies() != []
|
||||
|
||||
@spec ldap_enabled? :: boolean()
|
||||
def ldap_enabled?, do: get([:ldap, :enabled], false)
|
||||
|
||||
|
||||
@@ -125,13 +125,6 @@ defmodule Mobilizon.Discussions do
|
||||
@spec get_comment_from_url(String.t()) :: Comment.t() | nil
|
||||
def get_comment_from_url(url), do: Repo.get_by(Comment, url: url)
|
||||
|
||||
@doc """
|
||||
Gets a comment by its URL.
|
||||
Raises `Ecto.NoResultsError` if the comment does not exist.
|
||||
"""
|
||||
@spec get_comment_from_url!(String.t()) :: Comment.t()
|
||||
def get_comment_from_url!(url), do: Repo.get_by!(Comment, url: url)
|
||||
|
||||
@doc """
|
||||
Gets a comment by its URL, with all associations loaded.
|
||||
"""
|
||||
@@ -175,19 +168,6 @@ defmodule Mobilizon.Discussions do
|
||||
|> Repo.preload(@comment_preloads)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get all comment threads under an event
|
||||
"""
|
||||
@spec get_threads(String.t() | integer()) :: [Comment.t()]
|
||||
def get_threads(event_id) do
|
||||
Comment
|
||||
|> where([c, _], c.event_id == ^event_id and is_nil(c.origin_comment_id))
|
||||
|> join(:left, [c], r in Comment, on: r.origin_comment_id == c.id)
|
||||
|> group_by([c], c.id)
|
||||
|> select([c, r], %{c | total_replies: count(r.id)})
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets paginated replies for root comment
|
||||
"""
|
||||
@@ -198,17 +178,6 @@ defmodule Mobilizon.Discussions do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a comment or create it
|
||||
"""
|
||||
@spec get_or_create_comment(map()) :: {:ok, Comment.t()}
|
||||
def get_or_create_comment(%{"url" => url} = attrs) do
|
||||
case Repo.get_by(Comment, url: url) do
|
||||
%Comment{} = comment -> {:ok, Repo.preload(comment, @comment_preloads)}
|
||||
nil -> create_comment(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a comment.
|
||||
"""
|
||||
@@ -253,14 +222,6 @@ defmodule Mobilizon.Discussions do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of public comments.
|
||||
"""
|
||||
@spec list_comments :: [Comment.t()]
|
||||
def list_comments do
|
||||
Repo.all(from(c in Comment, where: c.visibility == ^:public))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a paginated list of local comments
|
||||
"""
|
||||
|
||||
@@ -159,34 +159,11 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one!()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an event by its URL, with all associations loaded.
|
||||
"""
|
||||
@spec get_public_event_by_url_with_preload(String.t()) ::
|
||||
{:ok, Event.t()} | {:error, :event_not_found}
|
||||
def get_public_event_by_url_with_preload(url) do
|
||||
event =
|
||||
url
|
||||
|> event_by_url_query()
|
||||
|> filter_unlisted_and_public_visibility()
|
||||
|> filter_draft()
|
||||
|> preload_for_event()
|
||||
|> Repo.one()
|
||||
|
||||
case event do
|
||||
%Event{} = event ->
|
||||
{:ok, event}
|
||||
|
||||
nil ->
|
||||
{:error, :event_not_found}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an event by its URL, with all associations loaded.
|
||||
Raises `Ecto.NoResultsError` if the event does not exist.
|
||||
"""
|
||||
@spec get_public_event_by_url_with_preload(String.t()) :: Event.t()
|
||||
@spec get_public_event_by_url_with_preload!(String.t()) :: Event.t()
|
||||
def get_public_event_by_url_with_preload!(url) do
|
||||
url
|
||||
|> event_by_url_query()
|
||||
@@ -228,18 +205,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an event by its UUID, with all associations loaded.
|
||||
"""
|
||||
@spec get_own_event_by_uuid_with_preload(String.t(), integer()) :: Event.t() | nil
|
||||
def get_own_event_by_uuid_with_preload(uuid, user_id) do
|
||||
uuid
|
||||
|> event_by_uuid_query()
|
||||
|> user_events_query(user_id)
|
||||
|> preload_for_event()
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an actor's eventual upcoming public event.
|
||||
"""
|
||||
@@ -253,13 +218,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
def get_or_create_event(%{"url" => url} = attrs) do
|
||||
case Repo.get_by(Event, url: url) do
|
||||
%Event{} = event -> {:ok, Repo.preload(event, @event_preloads)}
|
||||
nil -> create_event(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates an event.
|
||||
"""
|
||||
@@ -502,9 +460,9 @@ defmodule Mobilizon.Events do
|
||||
Finds close events to coordinates.
|
||||
Radius is in meters and defaults to 50km.
|
||||
"""
|
||||
@spec find_close_events(number, number, number, number) :: [Event.t()]
|
||||
def find_close_events(lon, lat, radius \\ 50_000, srid \\ 4326) do
|
||||
"SRID=#{srid};POINT(#{lon} #{lat})"
|
||||
@spec find_close_events(float(), float(), non_neg_integer()) :: [Event.t()]
|
||||
def find_close_events(lon, lat, radius \\ 50_000) do
|
||||
"SRID=#{4326};POINT(#{lon} #{lat})"
|
||||
|> Geo.WKT.decode!()
|
||||
|> close_events_query(radius)
|
||||
|> filter_draft()
|
||||
@@ -585,33 +543,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an existing tag or creates the new one.
|
||||
|
||||
From a map containing a %{"name" => "#mytag"} or a direct binary
|
||||
"""
|
||||
@spec get_or_create_tag(map) :: {:ok, Tag.t()} | {:error, Changeset.t()}
|
||||
def get_or_create_tag(%{"name" => "#" <> title}) do
|
||||
case Repo.get_by(Tag, title: title) do
|
||||
%Tag{} = tag ->
|
||||
{:ok, tag}
|
||||
|
||||
nil ->
|
||||
create_tag(%{"title" => title})
|
||||
end
|
||||
end
|
||||
|
||||
@spec get_or_create_tag(String.t()) :: {:ok, Tag.t()} | {:error, Changeset.t()}
|
||||
def get_or_create_tag(title) do
|
||||
case Repo.get_by(Tag, title: title) do
|
||||
%Tag{} = tag ->
|
||||
{:ok, tag}
|
||||
|
||||
nil ->
|
||||
create_tag(%{"title" => title})
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a tag.
|
||||
"""
|
||||
@@ -663,8 +594,8 @@ defmodule Mobilizon.Events do
|
||||
@doc """
|
||||
Checks whether two tags are linked or not.
|
||||
"""
|
||||
@spec are_tags_linked(Tag.t(), Tag.t()) :: boolean
|
||||
def are_tags_linked(%Tag{id: tag1_id}, %Tag{id: tag2_id}) do
|
||||
@spec are_tags_linked?(Tag.t(), Tag.t()) :: boolean
|
||||
def are_tags_linked?(%Tag{id: tag1_id}, %Tag{id: tag2_id}) do
|
||||
tag_relation =
|
||||
tag1_id
|
||||
|> tags_linked_query(tag2_id)
|
||||
@@ -833,8 +764,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@moderator_roles [:moderator, :administrator, :creator]
|
||||
|
||||
@doc """
|
||||
Returns the number of participations for all local events
|
||||
"""
|
||||
@@ -894,28 +823,6 @@ defmodule Mobilizon.Events do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of moderator participants for an event.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> moderator_for_event?(5, 3)
|
||||
true
|
||||
|
||||
"""
|
||||
@spec moderator_for_event?(integer, integer) :: boolean
|
||||
def moderator_for_event?(event_id, actor_id) do
|
||||
!(Repo.one(
|
||||
from(
|
||||
p in Participant,
|
||||
where:
|
||||
p.event_id == ^event_id and
|
||||
p.actor_id ==
|
||||
^actor_id and p.role in ^@moderator_roles
|
||||
)
|
||||
) == nil)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of organizers participants for an event.
|
||||
|
||||
@@ -957,17 +864,6 @@ defmodule Mobilizon.Events do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Counts approved participants.
|
||||
"""
|
||||
@spec count_approved_participants(integer | String.t()) :: integer
|
||||
def count_approved_participants(event_id) do
|
||||
event_id
|
||||
|> count_participants_query()
|
||||
|> filter_approved_role()
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Counts participant participants (participants with no extra role)
|
||||
"""
|
||||
@@ -979,17 +875,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Counts rejected participants.
|
||||
"""
|
||||
@spec count_rejected_participants(integer | String.t()) :: integer
|
||||
def count_rejected_participants(event_id) do
|
||||
event_id
|
||||
|> count_participants_query()
|
||||
|> filter_rejected_role()
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets the default participant role depending on the event join options.
|
||||
"""
|
||||
@@ -1221,17 +1106,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single feed token.
|
||||
Raises `Ecto.NoResultsError` if the feed token does not exist.
|
||||
"""
|
||||
@spec get_feed_token!(String.t()) :: FeedToken.t()
|
||||
def get_feed_token!(token) do
|
||||
token
|
||||
|> feed_token_query()
|
||||
|> Repo.one!()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a feed token.
|
||||
"""
|
||||
@@ -1244,17 +1118,6 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a feed token.
|
||||
"""
|
||||
@spec update_feed_token(FeedToken.t(), map) ::
|
||||
{:ok, FeedToken.t()} | {:error, Changeset.t()}
|
||||
def update_feed_token(%FeedToken{} = feed_token, attrs) do
|
||||
feed_token
|
||||
|> FeedToken.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a feed token.
|
||||
"""
|
||||
@@ -1746,21 +1609,11 @@ defmodule Mobilizon.Events do
|
||||
)
|
||||
end
|
||||
|
||||
@spec filter_approved_role(Ecto.Queryable.t()) :: Ecto.Query.t()
|
||||
defp filter_approved_role(query) do
|
||||
filter_role(query, [:not_approved, :rejected])
|
||||
end
|
||||
|
||||
@spec filter_participant_role(Ecto.Queryable.t()) :: Ecto.Query.t()
|
||||
defp filter_participant_role(query) do
|
||||
filter_role(query, :participant)
|
||||
end
|
||||
|
||||
@spec filter_rejected_role(Ecto.Queryable.t()) :: Ecto.Query.t()
|
||||
defp filter_rejected_role(query) do
|
||||
filter_role(query, :rejected)
|
||||
end
|
||||
|
||||
@spec filter_role(Ecto.Queryable.t(), list(atom()) | atom()) :: Ecto.Query.t()
|
||||
def filter_role(query, []), do: query
|
||||
|
||||
|
||||
@@ -52,16 +52,6 @@ defmodule Mobilizon.Medias do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
List the paginated media for an actor
|
||||
"""
|
||||
@spec medias_for_actor(integer | String.t(), integer | nil, integer | nil) :: Page.t()
|
||||
def medias_for_actor(actor_id, page, limit) do
|
||||
actor_id
|
||||
|> medias_for_actor_query()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
List the paginated media for user
|
||||
"""
|
||||
@@ -109,16 +99,6 @@ defmodule Mobilizon.Medias do
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a media.
|
||||
"""
|
||||
@spec update_media(Media.t(), map) :: {:ok, Media.t()} | {:error, Ecto.Changeset.t()}
|
||||
def update_media(%Media{} = media, attrs) do
|
||||
media
|
||||
|> Media.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a media.
|
||||
"""
|
||||
|
||||
@@ -69,10 +69,6 @@ defmodule Mobilizon.Posts do
|
||||
|> Repo.preload(@post_preloads)
|
||||
end
|
||||
|
||||
@spec get_post_by_slug(String.t()) :: Post.t() | nil
|
||||
def get_post_by_slug(nil), do: nil
|
||||
def get_post_by_slug(slug), do: Repo.get_by(Post, slug: slug)
|
||||
|
||||
@spec get_post_by_slug_with_preloads(String.t()) :: Post.t() | nil
|
||||
def get_post_by_slug_with_preloads(slug) do
|
||||
Post
|
||||
|
||||
@@ -23,27 +23,6 @@ defmodule Mobilizon.Reports do
|
||||
|> Repo.preload([:reported, :reporter, :manager, :event, :comments, :notes])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single report.
|
||||
Raises `Ecto.NoResultsError` if the report does not exist.
|
||||
"""
|
||||
@spec get_report!(integer | String.t()) :: Report.t()
|
||||
def get_report!(id) do
|
||||
Report
|
||||
|> Repo.get!(id)
|
||||
|> Repo.preload([:reported, :reporter, :manager, :event, :comments, :notes])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a report by its URL
|
||||
"""
|
||||
@spec get_report_by_url(String.t()) :: Report.t() | nil
|
||||
def get_report_by_url(url) do
|
||||
url
|
||||
|> report_by_url_query()
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a report.
|
||||
"""
|
||||
@@ -67,12 +46,6 @@ defmodule Mobilizon.Reports do
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a report.
|
||||
"""
|
||||
@spec delete_report(Report.t()) :: {:ok, Report.t()} | {:error, Ecto.Changeset.t()}
|
||||
def delete_report(%Report{} = report), do: Repo.delete(report)
|
||||
|
||||
@doc """
|
||||
Returns the list of reports.
|
||||
"""
|
||||
@@ -104,13 +77,6 @@ defmodule Mobilizon.Reports do
|
||||
@spec get_note(integer | String.t()) :: Note.t() | nil
|
||||
def get_note(id), do: Repo.get(Note, id)
|
||||
|
||||
@doc """
|
||||
Gets a single note.
|
||||
Raises `Ecto.NoResultsError` if the Note does not exist.
|
||||
"""
|
||||
@spec get_note!(integer | String.t()) :: Note.t()
|
||||
def get_note!(id), do: Repo.get!(Note, id)
|
||||
|
||||
@doc """
|
||||
Creates a note.
|
||||
"""
|
||||
@@ -130,21 +96,6 @@ defmodule Mobilizon.Reports do
|
||||
@spec delete_note(Note.t()) :: {:ok, Note.t()} | {:error, Ecto.Changeset.t()}
|
||||
def delete_note(%Note{} = note), do: Repo.delete(note)
|
||||
|
||||
@doc """
|
||||
Returns the list of notes for a report.
|
||||
"""
|
||||
@spec list_notes_for_report(Report.t()) :: [Note.t()]
|
||||
def list_notes_for_report(%Report{id: report_id}) do
|
||||
report_id
|
||||
|> list_notes_for_report_query()
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@spec report_by_url_query(String.t()) :: Ecto.Query.t()
|
||||
defp report_by_url_query(url) do
|
||||
from(r in Report, where: r.uri == ^url)
|
||||
end
|
||||
|
||||
@spec list_reports_query(ReportStatus.t()) :: Ecto.Query.t()
|
||||
defp list_reports_query(status) do
|
||||
from(
|
||||
@@ -158,13 +109,4 @@ defmodule Mobilizon.Reports do
|
||||
defp count_reports_query do
|
||||
from(r in Report, where: r.status == ^:open)
|
||||
end
|
||||
|
||||
@spec list_notes_for_report_query(integer | String.t()) :: Ecto.Query.t()
|
||||
defp list_notes_for_report_query(report_id) do
|
||||
from(
|
||||
n in Note,
|
||||
where: n.report_id == ^report_id,
|
||||
preload: [:report, :moderator]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,13 +27,6 @@ defmodule Mobilizon.Resources do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of top-level resources for a group
|
||||
"""
|
||||
def get_top_level_resources_for_group(%Actor{id: group_id}, page \\ nil, limit \\ nil) do
|
||||
get_resources_for_folder(%Resource{id: "root_something", actor_id: group_id}, page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of resources for a resource folder.
|
||||
"""
|
||||
|
||||
@@ -188,13 +188,6 @@ defmodule Mobilizon.Users.User do
|
||||
|> hash_password()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks whether an user is confirmed.
|
||||
"""
|
||||
@spec is_confirmed(t) :: boolean
|
||||
def is_confirmed(%__MODULE__{confirmed_at: nil}), do: false
|
||||
def is_confirmed(%__MODULE__{}), do: true
|
||||
|
||||
@doc """
|
||||
Returns whether an user owns an actor.
|
||||
"""
|
||||
|
||||
@@ -91,19 +91,6 @@ defmodule Mobilizon.Users do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets an user by its email.
|
||||
"""
|
||||
@spec get_user_by_email!(String.t(), Keyword.t()) :: User.t()
|
||||
def get_user_by_email!(email, options \\ []) do
|
||||
activated = Keyword.get(options, :activated, nil)
|
||||
unconfirmed = Keyword.get(options, :unconfirmed, true)
|
||||
|
||||
email
|
||||
|> user_by_email_query(activated, unconfirmed)
|
||||
|> Repo.one!()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get an user by its activation token.
|
||||
"""
|
||||
@@ -326,22 +313,6 @@ defmodule Mobilizon.Users do
|
||||
@spec count_users :: integer
|
||||
def count_users, do: Repo.one(from(u in User, select: count(u.id), where: u.disabled == false))
|
||||
|
||||
@doc """
|
||||
Gets a settings for an user.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Setting does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_setting!(123)
|
||||
%Setting{}
|
||||
|
||||
iex> get_setting!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_setting!(user_id), do: Repo.get!(Setting, user_id)
|
||||
|
||||
@spec get_setting(User.t()) :: Setting.t() | nil
|
||||
def get_setting(%User{id: user_id}), do: get_setting(user_id)
|
||||
|
||||
@@ -388,35 +359,6 @@ defmodule Mobilizon.Users do
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a setting.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_setting(setting)
|
||||
{:ok, %Setting{}}
|
||||
|
||||
iex> delete_setting(setting)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_setting(%Setting{} = setting) do
|
||||
Repo.delete(setting)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking setting changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_setting(setting)
|
||||
%Ecto.Changeset{source: %Setting{}}
|
||||
|
||||
"""
|
||||
def change_setting(%Setting{} = setting) do
|
||||
Setting.changeset(setting, %{})
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a paginated list of all of a user's subscriptions
|
||||
"""
|
||||
@@ -458,24 +400,6 @@ defmodule Mobilizon.Users do
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a push subscription.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_push_subscription(push_subscription, %{field: new_value})
|
||||
{:ok, %PushSubscription{}}
|
||||
|
||||
iex> update_push_subscription(push_subscription, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_push_subscription(%PushSubscription{} = push_subscription, attrs) do
|
||||
push_subscription
|
||||
|> PushSubscription.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a push subscription.
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
# Portions of this file are derived from Pleroma:
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mobilizon.Utils do
|
||||
@moduledoc """
|
||||
Module that provide generic utils functions for Mobilizon
|
||||
"""
|
||||
|
||||
@doc """
|
||||
POSIX-compliant check if command is available in the system
|
||||
|
||||
## Examples
|
||||
iex> command_available?("git")
|
||||
true
|
||||
iex> command_available?("wrongcmd")
|
||||
false
|
||||
|
||||
"""
|
||||
@spec command_available?(String.t()) :: boolean()
|
||||
def command_available?(command) do
|
||||
match?({_output, 0}, System.cmd("sh", ["-c", "command -v #{command}"]))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user