Merge branch '12991-docker-memory-limit'
[arvados.git] / apps / workbench / app / models / user.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class User < ArvadosBase
6   def initialize(*args)
7     super(*args)
8     @attribute_sortkey['first_name'] = '050'
9     @attribute_sortkey['last_name'] = '051'
10   end
11
12   def self.current
13     res = arvados_api_client.api self, '/current', nil, {}, false
14     arvados_api_client.unpack_api_response(res)
15   end
16
17   def self.system
18     @@arvados_system_user ||= begin
19                                 res = arvados_api_client.api self, '/system'
20                                 arvados_api_client.unpack_api_response(res)
21                               end
22   end
23
24   def full_name
25     (self.first_name || "") + " " + (self.last_name || "")
26   end
27
28   def activate
29     self.private_reload(arvados_api_client.api(self.class,
30                                                "/#{self.uuid}/activate",
31                                                {}))
32   end
33
34   def contents params={}
35     Group.contents params.merge(uuid: self.uuid)
36   end
37
38   def attributes_for_display
39     super.reject { |k,v| %w(owner_uuid default_owner_uuid identity_url prefs).index k }
40   end
41
42   def attribute_editable?(attr, ever=nil)
43     (ever or not (self.uuid.andand.match(/000000000000000$/) and
44                   self.is_admin)) and super
45   end
46
47   def friendly_link_name lookup=nil
48     [self.first_name, self.last_name].compact.join ' '
49   end
50
51   def unsetup
52     self.private_reload(arvados_api_client.api(self.class,
53                                                "/#{self.uuid}/unsetup",
54                                                {}))
55   end
56
57   def self.setup params
58     arvados_api_client.api(self, "/setup", params)
59   end
60
61   def update_profile params
62     self.private_reload(arvados_api_client.api(self.class,
63                                                "/#{self.uuid}/profile",
64                                                params))
65   end
66
67   def deletable?
68     false
69   end
70
71    def self.creatable?
72     current_user and current_user.is_admin
73    end
74 end