app/permissions/decidim/debates/permissions.rb in decidim-debates-0.22.0 vs app/permissions/decidim/debates/permissions.rb in decidim-debates-0.23.0

- old
+ new

@@ -13,19 +13,47 @@ case permission_action.action when :create toggle_allow(can_create_debate?) when :report allow! + when :edit + can_edit_debate? + when :endorse + can_endorse_debate? + when :close + can_close_debate? end permission_action end private def can_create_debate? authorized?(:create) && current_settings&.creation_enabled? && component.participatory_space.can_participate?(user) + end + + def can_edit_debate? + return allow! if debate&.editable_by?(user) + + disallow! + end + + def can_close_debate? + return allow! if debate&.closeable_by?(user) + + disallow! + end + + def can_endorse_debate? + return disallow! if debate.closed? + + allow! + end + + def debate + @debate ||= context.fetch(:debate, nil) || context.fetch(:resource, nil) end end end end