forked from potsda.mn/mobilizon
Clean specs
This commit is contained in:
parent
56efb0acb1
commit
5967b30bb1
|
@ -8,7 +8,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.{Actors, Config, Crypto}
|
alias Mobilizon.{Actors, Config, Crypto}
|
||||||
alias Mobilizon.Actors.{Actor, ActorOpenness, ActorType, ActorVisibility, Follower, Member}
|
alias Mobilizon.Actors.{ActorOpenness, ActorType, ActorVisibility, Follower, Member}
|
||||||
alias Mobilizon.Events.{Event, FeedToken}
|
alias Mobilizon.Events.{Event, FeedToken}
|
||||||
alias Mobilizon.Media.File
|
alias Mobilizon.Media.File
|
||||||
alias Mobilizon.Reports.{Report, Note}
|
alias Mobilizon.Reports.{Report, Note}
|
||||||
|
@ -46,7 +46,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
created_reports: [Report.t()],
|
created_reports: [Report.t()],
|
||||||
subject_reports: [Report.t()],
|
subject_reports: [Report.t()],
|
||||||
report_notes: [Note.t()],
|
report_notes: [Note.t()],
|
||||||
memberships: [Actor.t()]
|
memberships: [t]
|
||||||
}
|
}
|
||||||
|
|
||||||
@required_attrs [:preferred_username, :keys, :suspended, :url]
|
@required_attrs [:preferred_username, :keys, :suspended, :url]
|
||||||
|
@ -139,7 +139,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
has_many(:created_reports, Report, foreign_key: :reporter_id)
|
has_many(:created_reports, Report, foreign_key: :reporter_id)
|
||||||
has_many(:subject_reports, Report, foreign_key: :reported_id)
|
has_many(:subject_reports, Report, foreign_key: :reported_id)
|
||||||
has_many(:report_notes, Note, foreign_key: :moderator_id)
|
has_many(:report_notes, Note, foreign_key: :moderator_id)
|
||||||
many_to_many(:memberships, Actor, join_through: Member)
|
many_to_many(:memberships, __MODULE__, join_through: Member)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
@ -147,8 +147,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
@doc """
|
@doc """
|
||||||
Checks whether actor visibility is public.
|
Checks whether actor visibility is public.
|
||||||
"""
|
"""
|
||||||
@spec is_public_visibility(Actor.t()) :: boolean
|
@spec is_public_visibility(t) :: boolean
|
||||||
def is_public_visibility(%Actor{visibility: visibility}) do
|
def is_public_visibility(%__MODULE__{visibility: visibility}) do
|
||||||
visibility in [:public, :unlisted]
|
visibility in [:public, :unlisted]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -156,22 +156,22 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
Returns the display name if available, or the preferred username
|
Returns the display name if available, or the preferred username
|
||||||
(with the eventual @domain suffix if it's a distant actor).
|
(with the eventual @domain suffix if it's a distant actor).
|
||||||
"""
|
"""
|
||||||
@spec display_name(Actor.t()) :: String.t()
|
@spec display_name(t) :: String.t()
|
||||||
def display_name(%Actor{name: name} = actor) when name in [nil, ""] do
|
def display_name(%__MODULE__{name: name} = actor) when name in [nil, ""] do
|
||||||
preferred_username_and_domain(actor)
|
preferred_username_and_domain(actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_name(%Actor{name: name}), do: name
|
def display_name(%__MODULE__{name: name}), do: name
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns display name and username.
|
Returns display name and username.
|
||||||
"""
|
"""
|
||||||
@spec display_name_and_username(Actor.t()) :: String.t()
|
@spec display_name_and_username(t) :: String.t()
|
||||||
def display_name_and_username(%Actor{name: name} = actor) when name in [nil, ""] do
|
def display_name_and_username(%__MODULE__{name: name} = actor) when name in [nil, ""] do
|
||||||
preferred_username_and_domain(actor)
|
preferred_username_and_domain(actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_name_and_username(%Actor{name: name} = actor) do
|
def display_name_and_username(%__MODULE__{name: name} = actor) do
|
||||||
"#{name} (#{preferred_username_and_domain(actor)})"
|
"#{name} (#{preferred_username_and_domain(actor)})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -179,18 +179,18 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
Returns the preferred username with the eventual @domain suffix if it's
|
Returns the preferred username with the eventual @domain suffix if it's
|
||||||
a distant actor.
|
a distant actor.
|
||||||
"""
|
"""
|
||||||
@spec preferred_username_and_domain(Actor.t()) :: String.t()
|
@spec preferred_username_and_domain(t) :: String.t()
|
||||||
def preferred_username_and_domain(%Actor{preferred_username: preferred_username, domain: nil}) do
|
def preferred_username_and_domain(%__MODULE__{preferred_username: preferred_username, domain: nil}) do
|
||||||
preferred_username
|
preferred_username
|
||||||
end
|
end
|
||||||
|
|
||||||
def preferred_username_and_domain(%Actor{preferred_username: preferred_username, domain: domain}) do
|
def preferred_username_and_domain(%__MODULE__{preferred_username: preferred_username, domain: domain}) do
|
||||||
"#{preferred_username}@#{domain}"
|
"#{preferred_username}@#{domain}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Actor{} = actor, attrs) do
|
def changeset(%__MODULE__{} = actor, attrs) do
|
||||||
actor
|
actor
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> build_urls()
|
|> build_urls()
|
||||||
|
@ -205,8 +205,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec update_changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec update_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def update_changeset(%Actor{} = actor, attrs) do
|
def update_changeset(%__MODULE__{} = actor, attrs) do
|
||||||
actor
|
actor
|
||||||
|> cast(attrs, @update_attrs)
|
|> cast(attrs, @update_attrs)
|
||||||
|> cast_embed(:avatar)
|
|> cast_embed(:avatar)
|
||||||
|
@ -221,8 +221,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
@doc """
|
@doc """
|
||||||
Changeset for person registration.
|
Changeset for person registration.
|
||||||
"""
|
"""
|
||||||
@spec registration_changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec registration_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def registration_changeset(%Actor{} = actor, attrs) do
|
def registration_changeset(%__MODULE__{} = actor, attrs) do
|
||||||
actor
|
actor
|
||||||
|> cast(attrs, @registration_attrs)
|
|> cast(attrs, @registration_attrs)
|
||||||
|> build_urls()
|
|> build_urls()
|
||||||
|
@ -242,7 +242,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
@spec remote_actor_creation_changeset(map) :: Ecto.Changeset.t()
|
@spec remote_actor_creation_changeset(map) :: Ecto.Changeset.t()
|
||||||
def remote_actor_creation_changeset(attrs) do
|
def remote_actor_creation_changeset(attrs) do
|
||||||
changeset =
|
changeset =
|
||||||
%Actor{}
|
%__MODULE__{}
|
||||||
|> cast(attrs, @remote_actor_creation_attrs)
|
|> cast(attrs, @remote_actor_creation_attrs)
|
||||||
|> validate_required(@remote_actor_creation_required_attrs)
|
|> validate_required(@remote_actor_creation_required_attrs)
|
||||||
|> cast_embed(:avatar)
|
|> cast_embed(:avatar)
|
||||||
|
@ -267,14 +267,14 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
def relay_creation_changeset(attrs) do
|
def relay_creation_changeset(attrs) do
|
||||||
relay_creation_attrs = build_relay_creation_attrs(attrs)
|
relay_creation_attrs = build_relay_creation_attrs(attrs)
|
||||||
|
|
||||||
cast(%Actor{}, relay_creation_attrs, @relay_creation_attrs)
|
cast(%__MODULE__{}, relay_creation_attrs, @relay_creation_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Changeset for group creation
|
Changeset for group creation
|
||||||
"""
|
"""
|
||||||
@spec group_creation(struct(), map()) :: Ecto.Changeset.t()
|
@spec group_creation_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def group_creation(%Actor{} = actor, params) do
|
def group_creation_changeset(%__MODULE__{} = actor, params) do
|
||||||
actor
|
actor
|
||||||
|> cast(params, @group_creation_attrs)
|
|> cast(params, @group_creation_attrs)
|
||||||
|> cast_embed(:avatar)
|
|> cast_embed(:avatar)
|
||||||
|
@ -299,7 +299,7 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
%Ecto.Changeset{changes: %{preferred_username: username} = changes} = changeset
|
%Ecto.Changeset{changes: %{preferred_username: username} = changes} = changeset
|
||||||
) do
|
) do
|
||||||
with nil <- Map.get(changes, :domain, nil),
|
with nil <- Map.get(changes, :domain, nil),
|
||||||
%Actor{preferred_username: _} <- Actors.get_local_actor_by_name(username) do
|
%__MODULE__{preferred_username: _} <- Actors.get_local_actor_by_name(username) do
|
||||||
add_error(changeset, :preferred_username, "Username is already taken")
|
add_error(changeset, :preferred_username, "Username is already taken")
|
||||||
else
|
else
|
||||||
_ -> changeset
|
_ -> changeset
|
||||||
|
@ -349,8 +349,8 @@ defmodule Mobilizon.Actors.Actor do
|
||||||
Clear multiple caches for an actor
|
Clear multiple caches for an actor
|
||||||
"""
|
"""
|
||||||
# TODO: move to MobilizonWeb
|
# TODO: move to MobilizonWeb
|
||||||
@spec clear_cache(struct()) :: {:ok, true}
|
@spec clear_cache(t) :: {:ok, true}
|
||||||
def clear_cache(%Actor{preferred_username: preferred_username, domain: nil}) do
|
def clear_cache(%__MODULE__{preferred_username: preferred_username, domain: nil}) do
|
||||||
Cachex.del(:activity_pub, "actor_" <> preferred_username)
|
Cachex.del(:activity_pub, "actor_" <> preferred_username)
|
||||||
Cachex.del(:feed, "actor_" <> preferred_username)
|
Cachex.del(:feed, "actor_" <> preferred_username)
|
||||||
Cachex.del(:ics, "actor_" <> preferred_username)
|
Cachex.del(:ics, "actor_" <> preferred_username)
|
||||||
|
|
|
@ -340,7 +340,7 @@ defmodule Mobilizon.Actors do
|
||||||
@spec create_group(map) :: {:ok, Actor.t()} | {:error, Ecto.Changeset.t()}
|
@spec create_group(map) :: {:ok, Actor.t()} | {:error, Ecto.Changeset.t()}
|
||||||
def create_group(attrs \\ %{}) do
|
def create_group(attrs \\ %{}) do
|
||||||
%Actor{}
|
%Actor{}
|
||||||
|> Actor.group_creation(attrs)
|
|> Actor.group_creation_changeset(attrs)
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ defmodule Mobilizon.Actors.Bot do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(bot, attrs) do
|
def changeset(%__MODULE__{} = bot, attrs) do
|
||||||
bot
|
bot
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -29,7 +29,7 @@ defmodule Mobilizon.Actors.Follower do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(follower, attrs) do
|
def changeset(follower, attrs) do
|
||||||
follower
|
follower
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Mobilizon.Actors.Member do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Actors.{Actor, Member, MemberRole}
|
alias Mobilizon.Actors.{Actor, MemberRole}
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
role: MemberRole.t(),
|
role: MemberRole.t(),
|
||||||
|
@ -44,13 +44,13 @@ defmodule Mobilizon.Actors.Member do
|
||||||
@doc """
|
@doc """
|
||||||
Checks whether the member is an administrator (admin or creator) of the group.
|
Checks whether the member is an administrator (admin or creator) of the group.
|
||||||
"""
|
"""
|
||||||
def is_administrator(%Member{role: :administrator}), do: {:is_admin, true}
|
def is_administrator(%__MODULE__{role: :administrator}), do: {:is_admin, true}
|
||||||
def is_administrator(%Member{role: :creator}), do: {:is_admin, true}
|
def is_administrator(%__MODULE__{role: :creator}), do: {:is_admin, true}
|
||||||
def is_administrator(%Member{}), do: {:is_admin, false}
|
def is_administrator(%__MODULE__{}), do: {:is_admin, false}
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(member, attrs) do
|
def changeset(%__MODULE__{} = member, attrs) do
|
||||||
member
|
member
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -7,7 +7,6 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Addresses.Address
|
|
||||||
alias Mobilizon.Events.Event
|
alias Mobilizon.Events.Event
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
|
@ -56,8 +55,8 @@ defmodule Mobilizon.Addresses.Address do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Address{} = address, attrs) do
|
def changeset(%__MODULE__{} = address, attrs) do
|
||||||
address
|
address
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> set_url()
|
|> set_url()
|
||||||
|
|
|
@ -33,8 +33,8 @@ defmodule Mobilizon.Admin.ActionLog do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(action_log, attrs) do
|
def changeset(%__MODULE__{} = action_log, attrs) do
|
||||||
action_log
|
action_log
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -48,13 +48,13 @@ defmodule Mobilizon.Events.Comment do
|
||||||
Returns the id of the first comment in the conversation.
|
Returns the id of the first comment in the conversation.
|
||||||
"""
|
"""
|
||||||
@spec get_thread_id(t) :: integer
|
@spec get_thread_id(t) :: integer
|
||||||
def get_thread_id(%Comment{id: id, origin_comment_id: origin_comment_id}) do
|
def get_thread_id(%__MODULE__{id: id, origin_comment_id: origin_comment_id}) do
|
||||||
origin_comment_id || id
|
origin_comment_id || id
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Comment{} = comment, attrs) do
|
def changeset(%__MODULE__{} = comment, attrs) do
|
||||||
uuid = attrs["uuid"] || Ecto.UUID.generate()
|
uuid = attrs["uuid"] || Ecto.UUID.generate()
|
||||||
url = attrs["url"] || generate_url(uuid)
|
url = attrs["url"] || generate_url(uuid)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ defmodule Mobilizon.Events.Event do
|
||||||
alias Mobilizon.Addresses.Address
|
alias Mobilizon.Addresses.Address
|
||||||
|
|
||||||
alias Mobilizon.Events.{
|
alias Mobilizon.Events.{
|
||||||
Event,
|
|
||||||
EventOptions,
|
EventOptions,
|
||||||
EventStatus,
|
EventStatus,
|
||||||
EventVisibility,
|
EventVisibility,
|
||||||
|
@ -115,7 +114,7 @@ defmodule Mobilizon.Events.Event do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Event{} = event, attrs) do
|
def changeset(%__MODULE__{} = event, attrs) do
|
||||||
event
|
event
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> cast_embed(:options)
|
|> cast_embed(:options)
|
||||||
|
@ -124,7 +123,7 @@ defmodule Mobilizon.Events.Event do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec update_changeset(t, map) :: Ecto.Changeset.t()
|
@spec update_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def update_changeset(%Event{} = event, attrs) do
|
def update_changeset(%__MODULE__{} = event, attrs) do
|
||||||
event
|
event
|
||||||
|> Ecto.Changeset.cast(attrs, @update_attrs)
|
|> Ecto.Changeset.cast(attrs, @update_attrs)
|
||||||
|> cast_embed(:options)
|
|> cast_embed(:options)
|
||||||
|
@ -136,7 +135,7 @@ defmodule Mobilizon.Events.Event do
|
||||||
Checks whether an event can be managed.
|
Checks whether an event can be managed.
|
||||||
"""
|
"""
|
||||||
@spec can_be_managed_by(t, integer | String.t()) :: boolean
|
@spec can_be_managed_by(t, integer | String.t()) :: boolean
|
||||||
def can_be_managed_by(%Event{organizer_actor_id: organizer_actor_id}, actor_id)
|
def can_be_managed_by(%__MODULE__{organizer_actor_id: organizer_actor_id}, actor_id)
|
||||||
when organizer_actor_id == actor_id do
|
when organizer_actor_id == actor_id do
|
||||||
{:event_can_be_managed, true}
|
{:event_can_be_managed, true}
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,6 @@ defmodule Mobilizon.Events.EventOptions do
|
||||||
|
|
||||||
alias Mobilizon.Events.{
|
alias Mobilizon.Events.{
|
||||||
EventOffer,
|
EventOffer,
|
||||||
EventOptions,
|
|
||||||
EventParticipationCondition,
|
EventParticipationCondition,
|
||||||
CommentModeration
|
CommentModeration
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,7 @@ defmodule Mobilizon.Events.EventOptions do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%EventOptions{} = event_options, attrs) do
|
def changeset(%__MODULE__{} = event_options, attrs) do
|
||||||
cast(event_options, attrs, @attrs)
|
cast(event_options, attrs, @attrs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,6 @@ defmodule Mobilizon.Events.FeedToken do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Events.FeedToken
|
|
||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
|
@ -33,7 +32,7 @@ defmodule Mobilizon.Events.FeedToken do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%FeedToken{} = feed_token, attrs) do
|
def changeset(%__MODULE__{} = feed_token, attrs) do
|
||||||
feed_token
|
feed_token
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -10,7 +10,7 @@ defmodule Mobilizon.Events.Participant do
|
||||||
alias Mobilizon.Actors.Actor
|
alias Mobilizon.Actors.Actor
|
||||||
alias Mobilizon.Config
|
alias Mobilizon.Config
|
||||||
alias Mobilizon.Events
|
alias Mobilizon.Events
|
||||||
alias Mobilizon.Events.{Event, Participant, ParticipantRole}
|
alias Mobilizon.Events.{Event, ParticipantRole}
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
role: ParticipantRole.t(),
|
role: ParticipantRole.t(),
|
||||||
|
@ -41,7 +41,7 @@ defmodule Mobilizon.Events.Participant do
|
||||||
@spec is_not_only_organizer(integer | String.t(), integer | String.t()) :: boolean
|
@spec is_not_only_organizer(integer | String.t(), integer | String.t()) :: boolean
|
||||||
def is_not_only_organizer(event_id, actor_id) do
|
def is_not_only_organizer(event_id, actor_id) do
|
||||||
case Events.list_organizers_participants_for_event(event_id) do
|
case Events.list_organizers_participants_for_event(event_id) do
|
||||||
[%Participant{actor: %Actor{id: participant_actor_id}}] ->
|
[%__MODULE__{actor: %Actor{id: participant_actor_id}}] ->
|
||||||
participant_actor_id == actor_id
|
participant_actor_id == actor_id
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -51,7 +51,7 @@ defmodule Mobilizon.Events.Participant do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Participant{} = participant, attrs) do
|
def changeset(%__MODULE__{} = participant, attrs) do
|
||||||
participant
|
participant
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> ensure_url()
|
|> ensure_url()
|
||||||
|
@ -60,7 +60,7 @@ defmodule Mobilizon.Events.Participant do
|
||||||
|
|
||||||
# If there's a blank URL that's because we're doing the first insert
|
# If there's a blank URL that's because we're doing the first insert
|
||||||
@spec ensure_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
@spec ensure_url(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
||||||
defp ensure_url(%Ecto.Changeset{data: %Participant{url: nil}} = changeset) do
|
defp ensure_url(%Ecto.Changeset{data: %__MODULE__{url: nil}} = changeset) do
|
||||||
case fetch_change(changeset, :url) do
|
case fetch_change(changeset, :url) do
|
||||||
{:ok, _url} ->
|
{:ok, _url} ->
|
||||||
changeset
|
changeset
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Mobilizon.Events.Session do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Events.{Event, Session, Track}
|
alias Mobilizon.Events.{Event, Track}
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
audios_urls: String.t(),
|
audios_urls: String.t(),
|
||||||
|
@ -57,7 +57,7 @@ defmodule Mobilizon.Events.Session do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Session{} = session, attrs) do
|
def changeset(%__MODULE__{} = session, attrs) do
|
||||||
session
|
session
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -7,13 +7,13 @@ defmodule Mobilizon.Events.Tag do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Events.{Tag, TagRelation}
|
alias Mobilizon.Events.TagRelation
|
||||||
alias Mobilizon.Events.Tag.TitleSlug
|
alias Mobilizon.Events.Tag.TitleSlug
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
title: String.t(),
|
title: String.t(),
|
||||||
slug: TitleSlug.Type.t(),
|
slug: TitleSlug.Type.t(),
|
||||||
related_tags: [Tag.t()]
|
related_tags: [t]
|
||||||
}
|
}
|
||||||
|
|
||||||
@required_attrs [:title, :slug]
|
@required_attrs [:title, :slug]
|
||||||
|
@ -23,14 +23,14 @@ defmodule Mobilizon.Events.Tag do
|
||||||
field(:title, :string)
|
field(:title, :string)
|
||||||
field(:slug, TitleSlug.Type)
|
field(:slug, TitleSlug.Type)
|
||||||
|
|
||||||
many_to_many(:related_tags, Tag, join_through: TagRelation)
|
many_to_many(:related_tags, __MODULE__, join_through: TagRelation)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Tag{} = tag, attrs) do
|
def changeset(%__MODULE__{} = tag, attrs) do
|
||||||
tag
|
tag
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> TitleSlug.maybe_generate_slug()
|
|> TitleSlug.maybe_generate_slug()
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Mobilizon.Events.TagRelation do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Events.{Tag, TagRelation}
|
alias Mobilizon.Events.Tag
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
weight: integer,
|
weight: integer,
|
||||||
|
@ -29,7 +29,7 @@ defmodule Mobilizon.Events.TagRelation do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%TagRelation{} = tag, attrs) do
|
def changeset(%__MODULE__{} = tag, attrs) do
|
||||||
# Return if tag_id or link_id are not set because it will fail later otherwise
|
# Return if tag_id or link_id are not set because it will fail later otherwise
|
||||||
with %Ecto.Changeset{errors: [], changes: changes} = changeset <-
|
with %Ecto.Changeset{errors: [], changes: changes} = changeset <-
|
||||||
tag
|
tag
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Mobilizon.Events.Track do
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
alias Mobilizon.Events.{Track, Event, Session}
|
alias Mobilizon.Events.{Event, Session}
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
color: String.t(),
|
color: String.t(),
|
||||||
|
@ -34,7 +34,7 @@ defmodule Mobilizon.Events.Track do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t, map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%Track{} = track, attrs) do
|
def changeset(%__MODULE__{} = track, attrs) do
|
||||||
track
|
track
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -28,8 +28,8 @@ defmodule Mobilizon.Media.File do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(file, attrs) do
|
def changeset(%__MODULE__{} = file, attrs) do
|
||||||
file
|
file
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -23,8 +23,8 @@ defmodule Mobilizon.Media.Picture do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(picture, attrs) do
|
def changeset(%__MODULE__{} = picture, attrs) do
|
||||||
picture
|
picture
|
||||||
|> cast(attrs, [:actor_id])
|
|> cast(attrs, [:actor_id])
|
||||||
|> cast_embed(:file)
|
|> cast_embed(:file)
|
||||||
|
|
|
@ -30,8 +30,8 @@ defmodule Mobilizon.Reports.Note do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(note, attrs) do
|
def changeset(%__MODULE__{} = note, attrs) do
|
||||||
note
|
note
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
|
|
|
@ -50,16 +50,16 @@ defmodule Mobilizon.Reports.Report do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(report, attrs) do
|
def changeset(%__MODULE__{} = report, attrs) do
|
||||||
report
|
report
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|> validate_required(@required_attrs)
|
|> validate_required(@required_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec creation_changeset(Report.t(), map) :: Ecto.Changeset.t()
|
@spec creation_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def creation_changeset(report, attrs) do
|
def creation_changeset(%__MODULE__{} = report, attrs) do
|
||||||
report
|
report
|
||||||
|> changeset(attrs)
|
|> changeset(attrs)
|
||||||
|> put_assoc(:comments, attrs["comments"])
|
|> put_assoc(:comments, attrs["comments"])
|
||||||
|
|
|
@ -11,7 +11,7 @@ defmodule Mobilizon.Users.User do
|
||||||
alias Mobilizon.Crypto
|
alias Mobilizon.Crypto
|
||||||
alias Mobilizon.Events.FeedToken
|
alias Mobilizon.Events.FeedToken
|
||||||
alias Mobilizon.Service.EmailChecker
|
alias Mobilizon.Service.EmailChecker
|
||||||
alias Mobilizon.Users.{User, UserRole}
|
alias Mobilizon.Users.UserRole
|
||||||
|
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
email: String.t(),
|
email: String.t(),
|
||||||
|
@ -66,8 +66,8 @@ defmodule Mobilizon.Users.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec changeset(t | Ecto.Changeset.t(), map) :: Ecto.Changeset.t()
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def changeset(%User{} = user, attrs) do
|
def changeset(%__MODULE__{} = user, attrs) do
|
||||||
changeset =
|
changeset =
|
||||||
user
|
user
|
||||||
|> cast(attrs, @attrs)
|
|> cast(attrs, @attrs)
|
||||||
|
@ -84,8 +84,8 @@ defmodule Mobilizon.Users.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec registration_changeset(User.t(), map) :: Ecto.Changeset.t()
|
@spec registration_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def registration_changeset(%User{} = user, attrs) do
|
def registration_changeset(%__MODULE__{} = user, attrs) do
|
||||||
user
|
user
|
||||||
|> changeset(attrs)
|
|> changeset(attrs)
|
||||||
|> cast_assoc(:default_actor)
|
|> cast_assoc(:default_actor)
|
||||||
|
@ -99,14 +99,14 @@ defmodule Mobilizon.Users.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec send_password_reset_changeset(User.t(), map) :: Ecto.Changeset.t()
|
@spec send_password_reset_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def send_password_reset_changeset(%User{} = user, attrs) do
|
def send_password_reset_changeset(%__MODULE__{} = user, attrs) do
|
||||||
cast(user, attrs, [:reset_password_token, :reset_password_sent_at])
|
cast(user, attrs, [:reset_password_token, :reset_password_sent_at])
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec password_reset_changeset(User.t(), map) :: Ecto.Changeset.t()
|
@spec password_reset_changeset(t, map) :: Ecto.Changeset.t()
|
||||||
def password_reset_changeset(%User{} = user, attrs) do
|
def password_reset_changeset(%__MODULE__{} = user, attrs) do
|
||||||
user
|
user
|
||||||
|> cast(attrs, @password_reset_required_attrs)
|
|> cast(attrs, @password_reset_required_attrs)
|
||||||
|> validate_length(:password,
|
|> validate_length(:password,
|
||||||
|
@ -120,15 +120,15 @@ defmodule Mobilizon.Users.User do
|
||||||
@doc """
|
@doc """
|
||||||
Checks whether an user is confirmed.
|
Checks whether an user is confirmed.
|
||||||
"""
|
"""
|
||||||
@spec is_confirmed(User.t()) :: boolean
|
@spec is_confirmed(t) :: boolean
|
||||||
def is_confirmed(%User{confirmed_at: nil}), do: false
|
def is_confirmed(%__MODULE__{confirmed_at: nil}), do: false
|
||||||
def is_confirmed(%User{}), do: true
|
def is_confirmed(%__MODULE__{}), do: true
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns whether an user owns an actor.
|
Returns whether an user owns an actor.
|
||||||
"""
|
"""
|
||||||
@spec owns_actor(User.t(), integer | String.t()) :: {:is_owned, Actor.t() | nil}
|
@spec owns_actor(t, integer | String.t()) :: {:is_owned, Actor.t() | nil}
|
||||||
def owns_actor(%User{actors: actors}, actor_id) do
|
def owns_actor(%__MODULE__{actors: actors}, actor_id) do
|
||||||
user_actor = Enum.find(actors, fn actor -> "#{actor.id}" == "#{actor_id}" end)
|
user_actor = Enum.find(actors, fn actor -> "#{actor.id}" == "#{actor_id}" end)
|
||||||
|
|
||||||
{:is_owned, user_actor}
|
{:is_owned, user_actor}
|
||||||
|
|
Loading…
Reference in a new issue