Skip to content

Commit

Permalink
Merge branch 'release/0.27-stable' of github.com:AjuntamentdeBarcelon…
Browse files Browse the repository at this point in the history
…a/decidim into release/0.27-stable-bcn
  • Loading branch information
fblupi committed Sep 20, 2023
2 parents e201f49 + b88f1be commit bd158f9
Show file tree
Hide file tree
Showing 26 changed files with 229 additions and 41 deletions.
6 changes: 1 addition & 5 deletions .github/actions/module-rspec/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ runs:
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
name: Create the screenshots folder
shell: "bash"
- uses: nanasess/[email protected]
with:
# TODO: Unpin when nanasess/setup-chromedriver#190 is fixed:
# https://github.com/nanasess/setup-chromedriver/issues/190
chromedriver-version: 114.0.5735.90
- uses: nanasess/setup-chromedriver@v2
- run: RAILS_ENV=test bundle exec rails assets:precompile
name: Precompile assets
working-directory: ./spec/decidim_dummy_app/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
settings.attribute :scopes_enabled, type: :boolean, default: true
settings.attribute :scope_id, type: :scope
settings.attribute :comments_enabled, type: :boolean, default: true
settings.attribute :comments_max_length, type: :integer, required: false
settings.attribute :comments_max_length, type: :integer, required: true
settings.attribute :intro, type: :text, translated: true, editor: true
settings.attribute :categories_label, type: :string, translated: true, editor: true
settings.attribute :subcategories_label, type: :string, translated: true, editor: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "spec_helper"

describe "Accountability component" do # rubocop:disable RSpec/DescribeClass
let!(:component) { create(:accountability_component) }
let(:organization) { component.organization }
let!(:current_user) { create(:user, :confirmed, :admin, organization: organization) }

describe "on edit", type: :system do
let(:edit_component_path) do
Decidim::EngineRouter.admin_proxy(component.participatory_space).edit_component_path(component.id)
end

before do
switch_to_host(organization.host)
login_as current_user, scope: :user
end

