Sha256: df7ba16b240e7347e3a868b2acbe72a3ffff7fa4dec1e457a0ea1c3cd6b658c7

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A form object common to accept and reject actions requesters of Collaborative Drafts.
    class AccessToCollaborativeDraftForm < Decidim::Form
      mimic :collaborative_draft

      attribute :id, String
      attribute :requester_user_id, String
      attribute :state, String

      validates :id, :requester_user_id, presence: true
      validates :state, presence: true, inclusion: { in: %w(open) }

      validate :existence_of_requester_in_requesters

      def collaborative_draft
        @collaborative_draft ||= Decidim::Proposals::CollaborativeDraft.find id if id
      end

      def requester_user
        @requester_user ||= Decidim::User.find_by(id: requester_user_id, organization: current_organization) if requester_user_id
      end

      private

      def existence_of_requester_in_requesters
        if collaborative_draft
          errors.add(:requester_user_id, :invalid) unless collaborative_draft.requesters.exists? requester_user_id
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-proposals-0.23.6 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.5 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.4 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.3 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.2 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.1.rc1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.23.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.22.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.21.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.20.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.20.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.19.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.18.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.19.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.17.2 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.18.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.17.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.16.1 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb
decidim-proposals-0.17.0 app/forms/decidim/proposals/access_to_collaborative_draft_form.rb