From f6611e8eb5a7e12dc0dc0c216b598e04144e07c6 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 1 Sep 2023 18:16:06 +0200 Subject: [PATCH] feat(back): add admin setting to disable external event feature Signed-off-by: Thomas Citharel --- config/config.exs | 5 ++++- js/src/graphql/config.ts | 2 ++ js/src/types/config.model.ts | 1 + js/src/views/Event/EditView.vue | 6 +++++- lib/graphql/resolvers/config.ex | 1 + lib/graphql/resolvers/event.ex | 27 +++++++++++++++++++++++++++ lib/graphql/schema/config.ex | 4 ++++ lib/mobilizon/config.ex | 4 ++++ 8 files changed, 48 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index d2a0f9214..8cb7c203a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -41,7 +41,10 @@ config :mobilizon, :instance, email_reply_to: "noreply@localhost" config :mobilizon, :groups, enabled: true -config :mobilizon, :events, creation: true + +config :mobilizon, :events, + creation: true, + external: true config :mobilizon, :restrictions, only_admin_can_create_groups: false config :mobilizon, :restrictions, only_groups_can_create_events: false diff --git a/js/src/graphql/config.ts b/js/src/graphql/config.ts index 1022b7845..b7e4c7ba3 100644 --- a/js/src/graphql/config.ts +++ b/js/src/graphql/config.ts @@ -72,6 +72,7 @@ export const CONFIG = gql` features { groups eventCreation + eventExternal antispam } restrictions { @@ -370,6 +371,7 @@ export const FEATURES = gql` features { groups eventCreation + eventExternal antispam } } diff --git a/js/src/types/config.model.ts b/js/src/types/config.model.ts index 8548fb13d..e34c39c0a 100644 --- a/js/src/types/config.model.ts +++ b/js/src/types/config.model.ts @@ -96,6 +96,7 @@ export interface IConfig { timezones: string[]; features: { eventCreation: boolean; + eventExternal: boolean; groups: boolean; antispam: boolean; }; diff --git a/js/src/views/Event/EditView.vue b/js/src/views/Event/EditView.vue index 44cd754b5..a83fb61b3 100644 --- a/js/src/views/Event/EditView.vue +++ b/js/src/views/Event/EditView.vue @@ -246,7 +246,10 @@ --> - + {{ t("I want to manage the registration with an external provider") @@ -260,6 +263,7 @@ type="url" v-model="event.externalParticipationUrl" :placeholder="t('External provider URL')" + required /> diff --git a/lib/graphql/resolvers/config.ex b/lib/graphql/resolvers/config.ex index 1241872c3..b66afd1a5 100644 --- a/lib/graphql/resolvers/config.ex +++ b/lib/graphql/resolvers/config.ex @@ -145,6 +145,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do features: %{ groups: Config.instance_group_feature_enabled?(), event_creation: Config.instance_event_creation_enabled?(), + event_external: Config.instance_event_external_enabled?(), antispam: AntiSpam.service().ready?() }, restrictions: %{ diff --git a/lib/graphql/resolvers/event.ex b/lib/graphql/resolvers/event.ex index aaf18ef8c..16a86aa49 100644 --- a/lib/graphql/resolvers/event.ex +++ b/lib/graphql/resolvers/event.ex @@ -254,6 +254,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do with {:is_owned, %Actor{} = organizer_actor} <- User.owns_actor(user, organizer_actor_id), {:can_create_event, true} <- can_create_event(args), + {:event_external, true} <- edit_event_external_checker(args), {:organizer_group_member, true} <- {:organizer_group_member, is_organizer_group_member?(args)}, args_with_organizer <- @@ -281,6 +282,13 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do "Only groups can create events" )} + {:event_external, false} -> + {:error, + dgettext( + "errors", + "Providing external registration is not allowed" + )} + {:organizer_group_member, false} -> {:error, dgettext( @@ -322,6 +330,17 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do end end + @spec edit_event_external_checker(map()) :: {:event_external, boolean()} + defp edit_event_external_checker(args) do + if Config.instance_event_external_enabled?() do + {:event_external, true} + else + {:event_external, + Map.get(args, :join_options) != :external and + is_nil(Map.get(args, :external_participation_url))} + end + end + @doc """ Update an event """ @@ -340,6 +359,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do args <- extract_timezone(args, user.id), {:event_can_be_managed, true} <- {:event_can_be_managed, can_event_be_updated_by?(event, actor)}, + {:event_external, true} <- edit_event_external_checker(args), {:ok, %Activity{data: %{"object" => %{"type" => "Event"}}}, %Event{} = event} <- API.Events.update_event(args, event) do {:ok, event} @@ -351,6 +371,13 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do "This profile doesn't have permission to update an event on behalf of this group" )} + {:event_external, false} -> + {:error, + dgettext( + "errors", + "Providing external registration is not allowed" + )} + {:error, :event_not_found} -> {:error, dgettext("errors", "Event not found")} diff --git a/lib/graphql/schema/config.ex b/lib/graphql/schema/config.ex index cc42f1b1a..59579a6e3 100644 --- a/lib/graphql/schema/config.ex +++ b/lib/graphql/schema/config.ex @@ -314,6 +314,10 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do description: "Whether event creation is allowed on this instance" ) + field(:event_external, :boolean, + description: "Whether redirecting to external providers is authorized in event edition" + ) + field(:antispam, :boolean, description: "Whether anti-spam is activated on this instance") end diff --git a/lib/mobilizon/config.ex b/lib/mobilizon/config.ex index e27d7c9a2..92a29544e 100644 --- a/lib/mobilizon/config.ex +++ b/lib/mobilizon/config.ex @@ -357,6 +357,10 @@ defmodule Mobilizon.Config do def instance_event_creation_enabled?, do: :mobilizon |> Application.get_env(:events) |> Keyword.get(:creation) + @spec instance_event_external_enabled? :: boolean + def instance_event_external_enabled?, + do: :mobilizon |> Application.get_env(:events) |> Keyword.get(:external) + @spec instance_export_formats :: %{event_participants: list(String.t())} def instance_export_formats do %{