Sha256: 2a466f921b885ddfd3dfd6e011e57d5bcc210fa53913b091a321a4681ec5f885

Contents?: true

Size: 976 Bytes

Versions: 7

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This form holds the data for the invitations system.
  class InvitationsForm < Form
    mimic :invitations

    attribute :email_1, String
    attribute :email_2, String
    attribute :email_3, String
    attribute :email_4, String
    attribute :email_5, String
    attribute :email_6, String
    attribute :custom_text, String

    validates :email_1,
              :email_2,
              :email_3,
              :email_4,
              :email_5,
              :email_6,
              "valid_email_2/email": true,
              allow_blank: true
    validates :emails, presence: true

    def emails
      [email_1, email_2, email_3, email_4, email_5, email_6].uniq.select(&:present?)
    end

    def clean_emails
      existing_emails = Decidim::User
                        .where(organization: current_organization, email: emails)
                        .pluck(:email)
      emails - existing_emails
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.14.4 app/forms/decidim/invitations_form.rb
decidim-core-0.14.3 app/forms/decidim/invitations_form.rb
decidim-core-0.14.2 app/forms/decidim/invitations_form.rb
decidim-core-0.14.1 app/forms/decidim/invitations_form.rb
decidim-core-0.13.1 app/forms/decidim/invitations_form.rb
decidim-core-0.13.0 app/forms/decidim/invitations_form.rb
decidim-core-0.13.0.pre1 app/forms/decidim/invitations_form.rb