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