2018-07-04 14:29:17 +02:00
|
|
|
import EctoEnum
|
2019-01-14 15:56:07 +01:00
|
|
|
|
|
|
|
defenum(Mobilizon.Events.EventVisibilityEnum, :event_visibility_type, [
|
|
|
|
:public,
|
|
|
|
:unlisted,
|
2019-02-01 12:33:15 +01:00
|
|
|
:restricted,
|
|
|
|
:private
|
|
|
|
])
|
|
|
|
|
|
|
|
defenum(Mobilizon.Events.JoinOptionsEnum, :event_join_options_type, [
|
|
|
|
:free,
|
|
|
|
:restricted,
|
2019-01-14 15:56:07 +01:00
|
|
|
:invite
|
|
|
|
])
|
|
|
|
|
|
|
|
defenum(Mobilizon.Events.EventStatusEnum, :event_status_type, [
|
|
|
|
:tentative,
|
|
|
|
:confirmed,
|
|
|
|
:cancelled
|
|
|
|
])
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2019-02-22 16:54:01 +01:00
|
|
|
defenum(Mobilizon.Event.EventCategoryEnum, :event_category_type, [
|
|
|
|
:business,
|
|
|
|
:conference,
|
|
|
|
:birthday,
|
|
|
|
:demonstration,
|
|
|
|
:meeting
|
|
|
|
])
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Events.Event do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Represents an event
|
|
|
|
"""
|
2017-12-08 09:58:14 +01:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2019-02-22 16:54:01 +01:00
|
|
|
alias Mobilizon.Events.{Event, Participant, Tag, Session, Track}
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Addresses.Address
|
2017-12-08 09:58:14 +01:00
|
|
|
|
|
|
|
schema "events" do
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:url, :string)
|
|
|
|
field(:local, :boolean, default: true)
|
2019-02-14 14:19:55 +01:00
|
|
|
field(:begins_on, :utc_datetime)
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:description, :string)
|
2019-02-14 14:19:55 +01:00
|
|
|
field(:ends_on, :utc_datetime)
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:title, :string)
|
2019-01-14 15:56:07 +01:00
|
|
|
field(:status, Mobilizon.Events.EventStatusEnum, default: :confirmed)
|
|
|
|
field(:visibility, Mobilizon.Events.EventVisibilityEnum, default: :public)
|
2019-02-01 12:33:15 +01:00
|
|
|
field(:join_options, Mobilizon.Events.JoinOptionsEnum, default: :free)
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:thumbnail, :string)
|
|
|
|
field(:large_image, :string)
|
2019-02-14 14:19:55 +01:00
|
|
|
field(:publish_at, :utc_datetime)
|
2018-07-27 10:45:35 +02:00
|
|
|
field(:uuid, Ecto.UUID, default: Ecto.UUID.generate())
|
|
|
|
field(:online_address, :string)
|
2019-01-14 17:48:08 +01:00
|
|
|
field(:phone_address, :string)
|
2019-02-22 16:54:01 +01:00
|
|
|
field(:category, :string)
|
2018-07-27 10:45:35 +02:00
|
|
|
belongs_to(:organizer_actor, Actor, foreign_key: :organizer_actor_id)
|
|
|
|
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
|
|
|
many_to_many(:tags, Tag, join_through: "events_tags")
|
|
|
|
many_to_many(:participants, Actor, join_through: Participant)
|
|
|
|
has_many(:tracks, Track)
|
|
|
|
has_many(:sessions, Session)
|
|
|
|
belongs_to(:physical_address, Address)
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-05-17 11:32:23 +02:00
|
|
|
timestamps(type: :utc_datetime)
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(%Event{} = event, attrs) do
|
2018-06-14 17:25:55 +02:00
|
|
|
event
|
2018-07-04 14:29:17 +02:00
|
|
|
|> Ecto.Changeset.cast(attrs, [
|
|
|
|
:title,
|
|
|
|
:description,
|
|
|
|
:url,
|
|
|
|
:begins_on,
|
|
|
|
:ends_on,
|
|
|
|
:organizer_actor_id,
|
2019-02-22 16:54:01 +01:00
|
|
|
:category,
|
2018-07-04 14:29:17 +02:00
|
|
|
:status,
|
2019-01-14 15:56:07 +01:00
|
|
|
:visibility,
|
2018-07-04 14:29:17 +02:00
|
|
|
:thumbnail,
|
|
|
|
:large_image,
|
|
|
|
:publish_at,
|
|
|
|
:online_address,
|
2019-01-21 15:08:22 +01:00
|
|
|
:phone_address,
|
|
|
|
:uuid
|
2018-07-27 10:45:35 +02:00
|
|
|
])
|
2018-01-15 12:17:34 +01:00
|
|
|
|> cast_assoc(:tags)
|
2018-07-04 14:29:17 +02:00
|
|
|
|> cast_assoc(:physical_address)
|
2018-07-27 10:45:35 +02:00
|
|
|
|> validate_required([
|
|
|
|
:title,
|
|
|
|
:begins_on,
|
|
|
|
:organizer_actor_id,
|
2019-02-22 16:54:01 +01:00
|
|
|
:category,
|
2018-07-27 10:45:35 +02:00
|
|
|
:url,
|
2019-01-14 17:48:08 +01:00
|
|
|
:uuid
|
2018-07-27 10:45:35 +02:00
|
|
|
])
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
2019-01-25 17:06:57 +01:00
|
|
|
|
|
|
|
def can_event_be_managed_by(%Event{organizer_actor_id: organizer_actor_id}, actor_id)
|
|
|
|
when organizer_actor_id == actor_id do
|
|
|
|
{:event_can_be_managed, true}
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_event_be_managed_by(_event, _actor) do
|
|
|
|
{:event_can_be_managed, false}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|