From 1c616709ea412dc52db2d1f6cfb787bef82aa185 Mon Sep 17 00:00:00 2001 From: franpb14 Date: Sun, 16 May 2021 14:12:37 +0200 Subject: [PATCH] feat: organisations can also transfer time for the offer Sergi says that an organisation can also give time for an offer from another organisation so now it also works if an admin chooses an organisation's account. I have also refactored my code a bit. Issue #638. --- app/controllers/transfers_controller.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb index f67ad3be..68bf8052 100644 --- a/app/controllers/transfers_controller.rb +++ b/app/controllers/transfers_controller.rb @@ -56,14 +56,15 @@ def find_source def create_persisters source_organization = @source.organization.account + source_type = @source.accountable_type destination_organization = @account.organization.account - + @persisters = Array.new if source_organization == destination_organization - @persister = transfer_persister_between(@source, @account) + transfer_persister_between(@source, @account) else - @pers_src_org = transfer_persister_between(@source, source_organization) - @pers_between_orgs = transfer_persister_between(source_organization, destination_organization) - @pers_org_acc = transfer_persister_between(destination_organization, @account) + transfer_persister_between(@source, source_organization) if source_type == "Member" + transfer_persister_between(source_organization, destination_organization) + transfer_persister_between(destination_organization, @account) end end @@ -72,11 +73,11 @@ def transfer_persister_between(source, destination) transfer_params.merge(source: source, destination: destination) ) - ::Persister::TransferPersister.new(@transfer) + @persisters << ::Persister::TransferPersister.new(@transfer) end def persisters_saved? - @persister&.save || @pers_src_org&.save && @pers_between_orgs&.save && @pers_org_acc&.save + @persisters.each { |persister| return false if !persister.save } end def redirect_target @@ -84,7 +85,7 @@ def redirect_target when Organization accountable when Member - accountable.organization == current_organization ? accountable.user : @source.accountable.user + accountable.organization == current_organization ? accountable.user : accountable.organization else raise ArgumentError end