Skip to content

Commit

Permalink
Upgrade to Decidim v 0.27
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoleeSo13 committed Sep 28, 2023
1 parent 173981c commit 8490564
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 65 deletions.
8 changes: 8 additions & 0 deletions app/commands/decidim/challenges/invalid_broadcast_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module Decidim
module Challenges
class InvalidBroadcastError < StandardError
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module Decidim
module Challenges
class InvalidFormBroadcastError < StandardError
end
end
end
22 changes: 11 additions & 11 deletions app/controllers/decidim/problems/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def challenge_scope

def default_filter_params
{
search_text: "",
category_id: default_filter_category_params,
state: %w(proposal execution finished),
sectorial_scope_id: default_filter_scope_params,
technological_scope_id: default_filter_scope_params,
territorial_scope_id: default_filter_scope_params,
related_to: "",
sdgs_codes: [],
search_text_cont: "",
with_any_category_id: default_filter_category_params,
with_any_state: %w(proposal execution finished),
with_any_sectorial_scope_id: default_filter_scope_params,
with_any_technological_scope_id: default_filter_scope_params,
with_any_territorial_scope_id: default_filter_scope_params,
with_related_to: "",
sdgs_codes_cont: [],
}
end

Expand All @@ -64,11 +64,11 @@ def default_filter_scope_params
end

def problems
@problems ||= paginate(search.result.published)
@problems ||= paginate(search.result)
end

def search_klass
Decidim::Problems::ProblemSearch
def search_collection
::Decidim::Problems::Problem.published
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/decidim/solutions/solutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def show

def default_filter_params
{
search_text: "",
category_id: default_filter_category_params,
territorial_scope_id: default_filter_scope_params,
related_to: "",
sdgs_codes: [],
search_text_cont: "",
with_any_category_id: default_filter_category_params,
with_any_territorial_scope_id: default_filter_scope_params,
with_related_to: "",
sdgs_codes_cont: [],
}
end

Expand All @@ -61,7 +61,7 @@ def default_filter_scope_params
end

def solutions
@solutions ||= paginate(search.result.published)
@solutions ||= paginate(search.result)
end

def solution
Expand Down Expand Up @@ -89,8 +89,8 @@ def technological_scope
@technological_scope ||= current_organization.scopes.find_by(id: @solution.problem.decidim_technological_scope_id)
end

def search_klass
Decidim::Solutions::SolutionSearch
def search_collection
::Decidim::Solutions::Solution.published
end
end
end
Expand Down
12 changes: 10 additions & 2 deletions app/models/decidim/challenges/challenge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ class Challenge < Decidim::ApplicationRecord
scope :in_execution, -> { where(state: VALID_STATES.index(:execution)) }
scope :in_finished, -> { where(state: VALID_STATES.index(:finished)) }

