Skip to content

Commit

Permalink
Standardise current_user call within Commands tasks (Participatory …
Browse files Browse the repository at this point in the history
…Processes) (#12840)

* delgated current_user to form

* returned arguement perform action command

* create controller updated 2 arguements

* adapted instance_double to alter form test

* changed arguement in call in controller

* delgate current_user to form in import

* Deleted delegation method import process

* re-added current_user to call

* Update decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* reverting commit /controller_update/

* Update decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

---------

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
  • Loading branch information
greenwoodt and andreslucena committed May 22, 2024
1 parent 706ac9d commit 351b8a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ module Admin
# A command with all the business logic when copying a new participatory
# process in the system.
class CopyParticipatoryProcess < Decidim::Command
delegate :current_user, to: :form
# Public: Initializes the command.
#
# form - A form object with the params.
# participatory_process - A participatory_process we want to duplicate
def initialize(form, participatory_process, current_user)
def initialize(form, participatory_process)
@form = form
@participatory_process = participatory_process
@current_user = current_user
end

# Executes the command. Broadcasts these events:
Expand All @@ -25,7 +25,7 @@ def initialize(form, participatory_process, current_user)
def call
return broadcast(:invalid) if form.invalid?

Decidim.traceability.perform_action!("duplicate", @participatory_process, @current_user) do
Decidim.traceability.perform_action!("duplicate", @participatory_process, current_user) do
ParticipatoryProcess.transaction do
copy_participatory_process
copy_participatory_process_attachments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Admin
# A command with all the business logic when copying a new participatory
# process in the system.
class ImportParticipatoryProcess < Decidim::Command
delegate :current_user, to: :form
# Public: Initializes the command.
#
# form - A form object with the params.
Expand Down Expand Up @@ -36,10 +37,10 @@ def call
attr_reader :form

def import_participatory_process
importer = Decidim::ParticipatoryProcesses::ParticipatoryProcessImporter.new(form.current_organization, form.current_user)
importer = Decidim::ParticipatoryProcesses::ParticipatoryProcessImporter.new(form.current_organization, current_user)
participatory_processes.each do |original_process|
Decidim.traceability.perform_action!("import", Decidim::ParticipatoryProcess, form.current_user) do
@imported_process = importer.import(original_process, form.current_user, title: form.title, slug: form.slug)
Decidim.traceability.perform_action!("import", Decidim::ParticipatoryProcess, current_user) do
@imported_process = importer.import(original_process, current_user, title: form.title, slug: form.slug)
importer.import_participatory_process_steps(original_process["participatory_process_steps"]) if form.import_steps?
importer.import_categories(original_process["participatory_process_categories"]) if form.import_categories?
importer.import_folders_and_attachments(original_process["attachments"]) if form.import_attachments?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
enforce_permission_to :create, :process
@form = form(ParticipatoryProcessCopyForm).from_params(params)

CopyParticipatoryProcess.call(@form, current_participatory_process, current_user) do
CopyParticipatoryProcess.call(@form, current_participatory_process) do
on(:ok) do
flash[:notice] = I18n.t("participatory_processes_copies.create.success", scope: "decidim.admin")
redirect_to participatory_processes_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

module Decidim::ParticipatoryProcesses
describe Admin::CopyParticipatoryProcess do
subject { described_class.new(form, participatory_process, user) }
subject { described_class.new(form, participatory_process) }

let(:organization) { create(:organization) }
let(:user) { create(:user, organization:) }
let(:current_user) { create(:user, organization:) }
let(:participatory_process_group) { create(:participatory_process_group, organization:) }
let(:scope) { create(:scope, organization:) }
let(:errors) { double.as_null_object }
Expand All @@ -21,7 +21,8 @@ module Decidim::ParticipatoryProcesses
slug: "copied-slug",
copy_steps?: copy_steps,
copy_categories?: copy_categories,
copy_components?: copy_components
copy_components?: copy_components,
current_user:
)
end
let!(:category) do
Expand Down Expand Up @@ -77,9 +78,8 @@ module Decidim::ParticipatoryProcesses
it "traces the action", versioning: true do
expect(Decidim.traceability)
.to receive(:perform_action!)
.with("duplicate", Decidim::ParticipatoryProcess, user)
.with("duplicate", Decidim::ParticipatoryProcess, current_user)
.and_call_original

expect { subject.call }.to change(Decidim::ActionLog, :count)
action_log = Decidim::ActionLog.last
expect(action_log.action).to eq("duplicate")
Expand Down

0 comments on commit 351b8a4

Please sign in to comment.