app/forms/decidim/budgets/admin/project_form.rb in decidim-budgets-0.9.3 vs app/forms/decidim/budgets/admin/project_form.rb in decidim-budgets-0.10.0
- old
+ new
@@ -20,12 +20,13 @@
validates :description, translatable_presence: true
validates :budget, presence: true, numericality: { greater_than: 0 }
validates :category, presence: true, if: ->(form) { form.decidim_category_id.present? }
validates :scope, presence: true, if: ->(form) { form.decidim_scope_id.present? }
- validate { errors.add(:decidim_scope_id, :invalid) if current_participatory_space&.scope && !current_participatory_space&.scope&.ancestor_of?(scope) }
+ validate :scope_belongs_to_participatory_space_scope
+
delegate :categories, to: :current_feature
def map_model(model)
self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id)
@@ -47,17 +48,23 @@
# Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
#
# Returns a Decidim::Scope
def scope
- @scope ||= @decidim_scope_id ? current_feature.scopes.find_by(id: @decidim_scope_id) : current_participatory_space&.scope
+ @scope ||= @decidim_scope_id ? current_participatory_space.scopes.find_by(id: @decidim_scope_id) : current_participatory_space.scope
end
# Scope identifier
#
# Returns the scope identifier related to the project
def decidim_scope_id
@decidim_scope_id || scope&.id
+ end
+
+ private
+
+ def scope_belongs_to_participatory_space_scope
+ errors.add(:decidim_scope_id, :invalid) if current_participatory_space.out_of_scope?(scope)
end
end
end
end
end