Skip to content

Commit

Permalink
Merge branch 'develop' into docs/install-ruby-3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreslucena committed Oct 26, 2022
2 parents b2d10f0 + 2aa37bc commit e758949
Show file tree
Hide file tree
Showing 50 changed files with 270 additions and 162 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ plugins:
- "**/*/locales/*.yml"
- "**/*/*.svg"
- "decidim-dev/lib/decidim/dev/assets/iso-8859-15.md"
- "decidim-dev/lib/decidim/dev/assets/import_participatory_space_private_users_iso8859-1.csv"

stylelint:
# FIXME: after the webpacker packages changes, this is broken with this error:
Expand Down
4 changes: 2 additions & 2 deletions .rubocop_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Style/BlockDelimiters:
# This looks at the usage of a block's method to determine its type (e.g. is
# the result of a `map` assigned to a variable or passed to another
# method) but exceptions are permitted in the `ProceduralMethods`,
# `FunctionalMethods` and `IgnoredMethods` sections below.
# `FunctionalMethods` and `AllowedMethods` sections below.
- semantic
# The `braces_for_chaining` style enforces braces around single line blocks
# and do..end around multi-line blocks, except for multi-line blocks whose
Expand Down Expand Up @@ -259,7 +259,7 @@ Style/BlockDelimiters:
- let!
- subject
- watch
IgnoredMethods:
AllowedMethods:
# Methods that can be either procedural or functional and cannot be
# categorised from their usage alone, e.g.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def import!

ActiveRecord::Base.transaction do
i = 1
csv = CSV.new(@csv_file, headers: true, col_sep: ";")
csv = CSV.new(@csv_file, headers: true, col_sep: Decidim.default_csv_col_sep)
while (row = csv.shift).present?
i += 1
next if row.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Decidim
module Admin
class ProcessParticipatorySpacePrivateUserImportCsv < Decidim::Command
include Decidim::ProcessesFileLocally
include Decidim::Admin::CustomImport

# Public: Initializes the command.
#
Expand Down Expand Up @@ -34,10 +34,8 @@ def call
private

def process_csv
process_file_locally(@form.file) do |file_path|
CSV.foreach(file_path, encoding: "BOM|UTF-8") do |email, user_name|
ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, @current_user) if email.present? && user_name.present?
end
process_import_file(@form.file) do |(email, user_name)|
ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, @current_user) if email.present? && user_name.present?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Admin
# A command with all the business logic when processing the CSV to verify
# user groups.
class ProcessUserGroupVerificationCsv < Decidim::Command
include Decidim::ProcessesFileLocally
include Decidim::Admin::CustomImport

# Public: Initializes the command.
#
Expand Down Expand Up @@ -35,11 +35,8 @@ def process_csv
verifier = @form.current_user
organization = @form.current_organization

process_file_locally(@form.file) do |file_path|
CSV.foreach(file_path) do |row|
email = row[0]
VerifyUserGroupFromCsvJob.perform_later(email, verifier, organization) if email.present?
end
process_import_file(@form.file) do |(email)|
VerifyUserGroupFromCsvJob.perform_later(email, verifier, organization) if email.present?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Admin
#
class ParticipatorySpacePrivateUserCsvImportForm < Form
include Decidim::HasUploadValidations
include Decidim::ProcessesFileLocally
include Decidim::Admin::CustomImport

attribute :file, Decidim::Attributes::Blob
attribute :user_name, String
Expand All @@ -20,10 +20,8 @@ class ParticipatorySpacePrivateUserCsvImportForm < Form
def validate_csv
return if file.blank?

