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.29.1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.4 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.9 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.29.0 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.3 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.8 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.29.0.rc4 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.29.0.rc3 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.29.0.rc2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.29.0.rc1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.2 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.7 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.1 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.6 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.10 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.26.9 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.0 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.27.5 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.0.rc5 app/forms/decidim/initiatives/committee_member_form.rb
decidim-initiatives-0.28.0.rc4 app/forms/decidim/initiatives/committee_member_form.rb