2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-01-08 15:29:34 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Zendesk
|
|
|
|
module User
|
|
|
|
class Roles < Sequencer::Unit::Common::Provider::Named
|
|
|
|
|
|
|
|
uses :resource, :initiator
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def roles
|
|
|
|
return admin if initiator
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-08 15:29:34 +00:00
|
|
|
map_roles
|
|
|
|
end
|
|
|
|
|
|
|
|
def map_roles
|
|
|
|
return send(zendesk_role) if respond_to?(zendesk_role, true)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-08 15:29:34 +00:00
|
|
|
logger.error "Unknown mapping for role '#{resource.role.name}' (method: #{zendesk_role})"
|
|
|
|
end_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def zendesk_role
|
|
|
|
@zendesk_role ||= resource.role.name.tr('-', '_').to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_user
|
|
|
|
[role_customer]
|
|
|
|
end
|
|
|
|
|
|
|
|
def agent
|
|
|
|
return [role_agent] if resource.restricted_agent
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-01-08 15:29:34 +00:00
|
|
|
admin
|
|
|
|
end
|
|
|
|
|
|
|
|
def admin
|
|
|
|
[role_admin, role_agent]
|
|
|
|
end
|
|
|
|
|
|
|
|
def role_admin
|
|
|
|
@role_admin ||= lookup('Admin')
|
|
|
|
end
|
|
|
|
|
|
|
|
def role_agent
|
|
|
|
@role_agent ||= lookup('Agent')
|
|
|
|
end
|
|
|
|
|
|
|
|
def role_customer
|
|
|
|
@role_customer ||= lookup('Customer')
|
|
|
|
end
|
|
|
|
|
|
|
|
def lookup(role_name)
|
|
|
|
::Role.lookup(name: role_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|