process_file_locally(file) do |file_path|
CSV.foreach(file_path, encoding: "BOM|UTF-8") do |_email, user_name|
errors.add(:user_name, :invalid) unless user_name.match?(UserBaseEntity::REGEXP_NAME)
end
process_import_file(file) do |(_email, user_name)|
errors.add(:user_name, :invalid) if user_name.blank? || !user_name.match?(UserBaseEntity::REGEXP_NAME)
end
rescue CSV::MalformedCSVError
errors.add(:file, :malformed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
</div>
<div class="card-section">
<%= decidim_form_for(@form, url: participatory_space_private_users_csv_imports_path, html: { class: "form" }) do |form| %>
<p><%= t(".explanation") %></p>
<div class="mb-s">
<p><%= t(".explanation") %></p>
<p><%= t(".example_file") %></p>
<code class="code-block"><%= t(".explanation_example", csv_col_sep: Decidim.default_csv_col_sep) %></code>
</div>
<div class="row column">
<%= form.upload :file, optional: false %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
</div>
<div class="card-section">
<%= decidim_form_for(@form, url: user_groups_csv_verification_path, html: { class: "form" }) do |form| %>
<p><%= t(".explanation") %></p>
<div class="mb-s">
<p><%= t(".explanation") %></p>
<p><%= t(".example_file") %></p>
<code class="code-block"><%= t(".explanation_example") %></code>
</div>
<div class="row column">
<%= form.upload :file, optional: false %>
</div>
Expand Down
12 changes: 10 additions & 2 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ en:
title: New Participatory Space private participant.
participatory_space_private_users_csv_imports:
create:
invalid: There was a problem reading the CSV file.
invalid: There was a problem reading the CSV file. Please make sure you have followed the instructions.
success: CSV file uploaded successfully, we're sending an invitation email to participants. This might take a while.
new:
destroy:
Expand All @@ -857,7 +857,11 @@ en:
empty: You have no private participants.
explanation: You have %{count} private participants.
title: Delete private participants
explanation: Upload your CSV file. It must have two columns with email in the first column of the file and name in the last column of the file (email, name) of the users that you want to add to the participatory space, without headers. Avoid using invalid chars like `<>?%&^*#@()[]=+:;"{}\|` in user name.
example_file: 'Example file:'
explanation: Upload your CSV file. It must have two columns with email in the first column of the file and name in the last column of the file of the users that you want to add to the participatory space, without headers. Avoid using invalid chars like `<>?%&^*#@()[]=+:;"{}\|` in user name.
explanation_example: |
john.doe@example.org%{csv_col_sep}John Doe
jane.doe@example.org%{csv_col_sep}Jane Doe
title: Upload your CSV file
upload: Upload
reminders:
Expand Down Expand Up @@ -1006,7 +1010,11 @@ en:
verify_via_csv: Verify via CSV
user_groups_csv_verifications:
new:
example_file: 'Example file:'
explanation: Upload your CSV file. It must have the official emails of the groups in your organization in the first column of the file, without headers. Only groups that have confirmed their email and that have an email appearing in the CSV file will be validated.
explanation_example: |
acme@example.org
bubba.gump@example.org
title: Upload your CSV file
upload: Upload
users:
Expand Down
1 change: 1 addition & 0 deletions decidim-admin/lib/decidim/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Admin
autoload :FormBuilder, "decidim/admin/form_builder"
autoload :SearchFormBuilder, "decidim/admin/search_form_builder"
autoload :Import, "decidim/admin/import"
autoload :CustomImport, "decidim/admin/custom_import"

include ActiveSupport::Configurable

Expand Down
29 changes: 29 additions & 0 deletions decidim-admin/lib/decidim/admin/custom_import.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "active_support/concern"

module Decidim
module Admin
# A concern to help custom importing procedures that do not use the default
# importing logic.
module CustomImport
extend ActiveSupport::Concern

include Decidim::ProcessesFileLocally

private

def process_import_file(blob, &)
reader_klass = import_reader_klass_for(blob)
process_file_locally(blob) do |file_path|
reader = reader_klass.new(file_path)
reader.read_rows(&)
end
end

def import_reader_klass_for(blob)
Decidim::Admin::Import::Readers.search_by_mime_type(blob.content_type)
end
end
end
end
12 changes: 11 additions & 1 deletion decidim-admin/lib/decidim/admin/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ class Engine < ::Rails::Engine
decidim_admin.root_path,
icon_name: "dashboard",
position: 1,
active: ["decidim/admin/dashboard" => :show]
active: [%w(
decidim/admin/dashboard
decidim/admin/metrics
), []]

menu.add_item :moderations,
I18n.t("menu.moderation", scope: "decidim.admin"),
Expand Down Expand Up @@ -208,10 +211,15 @@ class Engine < ::Rails::Engine
decidim/admin/user_groups_csv_verifications
decidim/admin/officializations
decidim/admin/impersonatable_users
decidim/admin/conflicts
decidim/admin/moderated_users
decidim/admin/managed_users/impersonation_logs
decidim/admin/managed_users/promotions
decidim/admin/authorization_workflows
decidim/verifications/id_documents/admin/pending_authorizations
decidim/verifications/id_documents/admin/config
decidim/verifications/postal_letter/admin/pending_authorizations
decidim/verifications/csv_census/admin/census
), []],
if: allowed_to?(:read, :admin_user) || allowed_to?(:read, :managed_user)

Expand All @@ -238,6 +246,8 @@ class Engine < ::Rails::Engine
decidim/admin/scopes
decidim/admin/scope_types
decidim/admin/areas decidim/admin/area_types
decidim/admin/help_sections
decidim/admin/organization_external_domain_whitelist
),
[]
],
Expand Down
4 changes: 2 additions & 2 deletions decidim-admin/lib/decidim/admin/import/readers/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def self.first_data_index
end

def read_rows
::CSV.read(file, col_sep: ";").each_with_index do |row, index|
::CSV.read(file, col_sep: Decidim.default_csv_col_sep, encoding: "BOM|UTF-8").each_with_index do |row, index|
yield row, index
end
end

# Returns a StringIO
def example_file(data)
csv_data = ::CSV.generate(col_sep: ";") do |csv|
csv_data = ::CSV.generate(col_sep: Decidim.default_csv_col_sep) do |csv|
data.each do |row|
csv << row
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Decidim::Admin

