logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20200520155351_add_recipients_contain_blocked_domains_function.exs (1022B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.AddRecipientsContainBlockedDomainsFunction do
  5. use Ecto.Migration
  6. @disable_ddl_transaction true
  7. def up do
  8. statement = """
  9. CREATE OR REPLACE FUNCTION recipients_contain_blocked_domains(recipients varchar[], blocked_domains varchar[]) RETURNS boolean AS $$
  10. DECLARE
  11. recipient_domain varchar;
  12. recipient varchar;
  13. BEGIN
  14. FOREACH recipient IN ARRAY recipients LOOP
  15. recipient_domain = split_part(recipient, '/', 3)::varchar;
  16. IF recipient_domain = ANY(blocked_domains) THEN
  17. RETURN TRUE;
  18. END IF;
  19. END LOOP;
  20. RETURN FALSE;
  21. END;
  22. $$ LANGUAGE plpgsql;
  23. """
  24. execute(statement)
  25. end
  26. def down do
  27. execute(
  28. "drop function if exists recipients_contain_blocked_domains(recipients varchar[], blocked_domains varchar[])"
  29. )
  30. end
  31. end