Merge branch '16552-autocert'
[arvados.git] / services / api / test / factories / user.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class CurrentApiClientHelper
6   extend CurrentApiClient
7 end
8
9 FactoryBot.define do
10   factory :user do
11     transient do
12       join_groups { [] }
13     end
14     after :create do |user, evaluator|
15       CurrentApiClientHelper.act_as_system_user do
16         evaluator.join_groups.each do |g|
17           Link.create!(tail_uuid: user.uuid,
18                        head_uuid: g.uuid,
19                        link_class: 'permission',
20                        name: 'can_read')
21           Link.create!(tail_uuid: g.uuid,
22                        head_uuid: user.uuid,
23                        link_class: 'permission',
24                        name: 'can_read')
25         end
26       end
27     end
28     first_name { "Factory" }
29     last_name { "Factory" }
30     identity_url do
31       "https://example.com/#{rand(2**24).to_s(36)}"
32     end
33     factory :active_user do
34       is_active { true }
35       after :create do |user|
36         CurrentApiClientHelper.act_as_system_user do
37           Link.create!(tail_uuid: user.uuid,
38                        head_uuid: Group.where('uuid ~ ?', '-f+$').first.uuid,
39                        link_class: 'permission',
40                        name: 'can_read')
41         end
42       end
43     end
44     to_create do |instance|
45       CurrentApiClientHelper.act_as_system_user do
46         instance.save!
47       end
48     end
49   end
50 end