scope :with_any_state, ->(*values) {
scope :with_any_state, lambda { |*values|
where(state: Array(values).map(&:to_sym) & VALID_STATES)
}

scope :with_search_text, lambda { |search_text|
where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%")
}

scope :with_sdgs_codes, lambda { |sdgs_codes|
where(sdg_code: sdgs_codes)
}

def self.ransackable_scopes(_auth_object = nil)
[:with_any_state]
[:with_any_state, :with_search_text, :with_sdgs_codes]
end

searchable_fields({
Expand Down
59 changes: 59 additions & 0 deletions app/models/decidim/problems/problem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Problems
# The data store for a Problem in the Decidim::Problems component.
class Problem < Decidim::ApplicationRecord
include Decidim::HasComponent
include Decidim::FilterableResource
include Decidim::Loggable
include Decidim::Publicable
include Decidim::Resourceable
Expand Down Expand Up @@ -37,6 +38,64 @@ class Problem < Decidim::ApplicationRecord
scope :in_execution, -> { where(state: VALID_STATES.index(:execution)) }
scope :in_finished, -> { where(state: VALID_STATES.index(:finished)) }

scope :with_any_state, lambda { |*values|
where(state: Array(values).map(&:to_sym) & VALID_STATES)
}

scope :with_search_text, lambda { |search_text|
where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%")
}

scope :with_sdgs_codes, lambda { |sdgs_codes|
joins(:challenge).where("decidim_challenges_challenges" => { sdg_code: sdgs_codes })
}

scope :with_any_sectorial_scope_id, lambda { |*sectorial_scope_id|
if sectorial_scope_id.include?("all")
all
else
clean_scope_ids = sectorial_scope_id

conditions = []
conditions << "#{model_name.plural}.decidim_sectorial_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

includes(:sectorial_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end
}

scope :with_any_technological_scope_id, lambda { |*technological_scope_id|
if technological_scope_id.include?("all")
all
else
clean_scope_ids = technological_scope_id

conditions = []
conditions << "#{model_name.plural}.decidim_technological_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

includes(:technological_scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end
}

scope :with_any_territorial_scope_id, lambda { |*territorial_scope_id|
if territorial_scope_id.include?("all")
all
else
clean_scope_ids = territorial_scope_id

conditions = []
conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

includes(challenge: :scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end
}

def self.ransackable_scopes(_auth_object = nil)
[:with_any_state, :with_search_text, :with_sdgs_codes, :with_any_sectorial_scope_id, :with_any_technological_scope_id, :with_any_territorial_scope_id]
end

searchable_fields({
scope_id: "decidim_sectorial_scope_id",
participatory_space: :itself,
Expand Down
27 changes: 27 additions & 0 deletions app/models/decidim/solutions/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Solutions
# The data store for a Solution in the Decidim::Solutions component.
class Solution < Solutions::ApplicationRecord
include Decidim::HasComponent
include Decidim::FilterableResource
include Decidim::Loggable
include Decidim::Publicable
include Decidim::Resourceable
Expand All @@ -20,6 +21,32 @@ class Solution < Solutions::ApplicationRecord

scope :published, -> { where.not(published_at: nil) }

scope :with_search_text, lambda { |search_text|
where("title ->> '#{I18n.locale}' ILIKE ?", "%#{search_text}%")
}

scope :with_sdgs_codes, lambda { |sdgs_codes|
joins(:challenge).where("decidim_challenges_challenges" => { sdg_code: sdgs_codes })
}

scope :with_any_territorial_scope_id, lambda { |*territorial_scope_id|
if territorial_scope_id.include?("all")
all
else
clean_scope_ids = territorial_scope_id

conditions = []
conditions << "decidim_challenges_challenges.decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

includes(problem: { challenge: :scope }).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end
}

def self.ransackable_scopes(_auth_object = nil)
[:with_search_text, :with_sdgs_codes, :with_any_territorial_scope_id]
end

searchable_fields({
participatory_space: :itself,
A: :title,
Expand Down
12 changes: 6 additions & 6 deletions app/views/decidim/problems/problems/_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="filters__section">
<div class="filters__search">
<div class="input-group">
<%= form.search_field :search_text, label: false, class: "input-group-field", placeholder: t(".search") %>
<%= form.search_field :search_text_cont, label: false, class: "input-group-field", placeholder: t(".search") %>
<div class="input-group-button">
<button type="submit" class="button button--muted">
<%= icon "magnifying-glass", aria_label: t(".search") %>
Expand All @@ -12,16 +12,16 @@
</div>
</div>

<%= form.check_boxes_tree :state, filter_problems_state_values, legend_title: t(".state") %>
<%= form.check_boxes_tree :with_any_state, filter_problems_state_values, legend_title: t(".state") %>
<% if current_participatory_space.has_subscopes? %>
<%= form.check_boxes_tree :territorial_scope_id, filter_scopes_values, legend_title: t(".territorial_scope") %>
<%= form.check_boxes_tree :sectorial_scope_id, filter_scopes_values, legend_title: t(".sectorial_scope") %>
<%= form.check_boxes_tree :technological_scope_id, filter_scopes_values, legend_title: t(".technological_scope") %>
<%= form.check_boxes_tree :with_any_territorial_scope_id, filter_scopes_values, legend_title: t(".territorial_scope") %>
<%= form.check_boxes_tree :with_any_sectorial_scope_id, filter_scopes_values, legend_title: t(".sectorial_scope") %>
<%= form.check_boxes_tree :with_any_technological_scope_id, filter_scopes_values, legend_title: t(".technological_scope") %>
<% end %>
<% if current_component.categories.any? %>
<%= form.check_boxes_tree :category_id, filter_categories_values, legend_title: t(".category") %>
<%= form.check_boxes_tree :with_any_category_id, filter_categories_values, legend_title: t(".category") %>
<% end %>
<% if current_participatory_space.components.published.where(manifest_name: "sdgs").any? %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/decidim/solutions/solutions/_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="filters__section">
<div class="filters__search">
<div class="input-group">
<%= form.search_field :search_text, label: false, class: "input-group-field", placeholder: t(".search") %>
<%= form.search_field :search_text_cont, label: false, class: "input-group-field", placeholder: t(".search") %>
<div class="input-group-button">
<button type="submit" class="button button--muted">
<%= icon "magnifying-glass", aria_label: t(".search") %>
Expand All @@ -13,11 +13,11 @@
</div>

<% if current_participatory_space.has_subscopes? %>
<%= form.check_boxes_tree :territorial_scope_id, filter_scopes_values, legend_title: t(".territorial_scope") %>
<%= form.check_boxes_tree :with_any_territorial_scope_id, filter_scopes_values, legend_title: t(".territorial_scope") %>
<% end %>
<% if current_component.categories.any? %>
<%= form.check_boxes_tree :category_id, filter_categories_values, legend_title: t(".category") %>
<%= form.check_boxes_tree :with_any_category_id, filter_categories_values, legend_title: t(".category") %>
<% end %>
<% if current_participatory_space.components.published.where(manifest_name: "sdgs").any? %>
Expand Down
14 changes: 7 additions & 7 deletions spec/services/decidim/challenges/challenge_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ module Challenges
subject do
described_class.new(
component:,
search_text:,
state: states,
search_text_cont:,
with_any_state: states,
related_to:,
scope_id: scope_ids,
category_id: category_ids,
with_any_scope_id: scope_ids,
with_any_category_id: category_ids,
sdgs_codes:
).result
end

let(:search_text) { nil }
let(:search_text_cont) { nil }
let(:related_to) { nil }
let(:states) { nil }
let(:scope_ids) { nil }
Expand All @@ -37,8 +37,8 @@ module Challenges
expect(subject).not_to include(other_challenge)
end

describe "search_text filter" do
let(:search_text) { "dog" }
describe "search_text_cont filter" do
let(:search_text_cont) { "dog" }

it "returns the challenges containing the search in the title or the body" do
dog_challenge = create(:challenge, title: { I18n.locale => "A dog" }, component:)
Expand Down
18 changes: 9 additions & 9 deletions spec/services/decidim/problems/problem_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ module Problems
subject do
described_class.new(
component:,
search_text:,
state: states,
search_text_cont:,
with_any_state: states,
related_to:,
sectorial_scope_id: sectorial_scope_ids,
technological_scope_id: technological_scope_ids,
territorial_scope_id: territorial_scope_ids,
category_id: category_ids,
with_any_sectorial_scope_id: sectorial_scope_ids,
with_any_technological_scope_id: technological_scope_ids,
with_any_territorial_scope_id: territorial_scope_ids,
with_any_category_id: category_ids,
sdgs_codes:
).result
end

let(:search_text) { nil }
let(:search_text_cont) { nil }
let(:related_to) { nil }
let(:states) { nil }
let(:sectorial_scope_ids) { nil }
Expand All @@ -42,8 +42,8 @@ module Problems
expect(subject).not_to include(other_problem)
end

describe "search_text filter" do
let(:search_text) { "dog" }
describe "search_text_cont filter" do
let(:search_text_cont) { "dog" }

it "returns the problems containing the search in the title or the body" do
dog_problem = create(:problem, title: { I18n.locale => "A dog" }, component:)
Expand Down
14 changes: 7 additions & 7 deletions spec/services/decidim/solutions/solution_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ module Solutions
subject do
described_class.new(
component:,
search_text:,
state: states,
search_text_cont:,
with_any_state: states,
related_to:,
territorial_scope_id: territorial_scope_ids,
category_id: category_ids,
with_any_territorial_scope_id: territorial_scope_ids,
with_any_category_id: category_ids,
sdgs_codes:
).result
end

let(:search_text) { nil }
let(:search_text_cont) { nil }
let(:related_to) { nil }
let(:states) { nil }
let(:territorial_scope_ids) { nil }
Expand All @@ -39,8 +39,8 @@ module Solutions
expect(subject).not_to include(other_solution)
end

describe "search_text filter" do
let(:search_text) { "dog" }
describe "search_text_cont filter" do
let(:search_text_cont) { "dog" }

it "returns the solutions containing the search in the title or the body" do
dog_solution = create(:solution, title: { I18n.locale => "A dog" }, component:)
Expand Down
Loading

0 comments on commit 8490564

Please sign in to comment.