From 289ba0396095033fe4951cde41650c96628fe1ab Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 14 Jan 2019 17:48:08 +0100 Subject: [PATCH] Remove address_type and rename phone to phone_address An event can indeed have several address types Signed-off-by: Thomas Citharel --- js/src/components/Event/Event.vue | 4 +-- js/src/graphql/event.ts | 10 +++---- lib/mobilizon/events/event.ex | 10 ++----- lib/mobilizon_web/schema.ex | 4 +-- lib/mobilizon_web/schema/actor.ex | 3 ++ lib/mobilizon_web/schema/actors/follower.ex | 3 ++ lib/mobilizon_web/schema/actors/group.ex | 3 ++ lib/mobilizon_web/schema/actors/member.ex | 3 ++ lib/mobilizon_web/schema/actors/person.ex | 3 ++ lib/mobilizon_web/schema/address.ex | 3 ++ lib/mobilizon_web/schema/comment.ex | 17 +++++++++++ lib/mobilizon_web/schema/event.ex | 30 ++++++++++++++++--- lib/mobilizon_web/schema/events/category.ex | 3 ++ .../schema/events/participant.ex | 4 +++ lib/mobilizon_web/schema/user.ex | 3 ++ .../20190114162055_remove_address_type.exs | 11 +++++++ .../resolvers/event_resolver_test.exs | 3 +- 17 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 priv/repo/migrations/20190114162055_remove_address_type.exs diff --git a/js/src/components/Event/Event.vue b/js/src/components/Event/Event.vue index 6fa6c9e7b..a7f443823 100644 --- a/js/src/components/Event/Event.vue +++ b/js/src/components/Event/Event.vue @@ -105,9 +105,9 @@ - + {{ event.physical_address.streetAddress }} - + Mobile diff --git a/js/src/graphql/event.ts b/js/src/graphql/event.ts index 444669892..14906976f 100644 --- a/js/src/graphql/event.ts +++ b/js/src/graphql/event.ts @@ -12,13 +12,12 @@ export const FETCH_EVENT = gql` ends_on, state, status, - public, + visibility, thumbnail, large_image, publish_at, - # address_type, # online_address, - # phone, + # phone_address, organizerActor { avatarUrl, preferredUsername, @@ -56,13 +55,12 @@ export const FETCH_EVENTS = gql` ends_on, state, status, - public, + visibility, thumbnail, large_image, publish_at, - # address_type, # online_address, - # phone, + # phone_address, organizerActor { avatarUrl, preferredUsername, diff --git a/lib/mobilizon/events/event.ex b/lib/mobilizon/events/event.ex index c93616e07..6f36bcc45 100644 --- a/lib/mobilizon/events/event.ex +++ b/lib/mobilizon/events/event.ex @@ -1,5 +1,4 @@ import EctoEnum -defenum(Mobilizon.Events.AddressTypeEnum, :address_type, [:physical, :url, :phone, :other]) defenum(Mobilizon.Events.EventVisibilityEnum, :event_visibility_type, [ :public, @@ -38,9 +37,8 @@ defmodule Mobilizon.Events.Event do field(:large_image, :string) field(:publish_at, Timex.Ecto.DateTimeWithTimezone) field(:uuid, Ecto.UUID, default: Ecto.UUID.generate()) - field(:address_type, Mobilizon.Events.AddressTypeEnum, default: :physical) field(:online_address, :string) - field(:phone, :string) + field(:phone_address, :string) 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") @@ -69,9 +67,8 @@ defmodule Mobilizon.Events.Event do :thumbnail, :large_image, :publish_at, - :address_type, :online_address, - :phone + :phone_address ]) |> cast_assoc(:tags) |> cast_assoc(:physical_address) @@ -82,8 +79,7 @@ defmodule Mobilizon.Events.Event do :organizer_actor_id, :category_id, :url, - :uuid, - :address_type + :uuid ]) end diff --git a/lib/mobilizon_web/schema.ex b/lib/mobilizon_web/schema.ex index f9d2021ca..afdac3809 100644 --- a/lib/mobilizon_web/schema.ex +++ b/lib/mobilizon_web/schema.ex @@ -4,7 +4,6 @@ defmodule MobilizonWeb.Schema do """ use Absinthe.Schema - import Absinthe.Resolution.Helpers, only: [dataloader: 1] alias Mobilizon.{Actors, Events} alias Mobilizon.Actors.{Actor, Follower, Member} alias Mobilizon.Events.{Event, Comment, Participant} @@ -200,9 +199,8 @@ defmodule MobilizonWeb.Schema do arg(:thumbnail, :string) arg(:large_image, :string) arg(:publish_at, :datetime) - arg(:address_type, non_null(:address_type)) arg(:online_address, :string) - arg(:phone, :string) + arg(:phone_address, :string) arg(:organizer_actor_username, non_null(:string)) arg(:category, non_null(:string)) diff --git a/lib/mobilizon_web/schema/actor.ex b/lib/mobilizon_web/schema/actor.ex index d93ac5041..c3a051094 100644 --- a/lib/mobilizon_web/schema/actor.ex +++ b/lib/mobilizon_web/schema/actor.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.ActorInterface do + @moduledoc """ + Schema representation for Actor + """ use Absinthe.Schema.Notation import Absinthe.Resolution.Helpers, only: [dataloader: 1] alias Mobilizon.Actors.Actor diff --git a/lib/mobilizon_web/schema/actors/follower.ex b/lib/mobilizon_web/schema/actors/follower.ex index 163deef79..50f3cb3ae 100644 --- a/lib/mobilizon_web/schema/actors/follower.ex +++ b/lib/mobilizon_web/schema/actors/follower.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.Actors.FollowerType do + @moduledoc """ + Schema representation for Follower + """ use Absinthe.Schema.Notation @desc """ diff --git a/lib/mobilizon_web/schema/actors/group.ex b/lib/mobilizon_web/schema/actors/group.ex index 60a248ef6..1dab34591 100644 --- a/lib/mobilizon_web/schema/actors/group.ex +++ b/lib/mobilizon_web/schema/actors/group.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.Actors.GroupType do + @moduledoc """ + Schema representation for Group + """ use Absinthe.Schema.Notation import Absinthe.Resolution.Helpers, only: [dataloader: 1] import_types(MobilizonWeb.Schema.Actors.MemberType) diff --git a/lib/mobilizon_web/schema/actors/member.ex b/lib/mobilizon_web/schema/actors/member.ex index 97aef0491..26848f914 100644 --- a/lib/mobilizon_web/schema/actors/member.ex +++ b/lib/mobilizon_web/schema/actors/member.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.Actors.MemberType do + @moduledoc """ + Schema representation for Member + """ use Absinthe.Schema.Notation @desc """ diff --git a/lib/mobilizon_web/schema/actors/person.ex b/lib/mobilizon_web/schema/actors/person.ex index 2ddb39120..46b11dece 100644 --- a/lib/mobilizon_web/schema/actors/person.ex +++ b/lib/mobilizon_web/schema/actors/person.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do + @moduledoc """ + Schema representation for Person + """ use Absinthe.Schema.Notation import Absinthe.Resolution.Helpers, only: [dataloader: 1] import_types(MobilizonWeb.Schema.UserType) diff --git a/lib/mobilizon_web/schema/address.ex b/lib/mobilizon_web/schema/address.ex index 476575a7e..d3b560a16 100644 --- a/lib/mobilizon_web/schema/address.ex +++ b/lib/mobilizon_web/schema/address.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.AddressType do + @moduledoc """ + Schema representation for Address + """ use Absinthe.Schema.Notation object :physical_address do diff --git a/lib/mobilizon_web/schema/comment.ex b/lib/mobilizon_web/schema/comment.ex index 3ac004702..0768ad06e 100644 --- a/lib/mobilizon_web/schema/comment.ex +++ b/lib/mobilizon_web/schema/comment.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.CommentType do + @moduledoc """ + Schema representation for Comment + """ use Absinthe.Schema.Notation @desc "A comment" @@ -6,9 +9,23 @@ defmodule MobilizonWeb.Schema.CommentType do field(:uuid, :uuid) field(:url, :string) field(:local, :boolean) + field(:visibility, :comment_visibility) field(:text, :string) field(:primaryLanguage, :string) field(:replies, list_of(:comment)) field(:threadLanguages, non_null(list_of(:string))) end + + @desc "The list of visibility options for a comment" + enum :comment_visibility do + value(:public, description: "Publically listed and federated. Can be shared.") + value(:unlisted, description: "Visible only to people with the link - or invited") + + value(:private, + description: "Visible only to people members of the group or followers of the person" + ) + + value(:moderated, description: "Visible only after a moderator accepted") + value(:invite, description: "visible only to people invited") + end end diff --git a/lib/mobilizon_web/schema/event.ex b/lib/mobilizon_web/schema/event.ex index 0ed60c52f..2ff2192c3 100644 --- a/lib/mobilizon_web/schema/event.ex +++ b/lib/mobilizon_web/schema/event.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.EventType do + @moduledoc """ + Schema representation for Event + """ use Absinthe.Schema.Notation import Absinthe.Resolution.Helpers, only: [dataloader: 1] import_types(MobilizonWeb.Schema.AddressType) @@ -14,9 +17,8 @@ defmodule MobilizonWeb.Schema.EventType do field(:description, :string, description: "The event's description") field(:begins_on, :datetime, description: "Datetime for when the event begins") field(:ends_on, :datetime, description: "Datetime for when the event ends") - field(:state, :integer, description: "State of the event") - field(:status, :integer, description: "Status of the event") - field(:public, :boolean, description: "Whether the event is public or not") + field(:status, :event_status, description: "Status of the event") + field(:visibility, :event_visibility, description: "The event's visibility") # TODO replace me with picture object field(:thumbnail, :string, description: "A thumbnail picture for the event") # TODO replace me with banner @@ -36,7 +38,7 @@ defmodule MobilizonWeb.Schema.EventType do field(:category, :category, description: "The event's category") field(:participants, list_of(:participant), - resolve: &Resolvers.Event.list_participants_for_event/3, + resolve: &MobilizonWeb.Resolvers.Event.list_participants_for_event/3, description: "The event's participants" ) @@ -46,4 +48,24 @@ defmodule MobilizonWeb.Schema.EventType do field(:updated_at, :datetime, description: "When the event was last updated") field(:created_at, :datetime, description: "When the event was created") end + + @desc "The list of visibility options for an event" + enum :event_visibility do + value(:public, description: "Publically listed and federated. Can be shared.") + value(:unlisted, description: "Visible only to people with the link - or invited") + + value(:private, + description: "Visible only to people members of the group or followers of the person" + ) + + value(:moderated, description: "Visible only after a moderator accepted") + value(:invite, description: "visible only to people invited") + end + + @desc "The list of possible options for the event's status" + enum :event_status do + value(:tentative, description: "The event is tentative") + value(:confirmed, description: "The event is confirmed") + value(:cancelled, description: "The event is cancelled") + end end diff --git a/lib/mobilizon_web/schema/events/category.ex b/lib/mobilizon_web/schema/events/category.ex index 24f31edb7..25e263fe6 100644 --- a/lib/mobilizon_web/schema/events/category.ex +++ b/lib/mobilizon_web/schema/events/category.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.Events.CategoryType do + @moduledoc """ + Schema representation for Category + """ use Absinthe.Schema.Notation @desc "A category" diff --git a/lib/mobilizon_web/schema/events/participant.ex b/lib/mobilizon_web/schema/events/participant.ex index 54df1f753..47a6b36b9 100644 --- a/lib/mobilizon_web/schema/events/participant.ex +++ b/lib/mobilizon_web/schema/events/participant.ex @@ -1,5 +1,9 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do + @moduledoc """ + Schema representation for Participant + """ use Absinthe.Schema.Notation + import Absinthe.Resolution.Helpers, only: [dataloader: 1] @desc "Represents a participant to an event" object :participant do diff --git a/lib/mobilizon_web/schema/user.ex b/lib/mobilizon_web/schema/user.ex index d908c4e7e..b1106de93 100644 --- a/lib/mobilizon_web/schema/user.ex +++ b/lib/mobilizon_web/schema/user.ex @@ -1,4 +1,7 @@ defmodule MobilizonWeb.Schema.UserType do + @moduledoc """ + Schema representation for User + """ use Absinthe.Schema.Notation @desc "A local user of Mobilizon" diff --git a/priv/repo/migrations/20190114162055_remove_address_type.exs b/priv/repo/migrations/20190114162055_remove_address_type.exs new file mode 100644 index 000000000..ead2109fe --- /dev/null +++ b/priv/repo/migrations/20190114162055_remove_address_type.exs @@ -0,0 +1,11 @@ +defmodule Mobilizon.Repo.Migrations.RemoveAddressType do + use Ecto.Migration + + def up do + alter table(:events) do + remove(:address_type) + end + execute "DROP TYPE address_type" + rename table(:events), :phone, to: :phone_address + end +end diff --git a/test/mobilizon_web/resolvers/event_resolver_test.exs b/test/mobilizon_web/resolvers/event_resolver_test.exs index e82a1e10b..80a3ad207 100644 --- a/test/mobilizon_web/resolvers/event_resolver_test.exs +++ b/test/mobilizon_web/resolvers/event_resolver_test.exs @@ -118,8 +118,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do description: "it will be fine", begins_on: "#{DateTime.utc_now() |> DateTime.to_iso8601()}", organizer_actor_username: "#{actor.preferred_username}", - category: "#{category.title}", - address_type: #{"OTHER"} + category: "#{category.title}" ) { title, uuid