Skip to content
Permalink
Browse files

Bugfixing (#5376)

* Fix 'public_spaces' overwrite, only include published spaces

* Fix component generator. Closes #5295

* Tweak nickname help text

* Shorten filter text so it fits in the form

* Remove destroy link in organizations since the feature was removed. Closes #2066

* Fix scope select in initiatives admin

* Hide reported content from last activity

* Only show remaining events when there's no geocoding service at homepage

* Update CHANGELOG

* Fix locale checker task. Closes #5219.

Only English should be normalized since other languages come from Crowdin and
we don't expect them to have the keys in the same order.

* Include the participatory space followers as resource followers. Closes #5175.

* Store the random order in the session. Closes #5019
  • Loading branch information...
oriolgual committed Sep 30, 2019
1 parent 8a8bcb6 commit 0074c1153ee60b714ae14a358b9f507a78a271d2
Showing with 201 additions and 141 deletions.
  1. +1 −0 CHANGELOG.md
  2. +1 −1 decidim-assemblies/app/models/decidim/assembly.rb
  3. +1 −1 decidim-assemblies/config/locales/en.yml
  4. +2 −2 decidim-assemblies/spec/system/filter_assemblies_spec.rb
  5. +5 −9 decidim-budgets/app/controllers/decidim/budgets/projects_controller.rb
  6. +1 −0 decidim-budgets/app/models/decidim/budgets/project.rb
  7. +1 −11 decidim-budgets/app/services/decidim/budgets/project_search.rb
  8. +0 −2 decidim-budgets/app/views/decidim/budgets/projects/_filters.html.erb
  9. +1 −1 decidim-budgets/app/views/decidim/budgets/projects/_projects.html.erb
  10. +1 −21 decidim-consultations/app/controllers/concerns/decidim/consultations/orderable.rb
  11. +1 −1 decidim-consultations/app/controllers/decidim/consultations/consultations_controller.rb
  12. +1 −1 decidim-consultations/app/views/decidim/consultations/consultations/_consultations.html.erb
  13. +1 −2 decidim-core/app/cells/decidim/activities_cell.rb
  14. +1 −7 decidim-core/app/cells/decidim/content_blocks/last_activity_cell.rb
  15. +36 −0 decidim-core/app/controllers/concerns/decidim/orderable.rb
  16. +12 −0 decidim-core/app/models/decidim/action_log.rb
  17. +2 −2 decidim-core/config/locales/en.yml
  18. +8 −0 decidim-core/lib/decidim/followable.rb
  19. +1 −1 decidim-core/lib/decidim/has_private_users.rb
  20. +8 −0 decidim-core/spec/cells/decidim/content_blocks/last_activity_cell_spec.rb
  21. +46 −0 decidim-core/spec/lib/followable_spec.rb
  22. +46 −0 decidim-core/spec/models/decidim/action_log_spec.rb
  23. +4 −1 decidim-dev/lib/tasks/locale_checker.rake
  24. +6 −4 decidim-generators/exe/decidim
  25. +1 −0 decidim-generators/lib/decidim/generators/component_generator.rb
  26. +1 −19 decidim-initiatives/app/controllers/concerns/decidim/initiatives/orderable.rb
  27. +1 −1 decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb
  28. +1 −1 decidim-initiatives/app/views/decidim/initiatives/admin/initiatives/_form.html.erb
  29. +1 −1 decidim-initiatives/app/views/decidim/initiatives/initiatives/_initiatives.html.erb
  30. +1 −1 decidim-meetings/app/cells/decidim/meetings/content_blocks/upcoming_events/show.erb
  31. +1 −15 decidim-proposals/app/controllers/concerns/decidim/proposals/collaborative_orderable.rb
  32. +1 −15 decidim-proposals/app/controllers/concerns/decidim/proposals/orderable.rb
  33. +1 −1 decidim-proposals/app/controllers/decidim/proposals/proposals_controller.rb
  34. +1 −1 decidim-proposals/app/views/decidim/proposals/collaborative_drafts/_collaborative_drafts.html.erb
  35. +1 −1 decidim-proposals/app/views/decidim/proposals/proposals/_proposals.html.erb
  36. +1 −15 decidim-sortitions/app/controllers/concerns/decidim/sortitions/orderable.rb
  37. +1 −1 decidim-sortitions/app/controllers/decidim/sortitions/sortitions_controller.rb
  38. +1 −1 decidim-sortitions/app/views/decidim/sortitions/sortitions/_sortitions.html.erb
  39. +0 −1 decidim-system/app/views/decidim/system/organizations/show.html.erb
@@ -69,6 +69,7 @@
- **decidim-core**: Fix rendering when custom colors exist [#5347](https://github.com/decidim/decidim/pull/5347)
- **decidim-core**: Fix component generator [#5348](https://github.com/decidim/decidim/pull/5348)
- **decidim-core**: Fix email notifications [#5370](https://github.com/decidim/decidim/pull/5370)
- **decidim-assemblies**, **decidim-core**, **decidim-generators**, **decidim-initiatives**, **decidim-meetings**, **decidim-system** [\#5329](https://github.com/decidim/decidim/pull/5329)

**Removed**:

@@ -85,7 +85,7 @@ def self.visible_for(user)

# Overwriting existing method Decidim::HasPrivateUsers.public_spaces
def self.public_spaces
where(private_space: false).or(where(private_space: true).where(is_transparent: true))
where(private_space: false).or(where(private_space: true).where(is_transparent: true)).published
end

# Scope to return only the promoted assemblies.
@@ -264,7 +264,7 @@ en:
others: Others
public: Public
filter:
all: All types of assemblies
all: All types
commission: Commission
consultative_advisory: Consultative/Advisory
executive: Executive
@@ -20,11 +20,11 @@

before do
visit decidim_assemblies.assemblies_path
click_button "All types of assemblies"
click_button "All types"
end

it "filters by All types" do
click_link "All types of assemblies"
click_link "All types"
expect(page).to have_selector("article.card.card--assembly", count: 7)
end

@@ -6,21 +6,18 @@ module Budgets
class ProjectsController < Decidim::Budgets::ApplicationController
include FilterResource
include NeedsCurrentOrder
include Orderable

helper_method :projects, :random_seed, :project
helper_method :projects, :project

private

def projects
@projects ||= search.results.page(params[:page]).per(current_component.settings.projects_per_page)
end

def random_seed
@random_seed ||= search.random_seed
@projects ||= search.results.order_randomly(random_seed).page(params[:page]).per(current_component.settings.projects_per_page)
end

def project
@project ||= projects.find(params[:id])
@project ||= search.results.find(params[:id])
end

def search_klass
@@ -31,8 +28,7 @@ def default_filter_params
{
search_text: "",
scope_id: "",
category_id: "",
random_seed: params[:random_seed]
category_id: ""
}
end

@@ -16,6 +16,7 @@ class Project < Budgets::ApplicationRecord
include Decidim::Comments::Commentable
include Decidim::Traceable
include Decidim::Loggable
include Decidim::Randomable

component_manifest_name "budgets"
has_many :line_items, class_name: "Decidim::Budgets::LineItem", foreign_key: "decidim_project_id", dependent: :destroy
@@ -10,7 +10,6 @@ class ProjectSearch < ResourceSearch
# component - A Decidim::Component to get the projects from.
def initialize(options = {})
super(Project.all, options)
@random_seed = options[:random_seed].to_f
end

# Handle the search_text filter
@@ -22,16 +21,7 @@ def search_search_text

# Returns the random projects for the current page.
def results
@results ||= Project.transaction do
Project.connection.execute("SELECT setseed(#{Project.connection.quote(random_seed)})")
super.reorder(Arel.sql("RANDOM()")).load
end
end

# Returns the random seed used to randomize the proposals.
def random_seed
@random_seed = (rand * 2 - 1) if @random_seed == 0.0 || @random_seed > 1 || @random_seed < -1
@random_seed
Project.where(id: super.pluck(:id))
end

private
@@ -19,6 +19,4 @@
<% if current_component.categories.any? %>
<%= form.categories_select :category_id, current_component.categories, legend_title: t(".category"), disable_parents: false, label: false, prompt: t(".category_prompt") %>
<% end %>

<%= form.hidden_field :random_seed %>
<% end %>
@@ -3,4 +3,4 @@
<%= render partial: "project", locals: { project: project } %>
<% end %>
</div>
<%= decidim_paginate projects, random_seed: random_seed %>
<%= decidim_paginate projects %>
@@ -9,29 +9,15 @@ module Orderable
extend ActiveSupport::Concern

included do
helper_method :order, :available_orders, :random_seed
include Decidim::Orderable

private

# Gets how the proposals should be ordered based on the choice
# made by the user.
def order
@order ||= detect_order(params[:order]) || default_order
end

def detect_order(candidate)
available_orders.detect { |order| order == candidate }
end

# Available orders based on enabled settings
def available_orders
%w(random recent)
end

def default_order
"random"
end

def reorder(consultations)
case order
when "recent"
@@ -40,12 +26,6 @@ def reorder(consultations)
consultations.order_randomly(random_seed)
end
end

# Returns: A random float number between -1 and 1 to be used as a
# random seed at the database.
def random_seed
@random_seed ||= (params[:random_seed] ? params[:random_seed].to_f : (rand * 2 - 1))
end
end
end
end
@@ -10,7 +10,7 @@ class ConsultationsController < Decidim::Consultations::ApplicationController
include NeedsConsultation
include FilterResource
include Paginable
include Orderable
include Decidim::Consultations::Orderable
include ParticipatorySpaceContext

helper_method :collection, :consultations, :finished_consultations, :active_consultations, :filter
@@ -13,4 +13,4 @@
<%= card_for consultation %>
<% end %>
</div>
<%= decidim_paginate consultations, random_seed: random_seed %>
<%= decidim_paginate consultations %>
@@ -28,8 +28,7 @@ def activity_cell_for(activity)

def activities
@activities ||= last_activities.select do |activity|
!activity.resource_lazy.respond_to?(:can_participate?) ||
activity.resource_lazy.can_participate?(current_user)
activity.visible_for?(current_user)
end
end

@@ -33,7 +33,7 @@ def valid_activities
activities.each do |activity|
break if valid_activities_count == activities_to_show

if activity.resource_lazy.present? && activity.participatory_space_lazy.present? && visible_for_user?(activity)
if activity.visible_for?(current_user)
@valid_activities << activity
valid_activities_count += 1
end
@@ -44,12 +44,6 @@ def valid_activities

private

def visible_for_user?(activity)
return true unless activity.resource_lazy.respond_to?(:can_participate?)

activity.resource_lazy.can_participate?(current_user)
end

def activities
@activities ||= HomeActivitySearch.new(
organization: current_organization,
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
# Common logic to ordering resources
module Orderable
extend ActiveSupport::Concern

included do
helper_method :order, :available_orders, :random_seed

private

# Gets how the proposals should be ordered based on the choice
# made by the user.
def order
@order ||= detect_order(params[:order]) || default_order
end

def detect_order(candidate)
available_orders.detect { |order| order == candidate }
end

def default_order
"random"
end

# Returns: A random float number between -1 and 1 to be used as a
# random seed at the database.
def random_seed
@random_seed ||= session.fetch(:random_seed, (rand * 2 - 1)).to_f
end
end
end
end
@@ -128,5 +128,17 @@ def self.lazy_relation(id_method, klass_name, cache)
scope.each { |relation| loader.call(relation.id, relation) }
end
end

# Whether this activity or log is visible for a given user (can also be nil)
#
# Returns a True/False.
def visible_for?(user)
return false if resource_lazy.blank?
return false if participatory_space_lazy.blank?
return false if resource_lazy.respond_to?(:hidden?) && resource_lazy.hidden?
return false if resource_lazy.respond_to?(:can_participate?) && !resource_lazy.can_participate?(user)

true
end
end
end
@@ -365,7 +365,7 @@ en:
email_already_exists: Another account is using the same email address
new:
complete_profile: Complete profile
nickname_help: Your alias (@nickname) in %{organization}
nickname_help: Your alias in %{organization}
sign_up: Please complete your profile
subtitle: Please fill in the following form in order to complete the sign up
username_help: Public name that appears on your posts. With the aim of guaranteeing the anonymity, can be any name.
@@ -374,7 +374,7 @@ en:
already_have_an_account?: Already have an account?
newsletter: Receive an occasional newsletter with relevant information
newsletter_title: Contact permission
nickname_help: Your alias (@nickname) in %{organization}
nickname_help: Your alias in %{organization}
password_help: "%{minimun_characters} characters minimum, must not be too common (e.g. 123456) and must be different from your nickname and your email."
sign_in: Log in
sign_up: Sign up
@@ -9,5 +9,13 @@ module Followable
has_many :follows, as: :followable, foreign_key: "decidim_followable_id", foreign_type: "decidim_followable_type", class_name: "Decidim::Follow"
has_many :followers, through: :follows, source: :user
end

def followers
if respond_to?(:participatory_space) && participatory_space.present? && participatory_space.respond_to?(:followers)
super.or(participatory_space.followers).distinct
else
super
end
end
end
end
@@ -38,7 +38,7 @@ def can_participate?(user)
end

def self.public_spaces
where(private_space: false)
where(private_space: false).published
end

def self.private_spaces
@@ -53,6 +53,14 @@ def resource_types
it { is_expected.not_to include(action_log) }
end

context "when the resource has been hidden" do
before do
create(:moderation, :hidden, reportable: action_log.resource)
end

it { is_expected.not_to include(action_log) }
end

context "with a lot of activities" do
before do
5.times do
@@ -0,0 +1,46 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
describe Followable do
subject { resource }

let(:resource) { create(:dummy_resource) }

describe "followers" do
let!(:follow) { create(:follow, followable: resource) }

it "returns the users following the resource" do
expect(subject.followers).to include(follow.user)
end

context "when the resource doesn't have a participatory space" do
let(:resource) { create(:user) }

it "returns their followers" do
expect(subject.followers).to include(follow.user)
end
end

context "when the participatory space has also followers" do
let!(:space_follow) { create(:follow, followable: resource.participatory_space) }

it "includes them too" do
expect(subject.followers.count).to eq(2)
expect(subject.followers).to include(follow.user)
expect(subject.followers).to include(space_follow.user)
end

context "when the user follows the space and resource" do
let!(:space_follow) { create(:follow, followable: resource.participatory_space, user: follow.user) }

it "is included only once" do
expect(subject.followers.count).to eq(1)
expect(subject.followers).to include(follow.user)
end
end
end
end
end
end

0 comments on commit 0074c11

Please sign in to comment.
You can’t perform that action at this time.