Skip to content

Commit

Permalink
feat: organisations can also transfer time for the offer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
franpb14 committed May 16, 2021
1 parent ca70d10 commit 1c61670
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/controllers/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -72,19 +73,19 @@ 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
case accountable = @account.accountable
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
Expand Down

0 comments on commit 1c61670

Please sign in to comment.