From 46e1645bb91debb3e4ad98b82895ada5329e9351 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 21 Mar 2014 10:25:19 -0400 Subject: [PATCH] Fixes bug loading API tokens page. Added test using our new workbench testing framework to make sure it doesn't happen again. --- .../api_client_authorizations_controller.rb | 9 +++++- .../app/models/arvados_api_client.rb | 30 +++++++++++-------- .../app/models/arvados_resource_list.rb | 4 +++ .../app/views/layouts/application.html.erb | 2 +- .../api_client_authorizations_test.rb | 11 +++++++ 5 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 apps/workbench/test/integration/api_client_authorizations_test.rb diff --git a/apps/workbench/app/controllers/api_client_authorizations_controller.rb b/apps/workbench/app/controllers/api_client_authorizations_controller.rb index 81e324a46a..4a1256d9f7 100644 --- a/apps/workbench/app/controllers/api_client_authorizations_controller.rb +++ b/apps/workbench/app/controllers/api_client_authorizations_controller.rb @@ -1,8 +1,15 @@ class ApiClientAuthorizationsController < ApplicationController def index - @objects = model_class.all.to_ary.reject do |x| + m = model_class.all + items_available = m.items_available + offset = m.result_offset + limit = m.result_limit + filtered = m.to_ary.reject do |x| x.api_client_id == 0 or (x.expires_at and x.expires_at < Time.now) rescue false end + ArvadosApiClient.patch_paging_vars(filtered, items_available, offset, limit) + @objects = ArvadosResourceList.new(ApiClientAuthorization) + @objects.results= filtered super end diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb index 6d9269e667..093dd45ab3 100644 --- a/apps/workbench/app/models/arvados_api_client.rb +++ b/apps/workbench/app/models/arvados_api_client.rb @@ -90,22 +90,26 @@ class ArvadosApiClient resp end + def self.patch_paging_vars(ary, items_available, offset, limit) + if items_available + (class << ary; self; end).class_eval { attr_accessor :items_available } + ary.items_available = items_available + end + if offset + (class << ary; self; end).class_eval { attr_accessor :offset } + ary.offset = offset + end + if limit + (class << ary; self; end).class_eval { attr_accessor :limit } + ary.limit = limit + end + ary + end + def unpack_api_response(j, kind=nil) if j.is_a? Hash and j[:items].is_a? Array and j[:kind].match(/(_list|List)$/) ary = j[:items].collect { |x| unpack_api_response x, j[:kind] } - if j[:items_available] - (class << ary; self; end).class_eval { attr_accessor :items_available } - ary.items_available = j[:items_available] - end - if j[:offset] - (class << ary; self; end).class_eval { attr_accessor :offset } - ary.offset = j[:offset] - end - if j[:limit] - (class << ary; self; end).class_eval { attr_accessor :limit } - ary.limit = j[:limit] - end - ary + ArvadosApiClient.patch_paging_vars(ary, j[:items_available], j[:offset], j[:limit]) elsif j.is_a? Hash and (kind || j[:kind]) oclass = self.kind_class(kind || j[:kind]) if oclass diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb index 3842c97c37..6b17ececab 100644 --- a/apps/workbench/app/models/arvados_resource_list.rb +++ b/apps/workbench/app/models/arvados_resource_list.rb @@ -68,6 +68,10 @@ class ArvadosResourceList @results end + def results=(r) + @results = r + end + def all where({}) end diff --git a/apps/workbench/app/views/layouts/application.html.erb b/apps/workbench/app/views/layouts/application.html.erb index abef47136f..b5c75fc64f 100644 --- a/apps/workbench/app/views/layouts/application.html.erb +++ b/apps/workbench/app/views/layouts/application.html.erb @@ -149,7 +149,7 @@ <% end %>