Send email notifications when a participation is approved/rejected
Also handles participant status :rejected instead of deleting the participation Closes #164 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
defmodule Mobilizon.Storage.Repo.Migrations.RenamePostgresTypes do
|
||||
use Ecto.Migration
|
||||
alias Mobilizon.Actors.{ActorVisibility, MemberRole}
|
||||
|
||||
alias Mobilizon.Events.{
|
||||
CommentVisibility,
|
||||
JoinOptions,
|
||||
EventStatus,
|
||||
EventVisibility,
|
||||
ParticipantRole
|
||||
}
|
||||
|
||||
alias Mobilizon.Users.UserRole
|
||||
|
||||
@types %{
|
||||
"actor_visibility_type" => ActorVisibility.type(),
|
||||
"comment_visibility_type" => CommentVisibility.type(),
|
||||
"event_join_options_type" => JoinOptions.type(),
|
||||
"event_status_type" => EventStatus.type(),
|
||||
"event_visibility_type" => EventVisibility.type(),
|
||||
"member_role_type" => MemberRole.type(),
|
||||
"participant_role_type" => ParticipantRole.type(),
|
||||
"user_role_type" => UserRole.type()
|
||||
}
|
||||
|
||||
def up do
|
||||
Enum.each(@types, fn {k, v} -> rename_type(k, v) end)
|
||||
end
|
||||
|
||||
def down do
|
||||
Enum.each(@types, fn {k, v} -> rename_type(v, k) end)
|
||||
end
|
||||
|
||||
defp rename_type(old_type_name, new_type_name) do
|
||||
with %Postgrex.Result{columns: ["exists"], rows: [[true]]} <-
|
||||
Ecto.Adapters.SQL.query!(
|
||||
Mobilizon.Storage.Repo,
|
||||
"select exists (select 1 from pg_type where typname = '#{
|
||||
old_type_name |> remove_schema
|
||||
}' and typnamespace = (select oid from pg_namespace where nspname = 'public'))"
|
||||
) do
|
||||
Ecto.Migration.execute(
|
||||
"ALTER TYPE #{old_type_name |> remove_schema} RENAME TO #{new_type_name |> remove_schema}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# We don't want the schema: public.actor_visibility => actor_visibility
|
||||
def remove_schema(schema) when is_atom(schema), do: remove_schema(to_string(schema))
|
||||
def remove_schema("public." <> schema), do: schema
|
||||
def remove_schema(schema), do: schema
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
defmodule Mobilizon.Storage.Repo.Migrations.AddRejectedToParticipantRole do
|
||||
use Ecto.Migration
|
||||
alias Mobilizon.Storage.Repo
|
||||
alias Mobilizon.Events.Participant
|
||||
alias Mobilizon.Events.ParticipantRole
|
||||
import Ecto.Query
|
||||
|
||||
@disable_ddl_transaction true
|
||||
|
||||
def up do
|
||||
Ecto.Migration.execute(
|
||||
"ALTER TYPE #{ParticipantRole.type()} ADD VALUE IF NOT EXISTS 'rejected'"
|
||||
)
|
||||
end
|
||||
|
||||
def down do
|
||||
Participant
|
||||
|> where(role: "rejected")
|
||||
|> Repo.delete_all()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user