Sha256: fb823c9babeb3510634b9a0df694d76191214cf4d3b0d552358306e2fd3991eb

Contents?: true

Size: 841 Bytes

Versions: 69

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # A form object used to collect the data for a new initiative committee
    # member.
    class CommitteeMemberForm < Form
      mimic :initiatives_committee_member

      attribute :initiative_id, Integer
      attribute :user_id, Integer
      attribute :state, String

      validates :initiative_id, presence: true
      validates :user_id, presence: true
      validates :state, inclusion: { in: %w(requested rejected accepted) }, unless: :user_is_author?
      validates :state, inclusion: { in: %w(rejected accepted) }, if: :user_is_author?

      def user_is_author?
        initiative&.decidim_author_id == user_id
      end

      private

      def initiative
        @initiative ||= Decidim::Initiative.find_by(id: initiative_id)
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
decidim-initiatives-0.26.8 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.4 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.3 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.7 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.5 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.4 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.0 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.3 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.0.rc2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.0.rc1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.0 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.0.rc2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.0.rc1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.25.2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.25.1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.25.0 app/forms/decidim/initiatives/committee_member_form.rb