context "when the CSV file has BOM" do
let(:file) { upload_test_file(Decidim::Dev.test_file("import_participatory_space_private_users_with_bom.csv", "text/csv"), return_blob: true) }
let(:email) { "my_user@example.org" }
let(:email) { "john.doe@example.org" }

it "broadcasts ok" do
expect(subject.call).to broadcast(:ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module Admin
it { is_expected.to be_invalid }
end

context "when the CSV separator is incorrect" do
let(:file) { upload_test_file(Decidim::Dev.asset("import_participatory_space_private_users_invalid_col_sep.csv")) }

it { is_expected.to be_invalid }
end

context "when the provided file is encoded with incorrect character set" do
let(:file) { upload_test_file(Decidim::Dev.asset("import_participatory_space_private_users_iso8859-1.csv")) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
create(
:user_group,
:confirmed,
email: "my_usergroup@example.org", # hardcoded in the CSV file
email: "acme@example.org", # hardcoded in the CSV file
organization:,
users: [create(:user, organization:)]
)
Expand Down
4 changes: 3 additions & 1 deletion decidim-assemblies/lib/decidim/assemblies/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class AdminEngine < ::Rails::Engine
decidim_admin_assemblies.assemblies_path,
icon_name: "dial",
position: 2.2,
active: :inclusive,
active: is_active_link?(decidim_admin_assemblies.assemblies_path) ||
is_active_link?(decidim_admin_assemblies.assemblies_types_path) ||
is_active_link?(decidim_admin_assemblies.edit_assemblies_settings_path),
if: allowed_to?(:enter, :space_area, space_name: :assemblies)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
find(".card-title a.import").click

# The CSV has no headers
expect(Decidim::Admin::ImportParticipatorySpacePrivateUserCsvJob).to receive(:perform_later).once.ordered.with("my_user@example.org", "My User Name", assembly, user)
expect(Decidim::Admin::ImportParticipatorySpacePrivateUserCsvJob).to receive(:perform_later).once.ordered.with("my_private_user@example.org", "My Private User Name", assembly, user)
expect(Decidim::Admin::ImportParticipatorySpacePrivateUserCsvJob).to receive(:perform_later).once.ordered.with("john.doe@example.org", "John Doe", assembly, user)
expect(Decidim::Admin::ImportParticipatorySpacePrivateUserCsvJob).to receive(:perform_later).once.ordered.with("jane.doe@example.org", "Jane Doe", assembly, user)
dynamically_attach_file(:participatory_space_private_user_csv_import_file, Decidim::Dev.asset("import_participatory_space_private_users.csv"))
perform_enqueued_jobs { click_button "Upload" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ def cache_hash
end

def activities
@activities ||= ActionLog.where(
organization: current_organization,
visibility: %w(public-only all)
).with_new_resource_type("all").order(created_at: :desc).limit(activities_to_show * 6)
@activities ||= LastActivity.new(current_organization).query.limit(activities_to_show * 6)
end

def activities_to_show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def accept_resource
resource.update!(newsletter_notifications_at: Time.current) if update_resource_params[:newsletter_notifications]
resource.update!(managed: false) if resource.managed?
resource.update!(accepted_tos_version: resource.organization.tos_version)
Decidim::Gamification.increment_score(resource.invited_by, :invitations) if resource.invited_by
end

resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ def activities
end

def search_collection
ActionLog
.where(
organization: current_organization,
visibility: %w(public-only all)
)
.with_new_resource_type("all")
.order(created_at: :desc)
LastActivity.new(current_organization).query
end

def default_filter_params
Expand Down
4 changes: 2 additions & 2 deletions decidim-core/app/forms/decidim/account_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class AccountForm < Form
attribute :personal_url
attribute :about

validates :name, presence: true
validates :name, presence: true, format: { with: Decidim::User::REGEXP_NAME }
validates :email, presence: true, "valid_email_2/email": { disposable: true }
validates :nickname, presence: true, format: Decidim::User::REGEXP_NICKNAME
validates :nickname, presence: true, format: { with: Decidim::User::REGEXP_NICKNAME }

validates :nickname, length: { maximum: Decidim::User.nickname_max_length, allow_blank: true }
validates :password, confirmation: true
Expand Down
4 changes: 2 additions & 2 deletions decidim-core/app/forms/decidim/registration_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class RegistrationForm < Form
attribute :tos_agreement, Boolean
attribute :current_locale, String

validates :name, presence: true
validates :nickname, presence: true, format: Decidim::User::REGEXP_NICKNAME, length: { maximum: Decidim::User.nickname_max_length }
validates :name, presence: true, format: { with: Decidim::User::REGEXP_NAME }
validates :nickname, presence: true, format: { with: Decidim::User::REGEXP_NICKNAME }, length: { maximum: Decidim::User.nickname_max_length }
validates :email, presence: true, "valid_email_2/email": { disposable: true }
validates :password, confirmation: true
validates :password, password: { name: :name, email: :email, username: :nickname }
Expand Down
Loading

0 comments on commit e758949

Please sign in to comment.