🔍 Implement basic event visibility
See https://framagit.org/framasoft/mobilizon/wikis/spec/Event#visibility Also brings support for event status (tentative/confirmed/cancelled) Closes #56 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
import EctoEnum
|
||||
|
||||
defenum(Mobilizon.Events.CommentVisibilityEnum, :comment_visibility_type, [
|
||||
:public,
|
||||
:local,
|
||||
:group,
|
||||
:unlisted,
|
||||
:moderated,
|
||||
:private
|
||||
])
|
||||
|
||||
defmodule Mobilizon.Events.Comment do
|
||||
@moduledoc """
|
||||
An actor comment (for instance on an event or on a group)
|
||||
@@ -14,6 +25,7 @@ defmodule Mobilizon.Events.Comment do
|
||||
field(:text, :string)
|
||||
field(:url, :string)
|
||||
field(:local, :boolean, default: true)
|
||||
field(:visibility, :integer)
|
||||
field(:uuid, Ecto.UUID)
|
||||
belongs_to(:actor, Actor, foreign_key: :actor_id)
|
||||
belongs_to(:attributed_to, Actor, foreign_key: :attributed_to_id)
|
||||
@@ -38,7 +50,7 @@ defmodule Mobilizon.Events.Comment do
|
||||
else: "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
|
||||
comment
|
||||
|> cast(attrs, [
|
||||
|> Ecto.Changeset.cast(attrs, [
|
||||
:url,
|
||||
:text,
|
||||
:actor_id,
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
import EctoEnum
|
||||
defenum(AddressTypeEnum, :address_type, [:physical, :url, :phone, :other])
|
||||
defenum(Mobilizon.Events.AddressTypeEnum, :address_type, [:physical, :url, :phone, :other])
|
||||
|
||||
defenum(Mobilizon.Events.EventVisibilityEnum, :event_visibility_type, [
|
||||
:public,
|
||||
:unlisted,
|
||||
:private,
|
||||
:moderated,
|
||||
:invite
|
||||
])
|
||||
|
||||
defenum(Mobilizon.Events.EventStatusEnum, :event_status_type, [
|
||||
:tentative,
|
||||
:confirmed,
|
||||
:cancelled
|
||||
])
|
||||
|
||||
defmodule Mobilizon.Events.Event do
|
||||
@moduledoc """
|
||||
@@ -18,17 +32,13 @@ defmodule Mobilizon.Events.Event do
|
||||
field(:description, :string)
|
||||
field(:ends_on, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:title, :string)
|
||||
# ???
|
||||
field(:state, :integer, default: 0)
|
||||
# Event status: TENTATIVE 1, CONFIRMED 2, CANCELLED 3
|
||||
field(:status, :integer, default: 0)
|
||||
# If the event is public or private
|
||||
field(:public, :boolean, default: true)
|
||||
field(:status, Mobilizon.Events.EventStatusEnum, default: :confirmed)
|
||||
field(:visibility, Mobilizon.Events.EventVisibilityEnum, default: :public)
|
||||
field(:thumbnail, :string)
|
||||
field(:large_image, :string)
|
||||
field(:publish_at, Timex.Ecto.DateTimeWithTimezone)
|
||||
field(:uuid, Ecto.UUID, default: Ecto.UUID.generate())
|
||||
field(:address_type, AddressTypeEnum, default: :physical)
|
||||
field(:address_type, Mobilizon.Events.AddressTypeEnum, default: :physical)
|
||||
field(:online_address, :string)
|
||||
field(:phone, :string)
|
||||
belongs_to(:organizer_actor, Actor, foreign_key: :organizer_actor_id)
|
||||
@@ -54,9 +64,8 @@ defmodule Mobilizon.Events.Event do
|
||||
:ends_on,
|
||||
:organizer_actor_id,
|
||||
:category_id,
|
||||
:state,
|
||||
:status,
|
||||
:public,
|
||||
:visibility,
|
||||
:thumbnail,
|
||||
:large_image,
|
||||
:publish_at,
|
||||
|
||||
@@ -50,7 +50,7 @@ defmodule Mobilizon.Events do
|
||||
from(
|
||||
e in Event,
|
||||
select: count(e.id),
|
||||
where: e.local == ^true
|
||||
where: e.local == ^true and e.visibility == ^:public
|
||||
)
|
||||
)
|
||||
end
|
||||
@@ -80,7 +80,7 @@ defmodule Mobilizon.Events do
|
||||
e in Event,
|
||||
join: a in Address,
|
||||
on: a.id == e.physical_address_id,
|
||||
where: st_dwithin_in_meters(^point, a.geom, ^radius),
|
||||
where: e.visibility == ^:public and st_dwithin_in_meters(^point, a.geom, ^radius),
|
||||
preload: :organizer_actor
|
||||
)
|
||||
)
|
||||
@@ -130,17 +130,20 @@ defmodule Mobilizon.Events do
|
||||
"""
|
||||
@spec get_event_full_by_uuid(String.t()) :: Event.t()
|
||||
def get_event_full_by_uuid(uuid) do
|
||||
event = Repo.get_by(Event, uuid: uuid)
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
from(
|
||||
e in Event,
|
||||
where: e.uuid == ^uuid and e.visibility in [^:public, ^:unlisted],
|
||||
preload: [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
]
|
||||
)
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -166,7 +169,7 @@ defmodule Mobilizon.Events do
|
||||
def get_event_full_by_url(url) do
|
||||
case Repo.one(
|
||||
from(e in Event,
|
||||
where: e.url == ^url,
|
||||
where: e.url == ^url and e.visibility in [^:public, ^:unlisted],
|
||||
preload: [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
@@ -187,17 +190,20 @@ defmodule Mobilizon.Events do
|
||||
Gets an event by it's URL
|
||||
"""
|
||||
def get_event_full_by_url!(url) do
|
||||
event = Repo.get_by!(Event, url: url)
|
||||
|
||||
Repo.preload(event, [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
])
|
||||
Repo.one(
|
||||
from(e in Event,
|
||||
where: e.url == ^url and e.visibility in [^:public, ^:unlisted],
|
||||
preload: [
|
||||
:organizer_actor,
|
||||
:category,
|
||||
:sessions,
|
||||
:tracks,
|
||||
:tags,
|
||||
:participants,
|
||||
:physical_address
|
||||
]
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
@@ -211,7 +217,11 @@ defmodule Mobilizon.Events do
|
||||
"""
|
||||
def list_events(page \\ nil, limit \\ nil) do
|
||||
query =
|
||||
from(e in Event, preload: [:organizer_actor])
|
||||
from(
|
||||
e in Event,
|
||||
where: e.visibility == ^:public,
|
||||
preload: [:organizer_actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|
||||
Repo.all(query)
|
||||
@@ -228,7 +238,7 @@ defmodule Mobilizon.Events do
|
||||
|
||||
query =
|
||||
from(e in Event,
|
||||
where: ilike(e.title, ^like_sanitize(name)),
|
||||
where: e.visibility == ^:public and ilike(e.title, ^like_sanitize(name)),
|
||||
preload: [:organizer_actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
|
||||
Reference in New Issue
Block a user