Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add process groups #94

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def new

def create
enforce_permission_to :create, :translation_set

@form = form(TranslationSetForm).from_params(
params,
current_organization: current_organization
Expand Down Expand Up @@ -117,7 +118,7 @@ def sets
alias collection sets

def subject_manifests
@subject_manifests ||= Decidim.participatory_space_manifests.map do |manifest|
@subject_manifests ||= Decidim::TermCustomizer.manifests.map do |manifest|
models = manifest.model_class_name.constantize.where(organization: current_organization).map { |p| [translated_attribute(p.title), p.id] }
next unless models.count.positive?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def map_model(model)
model
end

self.subject_manifest = Decidim.participatory_space_manifests.find do |m|
self.subject_manifest = Decidim::TermCustomizer.manifests.find do |m|
m.model_class_name == subject.class.name
end.try(:name)
self.subject_id = subject.id
Expand Down Expand Up @@ -46,8 +46,8 @@ def component
end

def manifest
@manifest ||= Decidim.participatory_space_manifests.find do |m|
m.name == subject_manifest.to_sym
@manifest ||= Decidim::TermCustomizer.manifests.find do |m|
m.name.to_sym == subject_manifest.to_sym
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module ApplicationHelper
def tabs_id_for_constraint(constraint)
"constraint_#{constraint.to_param}"
end

def manifests
eliegaboriau marked this conversation as resolved.
Show resolved Hide resolved
Decidim::TermCustomizer.manifests
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/decidim/term_customizer/constraint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def space
def manifest
space_class = space ? space.class.name : subject_type

Decidim.participatory_space_manifests.find do |manifest|
Decidim::TermCustomizer.manifests.find do |manifest|
manifest.model_class_name == space_class
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/decidim/term_customizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ module TermCustomizer
class << self
attr_accessor :loader
end

def self.manifests
Decidim.participatory_space_manifests + [Decidim.find_resource_manifest(:participatory_process_group)]
end
end
end
7 changes: 7 additions & 0 deletions lib/decidim/term_customizer/context/controller_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def resolve!

@organization = env["decidim.current_organization"]

if defined?(Decidim::ParticipatoryProcesses)
@space ||= if controller.instance_of?(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController)
Decidim::ParticipatoryProcessGroup.where(organization: @organization).find(controller.params[:id])
end
end

# E.g. at the participatory process controller the
# `decidim.current_participatory_space` environment variable has not
# been set. Therefore, we need to fetch it directly from the
Expand All @@ -27,6 +33,7 @@ def resolve!
# we take this into account here.
end
end

@space ||= env["decidim.current_participatory_space"]

@component = env["decidim.current_component"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:data) { { headers: headers } }
let(:headers) { double }
let(:controller) { double }
let(:organization) { double }
let(:organization) { create(:organization) }

before do
allow(headers).to receive(:env).and_return(env)
Expand Down Expand Up @@ -100,4 +100,26 @@
expect(subject.component).to be(component)
end
end

context "with participatory process group defined in the controller" do
let(:env) do
{
"action_controller.instance" => controller,
"decidim.current_organization" => organization
}
end

let(:process_group) { create(:participatory_process_group, organization: organization) }

before do
allow(controller).to receive(:params).and_return({ id: process_group.id })
allow(controller).to receive(:instance_of?).with(Decidim::ParticipatoryProcesses::ParticipatoryProcessGroupsController).and_return(true)
end

it "resolves the participatory space as the participatory_process group" do
expect(subject.organization).to be(organization)
expect(subject.space).to eq(process_group)
expect(subject.component).to be_nil
end
end
end
64 changes: 64 additions & 0 deletions spec/lib/decidim/term_customizer/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,70 @@
end
end

context "with participatory process group" do
let(:space) { create(:participatory_process_group, organization: organization) }
let(:other_group) { create(:participatory_process_group, organization: organization) }
let(:other_set) { create(:translation_set) }

let(:constraint) do
set.constraints.create!(
organization: organization,
subject: space
)
end
let!(:other_constraint) do
other_set.constraints.create!(
organization: organization,
subject: other_group
)
end

describe "#constraints" do
it "returns correct constraints" do
expect(subject.constraints).to contain_exactly(constraint)
end
end

describe "#translations" do
let(:translations) { create_list(:translation, 10, translation_set: set) }
let!(:other_translations) { create_list(:translation, 10, translation_set: other_set) }

it "returns correct translations" do
expect(subject.translations).to match_array(translations)
end
end

context "when constraints are set for the subject type" do
let(:constraint) do
set.constraints.create!(
organization: organization,
subject_type: space.class.name
)
end
let!(:other_constraint) do
other_set.constraints.create!(
organization: organization,
subject_type: other_group.class.name
)
end

describe "#constraints" do
it "returns correct constraints" do
expect(subject.constraints).to contain_exactly(constraint, other_constraint)
end
end

describe "#translations" do
let(:translations) { create_list(:translation, 10, translation_set: set) }
let!(:other_translations) { create_list(:translation, 10, translation_set: other_set) }

it "returns correct translations" do
expect(subject.translations).to match_array(translations + other_translations)
end
end
end
end

context "with component process" do
let(:space) { create(:participatory_process, organization: organization) }
let(:component) { create(:proposal_component, participatory_space: space) }
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/decidim/term_customizer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "spec_helper"

describe Decidim::TermCustomizer do
describe "#manifests" do
it "returns the expected manifests" do
expect(Decidim::TermCustomizer.manifests.size).to equal(Decidim.participatory_space_manifests.size + 1)
expect(Decidim::TermCustomizer.manifests).to include(Decidim.find_resource_manifest(:participatory_process_group))
end
end
end