Sha256: 35229cfeda3e95602de7b4c6f93b5083ae00e854ab2e094ee03f8538ddf9cf1d

Contents?: true

Size: 969 Bytes

Versions: 2

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Admin
      # Base class to be inherited by other forms that have roles
      # in the Votings space
      class VotingRoleForm < Decidim::Form
        attribute :name, String
        attribute :email, String
        attribute :user_id, Integer
        attribute :existing_user, Boolean, default: false

        validates :email, presence: true, format: { with: ::Devise.email_regexp }, unless: ->(form) { form.existing_user }
        validates :name, presence: true, format: { with: UserBaseEntity::REGEXP_NAME }, unless: ->(form) { form.existing_user }
        validates :user, presence: true, if: ->(form) { form.existing_user }

        def map_model(model)
          self.user_id = model.decidim_user_id
          self.existing_user = user_id.present?
        end

        def user
          @user ||= current_organization.users.find_by(id: user_id)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-elections-0.26.8 app/forms/decidim/votings/admin/voting_role_form.rb
decidim-elections-0.27.4 app/forms/decidim/votings/admin/voting_role_form.rb