X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5620a47e20e004188e0f1d0245ae9e916575e806..b73985d8a0c9173aec57f6a81fe540b2813a5bff:/services/api/lib/common_api_template.rb diff --git a/services/api/lib/common_api_template.rb b/services/api/lib/common_api_template.rb index 7b7478e25b..67c7f8c4fa 100644 --- a/services/api/lib/common_api_template.rb +++ b/services/api/lib/common_api_template.rb @@ -1,8 +1,13 @@ module CommonApiTemplate def self.included(base) - base.extend(ClassMethods) base.acts_as_api + base.class_eval do + alias_method :as_api_response_orig, :as_api_response + include InstanceMethods + end + base.extend(ClassMethods) base.api_accessible :common do |t| + t.add :href t.add :kind t.add :etag t.add :uuid @@ -11,7 +16,21 @@ module CommonApiTemplate t.add :modified_by_client_uuid t.add :modified_by_user_uuid t.add :modified_at - t.add :updated_at + end + end + + module InstanceMethods + # choose template based on opts[:for_user] + def as_api_response(template=nil, opts={}) + if template.nil? + user = opts[:for_user] || current_user + if user.andand.is_admin and self.respond_to? :api_accessible_superuser + template = :superuser + else + template = :user + end + end + self.as_api_response_orig(template, opts) end end