Sha256: 1ba6c7ff372f8675395cbb838b390e18457f0e819e516ea10139325f3dcb3bd3

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      # A form object used to create a Delegation
      #
      class DelegationForm < Form
        mimic :delegation

        attribute :granter_id, Integer
        attribute :grantee_id, Integer

        attribute :granter_email, String
        attribute :grantee_email, String

        validate :granter_exists
        validate :grantee_exists

        def granter
          User.find_by(id: granter_id) || User.find_by(email: granter_email)
        end

        def grantee
          User.find_by(id: grantee_id) || User.find_by(email: grantee_email)
        end

        private

        def granter_exists
          return if granter.present?

          errors.add :granter_email, I18n.t("decidim.action_delegator.admin.delegations.granter_missing")
        end

        def grantee_exists
          return if grantee.present?

          errors.add :grantee_email, I18n.t("decidim.action_delegator.admin.delegations.grantee_missing")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/forms/decidim/action_delegator/admin/delegation_form.rb
decidim-action_delegator-0.7.2 app/forms/decidim/action_delegator/admin/delegation_form.rb
decidim-action_delegator-0.7.1 app/forms/decidim/action_delegator/admin/delegation_form.rb
decidim-action_delegator-0.7.0 app/forms/decidim/action_delegator/admin/delegation_form.rb