Add folders page, backed by groups.
[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 owned_items params={}
21     res = $arvados_api_client.api self.class, "/#{self.uuid}/owned_items", {
22       _method: 'GET'
23     }.merge(params)
24     ret = ArvadosResourceList.new
25     ret.results = $arvados_api_client.unpack_api_response(res)
26     ret
27   end
28
29   def full_name
30     (self.first_name || "") + " " + (self.last_name || "")
31   end
32
33   def activate
34     self.private_reload($arvados_api_client.api(self.class,
35                                                 "/#{self.uuid}/activate",
36                                                 {}))
37   end
38
39   def attributes_for_display
40     super.reject { |k,v| %w(owner_uuid default_owner_uuid identity_url prefs).index k }
41   end
42
43  def attribute_editable?(attr)
44     (not (self.uuid.andand.match(/000000000000000$/) and self.is_admin)) and super(attr)
45   end
46
47   def friendly_link_name
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 end