context "when comments_max_length is empty" do
it_behaves_like "has mandatory config setting", :comments_max_length
end
end
end
4 changes: 2 additions & 2 deletions decidim-admin/app/forms/decidim/admin/organization_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OrganizationForm < Form
attribute :default_locale, String
attribute :badges_enabled, Boolean
attribute :user_groups_enabled, Boolean
attribute :comments_max_length, Integer
attribute :comments_max_length, Integer, default: 0
attribute :rich_text_editor_in_public_views, Boolean
attribute :enable_machine_translations, Boolean
attribute :machine_translation_display_priority, String
Expand All @@ -43,7 +43,7 @@ class OrganizationForm < Form
validates :default_locale, :reference_prefix, presence: true
validates :default_locale, inclusion: { in: :available_locales }
validates :admin_terms_of_use_body, translatable_presence: true
validates :comments_max_length, numericality: { greater_than: 0 }, if: ->(form) { form.comments_max_length.present? }
validates :comments_max_length, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :machine_translation_display_priority,
inclusion: { in: Decidim::Organization::AVAILABLE_MACHINE_TRANSLATION_DISPLAY_PRIORITIES },
if: :machine_translation_enabled?
Expand Down
2 changes: 2 additions & 0 deletions decidim-admin/spec/forms/organization_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Admin
let(:github_handler) { "My github awesome handler" }
let(:default_locale) { :en }
let(:translation_priority) { "original" }
let(:comments_max_length) { 100 }
let(:admin_terms_of_use_body) do
{
ca: "",
Expand All @@ -42,6 +43,7 @@ module Admin
"instagram_handler" => instagram_handler,
"youtube_handler" => youtube_handler,
"github_handler" => github_handler,
"comments_max_length" => comments_max_length,
"machine_translation_display_priority" => translation_priority,
"admin_terms_of_use_body_ca" => admin_terms_of_use_body[:ca],
"admin_terms_of_use_body_en" => admin_terms_of_use_body[:en],
Expand Down
9 changes: 9 additions & 0 deletions decidim-admin/spec/system/admin_manages_organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
expect(page).to have_content("updated successfully")
end

it "marks the comments_max_length as required" do
visit decidim_admin.edit_organization_path
expect(find("#organization_comments_max_length")[:required]).to eq("true")

expect(page).not_to have_content("There's an error in this field.")
fill_in :organization_comments_max_length, with: ""
expect(page).to have_content("There's an error in this field.")
end

context "when using the rich text editor" do
before do
visit decidim_admin.edit_organization_path
Expand Down
2 changes: 1 addition & 1 deletion decidim-blogs/lib/decidim/blogs/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
component.settings(:global) do |settings|
settings.attribute :announcement, type: :text, translated: true, editor: true
settings.attribute :comments_enabled, type: :boolean, default: true
settings.attribute :comments_max_length, type: :integer, required: false
settings.attribute :comments_max_length, type: :integer, required: true
end

component.settings(:step) do |settings|
Expand Down
24 changes: 24 additions & 0 deletions decidim-blogs/spec/lib/decidim/blogs/component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "spec_helper"

describe "Blogs component" do # rubocop:disable RSpec/DescribeClass
let!(:component) { create(:post_component) }
let(:organization) { component.organization }
let!(:current_user) { create(:user, :confirmed, :admin, organization: organization) }

describe "on edit", type: :system do
let(:edit_component_path) do
Decidim::EngineRouter.admin_proxy(component.participatory_space).edit_component_path(component.id)
end

before do
switch_to_host(organization.host)
login_as current_user, scope: :user
end

context "when comments_max_length is empty" do
it_behaves_like "has mandatory config setting", :comments_max_length
end
end
end
2 changes: 1 addition & 1 deletion decidim-budgets/app/models/decidim/budgets/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.ordered_ids(ids)
# array. This is why we search for match ",2," instead to get the actual
# position for ID 2.
concat_ids = connection.quote(",#{ids.join(",")},")
order(Arel.sql("position(concat(',', id::text, ',') in #{concat_ids})"))
order(Arel.sql("position(concat(',', decidim_budgets_projects.id::text, ',') in #{concat_ids})"))
end

def self.log_presenter_class_for(_log)
Expand Down
2 changes: 1 addition & 1 deletion decidim-budgets/lib/decidim/budgets/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
settings.attribute :vote_selected_projects_minimum, type: :integer, default: 0
settings.attribute :vote_selected_projects_maximum, type: :integer, default: 1
settings.attribute :comments_enabled, type: :boolean, default: true
settings.attribute :comments_max_length, type: :integer, required: false
settings.attribute :comments_max_length, type: :integer, required: true
settings.attribute :geocoding_enabled, type: :boolean, default: false
settings.attribute :resources_permissions_enabled, type: :boolean, default: true
settings.attribute :announcement, type: :text, translated: true, editor: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def new_settings(name, data)
visit edit_component_path
end

context "when comments_max_length is empty" do
it_behaves_like "has mandatory config setting", :comments_max_length
end

context "when minimum projects rule is checked" do
before do
check "Enable rule: Minimum number of projects to be voted on"
Expand Down
26 changes: 16 additions & 10 deletions decidim-budgets/spec/models/decidim/budgets/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ module Decidim::Budgets

describe ".ordered_ids" do
let(:budget) { create(:budget, total_budget: 1_000_000) }
let(:projects) { create_list(:project, 50, budget: budget, budget_amount: 100_000) }
let(:category) { create(:category, participatory_space: budget.participatory_space) }
let(:projects) { create_list(:project, 50, budget: budget, budget_amount: 100_000, category: category) }
let(:test_ids) do
first = described_class.where(budget: budget).order(:id).pluck(:id)[0..3]
ids = described_class.where(budget: budget).pluck(:id).shuffle

# Put the first items at the end of the IDs array in order to get
# possibly "conflicting" matches for them at earlier array positions.
# As we have 50 projects, we should have IDs starting with 1, 2, 3 and 4
# which is why we put the first 4 items at the end.
(ids - first) + first
end

before do
# Reset the project IDs to start from 1 in order to get possibly
Expand All @@ -50,17 +61,12 @@ module Decidim::Budgets
end

it "returns the correctly ordered projects" do
first = described_class.where(budget: budget).order(:id).pluck(:id)[0..3]
ids = described_class.where(budget: budget).pluck(:id).shuffle

# Put the first items at the end of the IDs array in order to get
# possibly "conflicting" matches for them at earlier array positions.
# As we have 50 projects, we should have IDs starting with 1, 2, 3 and 4
# which is why we put the first 4 items at the end.
test_ids = (ids - first) + first

expect(described_class.ordered_ids(test_ids).pluck(:id)).to eq(test_ids)
end

it "returns the correctly ordered projects after filtering by category" do
expect(described_class.with_any_category([category.id]).ordered_ids(test_ids).pluck(:id)).to eq(test_ids)
end
end

describe "#orders_count" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ def comments_max_length
def component_comments_max_length
return unless model.component&.settings.respond_to?(:comments_max_length)

model.component.settings.comments_max_length if model.component.settings.comments_max_length.positive?
model.component.settings.comments_max_length if model.component.settings.comments_max_length.to_i.positive?
end

def organization_comments_max_length
return unless organization

organization.comments_max_length if organization.comments_max_length.positive?
organization.comments_max_length if organization.comments_max_length.to_i.positive?
end

def organization
Expand Down
13 changes: 13 additions & 0 deletions decidim-comments/spec/cells/decidim/comments/comment_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ module Decidim::Comments
let(:comment) { create(:comment, commentable: commentable) }

context "when rendering" do
context "when component comments_max_length is malformed" do
let(:component) { create(:component, participatory_space: participatory_process, settings: { comments_max_length: "" }) }

it { expect { subject }.not_to raise_error }
end

context "when organization comments_max_length is malformed" do
let(:component) { create(:component, participatory_space: participatory_process, settings: { comments_max_length: "" }) }
let(:organization) { create(:organization, comments_max_length: "") }

it { expect { subject }.not_to raise_error }
end

it "renders the form" do
expect(subject).to have_css(".hashtags__container textarea#add-comment-DummyResource-#{commentable.id}[maxlength='1000']")
expect(subject).to have_css("#add-comment-DummyResource-#{commentable.id}-remaining-characters")
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/controllers/decidim/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_url
end

def external_url
@external_url ||= URI.parse(params[:external_url])
@external_url ||= URI.parse(URI::Parser.new.escape(params[:external_url]))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UserTimelineController < Decidim::ApplicationController
helper_method :activities, :resource_types, :user

def index
raise ActionController::RoutingError, "Not Found" if current_user != user
raise ActionController::RoutingError, "Not Found" unless user && current_user == user
end

private
Expand Down
3 changes: 2 additions & 1 deletion decidim-core/lib/decidim/core/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ def generate_localized_title
published_at { Time.current }
settings do
{
dummy_global_translatable_text: generate_localized_title
dummy_global_translatable_text: generate_localized_title,
comments_max_length: participatory_space.organization.comments_max_length || organization.comments_max_length
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,54 @@

module Decidim
describe UserTimelineController, type: :controller do
subject { get :index, params: { nickname: nickname } }

routes { Decidim::Core::Engine.routes }

let(:organization) { create(:organization) }
let!(:user) { create(:user, :confirmed, nickname: "Nick", organization: organization) }
let(:nickname) { "foobar" }

before do
request.env["decidim.current_organization"] = organization
sign_in user
end

shared_examples_for "a not found page" do
it "raises an ActionController::RoutingError" do
expect { subject }.to raise_error(ActionController::RoutingError, "Not Found")
end
end

describe "#index" do
context "with a different user than me" do
it "raises an ActionController::RoutingError" do
expect do
get :index, params: { nickname: "foobar" }
end.to raise_error(ActionController::RoutingError, "Not Found")
context "with the user logged in" do
before do
sign_in user
end

context "with a different user than me" do
it_behaves_like "a not found page"
end

context "with my user with uppercase" do
let(:nickname) { user.nickname.upcase }

it "returns the lowercased user" do
subject

expect(response).to render_template(:index)
end
end
end

context "with my user with uppercase" do
it "returns the lowercased user" do
get :index, params: { nickname: "NICK" }
expect(response).to render_template(:index)
context "without the user logged in" do
context "with a non existing user" do
it_behaves_like "a not found page"
end

context "with my user with uppercase" do
let(:nickname) { user.nickname.upcase }

it_behaves_like "a not found page"
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions decidim-core/spec/system/external_domain_warning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
expect(page).to have_link("Another link", href: "http://www.example.org")
end

context "when url has special characters" do
let(:destination) { "https://example.org/test?foo=bàr" }
let(:url) { "http://#{organization.host}/link?external_url=#{destination}" }

it "does not show invalid url alert" do
visit url
expect(page).not_to have_content("Invalid URL")
expect(page).to have_content("b%C3%A0r")
end
end

context "when url is invalid" do
let(:invalid_url) { "http://#{organization.host}/link?external_url=foo" }

Expand Down
2 changes: 1 addition & 1 deletion decidim-debates/lib/decidim/debates/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
settings.attribute :scopes_enabled, type: :boolean, default: false
settings.attribute :scope_id, type: :scope
settings.attribute :comments_enabled, type: :boolean, default: true
settings.attribute :comments_max_length, type: :integer, required: false
settings.attribute :comments_max_length, type: :integer, required: true
settings.attribute :announcement, type: :text, translated: true, editor: true
end

Expand Down
5 changes: 3 additions & 2 deletions decidim-debates/lib/decidim/debates/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def generate_localized_debate_title
description { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_debate_title } }
information_updates { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_debate_title } }
instructions { Decidim::Faker::Localized.wrapped("<p>", "</p>") { generate_localized_debate_title } }
component { build(:component, manifest_name: "debates") }
component { build(:debates_component) }
author { component.try(:organization) }

trait :open_ama do
Expand Down Expand Up @@ -67,7 +67,8 @@ def generate_localized_debate_title
participatory_space { create(:participatory_process, :with_steps, organization: organization) }
settings do
{
comments_enabled: true
comments_enabled: true,
comments_max_length: organization.comments_max_length
}
end

Expand Down
Loading

0 comments on commit bd158f9

Please sign in to comment.