namespace :identity do
desc 'switch_role'
task switch_role_to_superuser: :environment do
switch_role 'apple:superuser'
end
task switch_role_to_importer: :environment do
switch_role 'apple:importer'
end
task switch_role_to_exporter: :environment do
switch_role 'apple:exporter'
end
task switch_role_to_export_supervisor: :environment do
switch_role 'apple:export_supervisor'
end
task switch_role_to_finance_and_accounting: :environment do
switch_role 'apple:finance_and_accounting'
end
task switch_role_to_control_tower: :environment do
switch_role 'apple:control_tower'
end
task switch_role_to_client: :environment do
switch_role 'apple:client'
end
task switch_role_to_fd_user: :environment do
switch_role 'apple:fd_user'
end
private
def switch_role(role)
user = find_or_create_user
context = ::Identity::ReinitializeRolesToUserContext.new(user, role)
context.perform
puts "User: #{user.name} switched to #{role}."
end
def find_or_create_user
User.find_or_create_by(email: 'localuser@test.com', name: 'localuser')
end
end