8784: Fix test for latest firefox.
[arvados.git] / services / api / lib / common_api_template.rb
1 module CommonApiTemplate
2   def self.included(base)
3     base.acts_as_api
4     base.class_eval do
5       alias_method :as_api_response_orig, :as_api_response
6       include InstanceMethods
7     end
8     base.extend(ClassMethods)
9     base.api_accessible :common do |t|
10       t.add :href
11       t.add :kind
12       t.add :etag
13       t.add :uuid
14       t.add :owner_uuid
15       t.add :created_at
16       t.add :modified_by_client_uuid
17       t.add :modified_by_user_uuid
18       t.add :modified_at
19     end
20   end
21
22   module InstanceMethods
23     # choose template based on opts[:for_user]
24     def as_api_response(template=nil, opts={})
25       if template.nil?
26         user = opts[:for_user] || current_user
27         if user.andand.is_admin and self.respond_to? :api_accessible_superuser
28           template = :superuser
29         else
30           template = :user
31         end
32       end
33       self.as_api_response_orig(template, opts)
34     end
35   end
36
37   module ClassMethods
38   end
39 end