iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 26
0
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

上一篇
[Day25] Ruby on Rails - 使用 change_column 碰的的問題分享
下一篇
[Day27] Ruby on Rails - ruby require 與 load 區別
系列文
Junior Ruby on Rails 工程師的心得與自我挑戰 30 天 (單身狗轉移注意力之歷練)30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言