-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: scopes and their children are checked in the filters on proposals page * test: update proposal controller test with extends tests * test: update test to include 2 levels of children * refactor: update extends after review
- Loading branch information
1 parent
8991a55
commit 4cd181a
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
lib/extends/controllers/decidim/proposals/proposals_controller_extends.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "active_support/concern" | ||
module ProposalsControllerExtends | ||
extend ActiveSupport::Concern | ||
included do | ||
private | ||
|
||
def default_filter_scope_params | ||
return "all" unless current_component.scopes.any? | ||
|
||
scope = current_component.scope | ||
return current_component_scope_ids if scope.blank? | ||
|
||
scope_children_ids = scope.children&.map(&:id) | ||
ids = ["all", scope.id] + scope_children_ids | ||
while Decidim::Scope.where(parent_id: scope_children_ids).present? | ||
sub_ids = Decidim::Scope.where(parent_id: scope_children_ids).pluck(:id) | ||
ids += sub_ids | ||
scope_children_ids = sub_ids | ||
end | ||
ids.map(&:to_s) | ||
end | ||
|
||
def current_component_scope_ids | ||
component_scopes = current_component.scopes.pluck(:id).map(&:to_s) | ||
%w(all global) + component_scopes | ||
end | ||
end | ||
end | ||
|
||
Decidim::Proposals::ProposalsController.include(ProposalsControllerExtends) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters