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
|
|
|
|
2017-11-21 21:50:03 +00:00
|
|
|
FactoryBot.define do
|
2017-01-27 08:17:03 +00:00
|
|
|
factory :user do
|
2020-05-14 21:32:49 +00:00
|
|
|
transient do
|
|
|
|
intro_clues { true }
|
2021-04-01 13:07:13 +00:00
|
|
|
slug { "#{firstname}.#{lastname}".parameterize }
|
2020-05-14 21:32:49 +00:00
|
|
|
end
|
|
|
|
|
2021-04-01 13:07:13 +00:00
|
|
|
login { slug }
|
|
|
|
firstname { Faker::Name.first_name }
|
|
|
|
lastname { Faker::Name.last_name }
|
|
|
|
sequence(:email) { |n| "#{slug}.#{n}@zammad.org" }
|
2019-01-31 04:41:54 +00:00
|
|
|
password { nil }
|
|
|
|
active { true }
|
|
|
|
login_failed { 0 }
|
|
|
|
updated_by_id { 1 }
|
|
|
|
created_by_id { 1 }
|
2017-01-27 08:17:03 +00:00
|
|
|
|
2020-05-14 21:32:49 +00:00
|
|
|
callback(:after_stub, :before_create) do |object, context|
|
|
|
|
next if !context.intro_clues
|
|
|
|
|
|
|
|
object.preferences ||= {}
|
|
|
|
object.preferences[:intro] = true
|
|
|
|
end
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
factory :customer do
|
2019-02-04 06:56:18 +00:00
|
|
|
role_ids { Role.signup_role_ids.sort }
|
2019-02-13 04:19:33 +00:00
|
|
|
|
|
|
|
trait :with_org do
|
|
|
|
organization
|
|
|
|
end
|
2019-02-04 06:56:18 +00:00
|
|
|
end
|
2017-05-02 11:37:20 +00:00
|
|
|
|
2020-08-20 07:10:08 +00:00
|
|
|
factory :agent_and_customer do
|
2021-07-16 13:38:01 +00:00
|
|
|
role_ids { Role.signup_role_ids.push(Role.find_by(name: 'Agent').id).sort }
|
2020-08-20 07:10:08 +00:00
|
|
|
|
|
|
|
trait :with_org do
|
|
|
|
organization
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
factory :agent do
|
2019-02-04 06:56:18 +00:00
|
|
|
roles { Role.where(name: 'Agent') }
|
|
|
|
end
|
2018-03-08 12:23:37 +00:00
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
factory :admin do
|
2019-02-04 06:56:18 +00:00
|
|
|
roles { Role.where(name: %w[Admin Agent]) }
|
|
|
|
end
|
2020-04-27 13:34:52 +00:00
|
|
|
|
2021-07-02 06:54:23 +00:00
|
|
|
trait :with_valid_password do
|
|
|
|
password { generate :password_valid }
|
|
|
|
end
|
|
|
|
|
2020-04-27 13:34:52 +00:00
|
|
|
# make given password accessible for e.g. authentication logic
|
|
|
|
before(:create) do |user|
|
|
|
|
password_plain = user.password
|
|
|
|
user.define_singleton_method(:password_plain, -> { password_plain })
|
|
|
|
end
|
2021-08-19 17:31:15 +00:00
|
|
|
|
2021-10-29 08:49:17 +00:00
|
|
|
trait :groupable do
|
|
|
|
transient do
|
|
|
|
group { nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, context|
|
|
|
|
Array(context.group).each do |group|
|
|
|
|
user.groups << group
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-19 17:31:15 +00:00
|
|
|
trait :preferencable do
|
|
|
|
transient do
|
|
|
|
notification_group_ids { [] }
|
|
|
|
end
|
|
|
|
|
|
|
|
preferences do
|
|
|
|
{
|
|
|
|
'notification_config' => {
|
|
|
|
'matrix' => {
|
|
|
|
'create' => { 'criteria' => { 'owned_by_me' => true, 'owned_by_nobody' => true }, 'channel' => { 'email' => true, 'online' => true } },
|
|
|
|
'update' => { 'criteria' => { 'owned_by_me' => true, 'owned_by_nobody' => true }, 'channel' => { 'email' => true, 'online' => true } },
|
|
|
|
'reminder_reached' => { 'criteria' => { 'owned_by_me' => true, 'owned_by_nobody' => true }, 'channel' => { 'email' => true, 'online' => true } },
|
|
|
|
'escalation' => { 'criteria' => { 'owned_by_me' => true, 'owned_by_nobody' => true }, 'channel' => { 'email' => true, 'online' => true } },
|
|
|
|
},
|
|
|
|
'group_ids' => notification_group_ids
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2021-10-29 08:49:17 +00:00
|
|
|
|
|
|
|
trait :ooo do
|
|
|
|
transient do
|
|
|
|
ooo_agent { nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
out_of_office { true }
|
|
|
|
out_of_office_start_at { 1.day.ago }
|
|
|
|
out_of_office_end_at { 1.day.from_now }
|
|
|
|
out_of_office_replacement_id { ooo_agent.id }
|
|
|
|
end
|
2017-02-24 17:27:27 +00:00
|
|
|
end
|
2021-07-02 06:54:23 +00:00
|
|
|
|
|
|
|
sequence(:password_valid) do |n|
|
|
|
|
"SOme-pass#{n}"
|
|
|
|
end
|
2017-01-27 08:17:03 +00:00
|
|
|
end
|