[ARVADOS] created: d325f035a861d1421f6e2fe0d2f01e9f3e93d749

git at public.curoverse.com git at public.curoverse.com
Mon Apr 21 17:50:40 EDT 2014


        at  d325f035a861d1421f6e2fe0d2f01e9f3e93d749 (commit)


commit d325f035a861d1421f6e2fe0d2f01e9f3e93d749
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 17:50:49 2014 -0400

    Add owned_items action for groups and users.

diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 4b13fca..4836a73 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -10,12 +10,13 @@ class ApplicationController < ActionController::Base
   before_filter :require_auth_scope_all, :except => :render_not_found
   before_filter :catch_redirect_hint
 
-  before_filter :load_where_param, :only => :index
-  before_filter :load_filters_param, :only => :index
-  before_filter :find_objects_for_index, :only => :index
   before_filter :find_object_by_uuid, :except => [:index, :create,
                                                   :render_error,
                                                   :render_not_found]
+  before_filter :load_limit_offset_order_params, only: [:index, :owned_items]
+  before_filter :load_where_param, only: [:index, :owned_items]
+  before_filter :load_filters_param, only: [:index, :owned_items]
+  before_filter :find_objects_for_index, :only => :index
   before_filter :reload_object_before_update, :only => :update
   before_filter :render_404_if_no_object, except: [:index, :create,
                                                    :render_error,
@@ -25,6 +26,8 @@ class ApplicationController < ActionController::Base
 
   attr_accessor :resource_attrs
 
+  DEFAULT_LIMIT = 100
+
   def index
     @objects.uniq!(&:id)
     if params[:eager] and params[:eager] != '0' and params[:eager] != 0 and params[:eager] != ''
@@ -56,6 +59,52 @@ class ApplicationController < ActionController::Base
     show
   end
 
+  def owned_items
+    all_objects = []
+    all_available = 0
+
+    # We stuffed params[:uuid] into @where in find_object_by_uuid,
+    # but we don't want it there any more.
+    @where = {}
+    # Order, limit, offset don't work here.
+    limit_all = @limit
+    @limit = DEFAULT_LIMIT
+    offset_all = @offset
+    @offset = 0
+    orders_all = @orders
+    @orders = []
+
+    ArvadosModel.descendants.reject(&:abstract_class?).sort_by(&:to_s).each do |klass|
+      case klass.to_s
+      when *%w(ApiClientAuthorization Link ApiClient)
+        # Do not want.
+      else
+        @objects = klass.
+          readable_by(current_user).
+          where(owner_uuid: @object.uuid)
+        apply_where_limit_order_params
+        # TODO: follow links, too
+        all_available += @objects.
+          except(:limit).except(:offset).
+          count(:id, distinct: true)
+        if all_objects.length < limit_all + offset_all
+          all_objects += @objects.to_a
+        end
+      end
+    end
+    @objects = all_objects[offset_all..(offset_all+limit_all-1)] || []
+    @object_list = {
+      :kind  => "arvados#objectList",
+      :etag => "",
+      :self_link => "",
+      :offset => offset_all,
+      :limit => limit_all,
+      :items_available => all_available,
+      :items => @objects.as_api_response(nil)
+    }
+    render json: @object_list
+  end
+
   def catch_redirect_hint
     if !current_user
       if params.has_key?('redirect_to') then
@@ -135,12 +184,51 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  def load_limit_offset_order_params
+    if params[:limit]
+      begin
+        @limit = params[:limit].to_i
+      rescue
+        raise ArgumentError.new("Invalid value for limit parameter")
+      end
+    else
+      @limit = DEFAULT_LIMIT
+    end
+
+    if params[:offset]
+      begin
+        @offset = params[:offset].to_i
+      rescue
+        raise ArgumentError.new("Invalid value for offset parameter")
+      end
+    else
+      @offset = 0
+    end
+
+    @orders = []
+    if params[:order]
+      params[:order].split(',').each do |order|
+        attr, direction = order.strip.split " "
+        direction ||= 'asc'
+        if attr.match /^[a-z][_a-z0-9]+$/ and
+            model_class.columns.collect(&:name).index(attr) and
+            ['asc','desc'].index direction.downcase
+          @orders << "#{table_name}.#{attr} #{direction.downcase}"
+        end
+      end
+    end
+    if @orders.empty?
+      @orders << "#{table_name}.modified_at desc"
+    end
+  end
+
   def find_objects_for_index
     @objects ||= model_class.readable_by(current_user)
     apply_where_limit_order_params
   end
 
   def apply_where_limit_order_params
+    ar_table_name = @objects.table_name
     if @filters.is_a? Array and @filters.any?
       cond_out = []
       param_out = []
@@ -151,7 +239,7 @@ class ApplicationController < ActionController::Base
         case operator.downcase
         when '=', '<', '<=', '>', '>=', 'like'
           if operand.is_a? String
-            cond_out << "#{table_name}.#{attr} #{operator} ?"
+            cond_out << "#{ar_table_name}.#{attr} #{operator} ?"
             if (# any operator that operates on value rather than
                 # representation:
                 operator.match(/[<=>]/) and
@@ -162,7 +250,7 @@ class ApplicationController < ActionController::Base
           end
         when 'in'
           if operand.is_a? Array
-            cond_out << "#{table_name}.#{attr} IN (?)"
+            cond_out << "#{ar_table_name}.#{attr} IN (?)"
             param_out << operand
           end
         when 'is_a'
@@ -171,7 +259,7 @@ class ApplicationController < ActionController::Base
           operand.each do |op|
               cl = ArvadosModel::kind_class op
               if cl
-                cond << "#{table_name}.#{attr} like ?"
+                cond << "#{ar_table_name}.#{attr} like ?"
                 param_out << cl.uuid_like_pattern
               else
                 cond << "1=0"
@@ -193,7 +281,7 @@ class ApplicationController < ActionController::Base
               value[0] == 'contains' then
             ilikes = []
             model_class.searchable_columns('ilike').each do |column|
-              ilikes << "#{table_name}.#{column} ilike ?"
+              ilikes << "#{ar_table_name}.#{column} ilike ?"
               conditions << "%#{value[1]}%"
             end
             if ilikes.any?
@@ -203,24 +291,24 @@ class ApplicationController < ActionController::Base
         elsif attr.to_s.match(/^[a-z][_a-z0-9]+$/) and
             model_class.columns.collect(&:name).index(attr.to_s)
           if value.nil?
-            conditions[0] << " and #{table_name}.#{attr} is ?"
+            conditions[0] << " and #{ar_table_name}.#{attr} is ?"
             conditions << nil
           elsif value.is_a? Array
             if value[0] == 'contains' and value.length == 2
-              conditions[0] << " and #{table_name}.#{attr} like ?"
+              conditions[0] << " and #{ar_table_name}.#{attr} like ?"
               conditions << "%#{value[1]}%"
             else
-              conditions[0] << " and #{table_name}.#{attr} in (?)"
+              conditions[0] << " and #{ar_table_name}.#{attr} in (?)"
               conditions << value
             end
           elsif value.is_a? String or value.is_a? Fixnum or value == true or value == false
-            conditions[0] << " and #{table_name}.#{attr}=?"
+            conditions[0] << " and #{ar_table_name}.#{attr}=?"
             conditions << value
           elsif value.is_a? Hash
             # Not quite the same thing as "equal?" but better than nothing?
             value.each do |k,v|
               if v.is_a? String
-                conditions[0] << " and #{table_name}.#{attr} ilike ?"
+                conditions[0] << " and #{ar_table_name}.#{attr} ilike ?"
                 conditions << "%#{k}%#{v}%"
               end
             end
@@ -234,46 +322,9 @@ class ApplicationController < ActionController::Base
       end
     end
 
-    if params[:limit]
-      begin
-        @limit = params[:limit].to_i
-      rescue
-        raise ArgumentError.new("Invalid value for limit parameter")
-      end
-    else
-      @limit = 100
-    end
+    @objects = @objects.order(@orders.join ", ") if @orders.any?
     @objects = @objects.limit(@limit)
-
-    orders = []
-
-    if params[:offset]
-      begin
-        @objects = @objects.offset(params[:offset].to_i)
-        @offset = params[:offset].to_i
-      rescue
-        raise ArgumentError.new("Invalid value for limit parameter")
-      end
-    else
-      @offset = 0
-    end
-
-    orders = []
-    if params[:order]
-      params[:order].split(',').each do |order|
-        attr, direction = order.strip.split " "
-        direction ||= 'asc'
-        if attr.match /^[a-z][_a-z0-9]+$/ and
-            model_class.columns.collect(&:name).index(attr) and
-            ['asc','desc'].index direction.downcase
-          orders << "#{table_name}.#{attr} #{direction.downcase}"
-        end
-      end
-    end
-    if orders.empty?
-      orders << "#{table_name}.modified_at desc"
-    end
-    @objects = @objects.order(orders.join ", ")
+    @objects = @objects.offset(@offset)
   end
 
   def resource_attrs
@@ -404,6 +455,10 @@ class ApplicationController < ActionController::Base
       params[:uuid] = params.delete :id
     end
     @where = { uuid: params[:uuid] }
+    @offset = 0
+    @limit = 1
+    @orders = []
+    @filters = []
     find_objects_for_index
     @object = @objects.first
   end
diff --git a/services/api/config/routes.rb b/services/api/config/routes.rb
index 211701a..cfd3b61 100644
--- a/services/api/config/routes.rb
+++ b/services/api/config/routes.rb
@@ -107,9 +107,13 @@ Server::Application.routes.draw do
       resources :pipeline_templates
       resources :pipeline_instances
       resources :specimens
-      resources :groups
+      resources :groups do
+        get 'owned_items', on: :member
+      end
       resources :logs
-      resources :users
+      resources :users do
+        get 'owned_items', on: :member
+      end
       resources :api_clients
       resources :api_client_authorizations
       resources :jobs
diff --git a/services/api/test/functional/arvados/v1/groups_controller_test.rb b/services/api/test/functional/arvados/v1/groups_controller_test.rb
index 1264997..5b0fd59 100644
--- a/services/api/test/functional/arvados/v1/groups_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/groups_controller_test.rb
@@ -27,4 +27,51 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
     assert_not_nil group_uuids.index groups(:asubfolder).uuid
   end
 
+  test 'get group-owned objects' do
+    authorize_with :active
+    get :owned_items, {
+      id: groups(:afolder).uuid,
+      format: :json,
+    }
+    assert_response :success
+    assert_operator 2, :<=, jresponse['items_available']
+    assert_operator 2, :<=, jresponse['items'].count
+  end
+
+  test 'get group-owned objects with limit' do
+    authorize_with :active
+    get :owned_items, {
+      id: groups(:afolder).uuid,
+      limit: 1,
+      format: :json,
+    }
+    assert_response :success
+    assert_operator 1, :<, jresponse['items_available']
+    assert_equal 1, jresponse['items'].count
+  end
+
+  test 'get group-owned objects with limit and offset' do
+    authorize_with :active
+    get :owned_items, {
+      id: groups(:afolder).uuid,
+      limit: 1,
+      offset: 12345,
+      format: :json,
+    }
+    assert_response :success
+    assert_operator 1, :<, jresponse['items_available']
+    assert_equal 0, jresponse['items'].count
+  end
+
+  test 'get group-owned objects with additional filter matching nothing' do
+    authorize_with :active
+    get :owned_items, {
+      id: groups(:afolder).uuid,
+      filters: [['uuid', 'in', ['foo_not_a_uuid','bar_not_a_uuid']]],
+      format: :json,
+    }
+    assert_response :success
+    assert_equal [], jresponse['items']
+    assert_equal 0, jresponse['items_available']
+  end
 end
diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb
index 6dc5950..c466e90 100644
--- a/services/api/test/functional/arvados/v1/users_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/users_controller_test.rb
@@ -880,4 +880,19 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
                                tail_uuid: system_group_uuid,
                                head_uuid: user_uuid).count
   end
+
+  test 'get user-owned objects' do
+    authorize_with :active
+    get :owned_items, {
+      id: users(:active).uuid,
+      format: :json,
+    }
+    assert_response :success
+    assert_operator 2, :<=, jresponse['items_available']
+    assert_operator 2, :<=, jresponse['items'].count
+    kinds = jresponse['items'].collect { |i| i['kind'] }.uniq
+    expect_kinds = %w'arvados#group arvados#specimen arvados#pipelineTemplate arvados#job'
+    assert_equal expect_kinds, (expect_kinds & kinds)
+  end
+
 end

commit 61f4536217e0beeafab54a8b66d40f859fdd1306
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 15:46:19 2014 -0400

    Fill in "I'm in a folder" fixtures

diff --git a/services/api/test/fixtures/groups.yml b/services/api/test/fixtures/groups.yml
index 7b215ef..ce04ece 100644
--- a/services/api/test/fixtures/groups.yml
+++ b/services/api/test/fixtures/groups.yml
@@ -47,6 +47,11 @@ testusergroup_admins:
 afolder:
   uuid: zzzzz-j7d0g-v955i6s2oi1cbso
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2014-04-21 15:37:48 -0400
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  modified_at: 2014-04-21 15:37:48 -0400
+  updated_at: 2014-04-21 15:37:48 -0400
   name: A Folder
   description: Test folder belonging to active user
   group_class: folder
@@ -54,6 +59,11 @@ afolder:
 asubfolder:
   uuid: zzzzz-j7d0g-axqo7eu9pwvna1x
   owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+  created_at: 2014-04-21 15:37:48 -0400
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  modified_at: 2014-04-21 15:37:48 -0400
+  updated_at: 2014-04-21 15:37:48 -0400
   name: A Subfolder
   description: Test folder belonging to active user's first test folder
   group_class: folder
diff --git a/services/api/test/fixtures/links.yml b/services/api/test/fixtures/links.yml
index fc3f23d..46f4afe 100644
--- a/services/api/test/fixtures/links.yml
+++ b/services/api/test/fixtures/links.yml
@@ -289,3 +289,17 @@ test_timestamps:
   link_class: test
   name: test
   properties: {}
+
+specimen_is_in_two_folders:
+  uuid: zzzzz-o0j2j-ryhm1bn83ni03sn
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  created_at: 2014-04-21 15:37:48 -0400
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  modified_at: 2014-04-21 15:37:48 -0400
+  updated_at: 2014-04-21 15:37:48 -0400
+  tail_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+  head_uuid: zzzzz-2x53u-5gid26432uujf79
+  link_class: permission
+  name: can_manage
+  properties: {}
diff --git a/services/api/test/fixtures/specimens.yml b/services/api/test/fixtures/specimens.yml
index 26e9bc1..6ad7cfe 100644
--- a/services/api/test/fixtures/specimens.yml
+++ b/services/api/test/fixtures/specimens.yml
@@ -17,3 +17,7 @@ in_afolder:
 in_asubfolder:
   uuid: zzzzz-2x53u-c40lddwcqqr1ffs
   owner_uuid: zzzzz-j7d0g-axqo7eu9pwvna1x
+
+in_afolder_linked_from_asubfolder:
+  uuid: zzzzz-2x53u-5gid26432uujf79
+  owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso

commit 04e99ad773e4a47dabc7f0e1b624f67a00ff00b9
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 15:43:34 2014 -0400

    Improve permission link examples.

diff --git a/doc/api/schema/Link.html.textile.liquid b/doc/api/schema/Link.html.textile.liquid
index dec33bf..6209a8c 100644
--- a/doc/api/schema/Link.html.textile.liquid
+++ b/doc/api/schema/Link.html.textile.liquid
@@ -51,9 +51,11 @@ h3. permission
 
 table(table table-bordered table-condensed).
 |_. tail_type→head_type|_. name→head_uuid {properties}|_. Notes|
-|User→Group  |can_manage → _group uuid_|Writable only by a user who can_manage this group|
-|User→Group  |can_read → _group uuid_  |Writable only by a user who can_manage this group.
-Gives permission to read any object owned by this group.|
+|User→Group  |{white-space:nowrap}. can_manage → _group uuid_|The User can read, write, and control permissions on the Group itself, every object owned by the Group, and every object on which the Group has _can_manage_ permission.|
+|User→Group  |can_read → _group uuid_  |The User can retrieve the Group itself and every object that is readable by the Group.|
+|User→Job|can_write → _job uuid_  |The User can read and update the Job. (This works for all object types, not just jobs.)|
+|User→Job|can_manage → _job uuid_  |The User can read, update, and change permissions for the Job. (This works for all object types, not just jobs.)|
+|Group→Job|can_manage → _job uuid_  |Anyone with _can_manage_ permission on the Group can also read, update, and change permissions for the Job. Anyone with _can_read_ permission on the Group can read the Job. (This works for all object types, not just jobs.)|
 
 h3. resources
 

commit 6f6c9a2c6e7b871ad9ee592f45ebfdb7f5f26ee1
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 13:46:30 2014 -0400

    Add some test fixtures that are owned by folders.

diff --git a/services/api/test/fixtures/specimens.yml b/services/api/test/fixtures/specimens.yml
index 070a5fe..26e9bc1 100644
--- a/services/api/test/fixtures/specimens.yml
+++ b/services/api/test/fixtures/specimens.yml
@@ -9,3 +9,11 @@ owned_by_private_group:
 owned_by_spectator:
   uuid: zzzzz-2x53u-3b0xxwzlbzxq5yr
   owner_uuid: zzzzz-tpzed-l1s2piq4t4mps8r
+
+in_afolder:
+  uuid: zzzzz-2x53u-7r18rnd5nzhg5yk
+  owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+
+in_asubfolder:
+  uuid: zzzzz-2x53u-c40lddwcqqr1ffs
+  owner_uuid: zzzzz-j7d0g-axqo7eu9pwvna1x

commit deed6e331c70c4410b161f260e2b93fa71b39d50
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 12:15:56 2014 -0400

    Set :null=>false explicitly on timestamp columns.
    
    New versions of Rails do this automatically, but dev instances keep
    having edit wars because some of them have never been told to add the
    not-null constraint.

diff --git a/services/api/db/migrate/20140421151940_timestamps_not_null.rb b/services/api/db/migrate/20140421151940_timestamps_not_null.rb
new file mode 100644
index 0000000..e4ca19e
--- /dev/null
+++ b/services/api/db/migrate/20140421151940_timestamps_not_null.rb
@@ -0,0 +1,13 @@
+class TimestampsNotNull < ActiveRecord::Migration
+  def up
+    ActiveRecord::Base.connection.tables.each do |t|
+      next if t == 'schema_migrations'
+      change_column t.to_sym, :created_at, :datetime, :null => false
+      change_column t.to_sym, :updated_at, :datetime, :null => false
+    end
+  end
+  def down
+    # There might have been a NULL constraint before this, depending
+    # on the version of Rails used to build the database.
+  end
+end
diff --git a/services/api/db/schema.rb b/services/api/db/schema.rb
index 59963de..373c279 100644
--- a/services/api/db/schema.rb
+++ b/services/api/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20140421140924) do
+ActiveRecord::Schema.define(:version => 20140421151940) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",                                           :null => false
@@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
   create_table "collections", :force => true do |t|
     t.string   "locator"
     t.string   "owner_uuid"
-    t.datetime "created_at"
+    t.datetime "created_at",                          :null => false
     t.string   "modified_by_client_uuid"
     t.string   "modified_by_user_uuid"
     t.datetime "modified_at"
@@ -80,7 +80,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.string   "redundancy_confirmed_by_client_uuid"
     t.datetime "redundancy_confirmed_at"
     t.integer  "redundancy_confirmed_as"
-    t.datetime "updated_at"
+    t.datetime "updated_at",                          :null => false
     t.string   "uuid"
     t.text     "manifest_text"
   end
@@ -104,8 +104,8 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.string   "repository_name"
     t.string   "sha1"
     t.string   "message"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",      :null => false
+    t.datetime "updated_at",      :null => false
   end
 
   add_index "commits", ["repository_name", "sha1"], :name => "index_commits_on_repository_name_and_sha1", :unique => true
@@ -135,8 +135,8 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.string   "modified_by_user_uuid"
     t.datetime "modified_at"
     t.text     "properties"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",              :null => false
+    t.datetime "updated_at",              :null => false
   end
 
   add_index "humans", ["uuid"], :name => "index_humans_on_uuid", :unique => true
@@ -184,8 +184,8 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.boolean  "running"
     t.boolean  "success"
     t.string   "output"
-    t.datetime "created_at"
-    t.datetime "updated_at"
+    t.datetime "created_at",                                  :null => false
+    t.datetime "updated_at",                                  :null => false
     t.string   "priority"
     t.string   "is_locked_by_uuid"
     t.string   "log"
@@ -237,7 +237,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
   create_table "links", :force => true do |t|
     t.string   "uuid"
     t.string   "owner_uuid"
-    t.datetime "created_at"
+    t.datetime "created_at",              :null => false
     t.string   "modified_by_client_uuid"
     t.string   "modified_by_user_uuid"
     t.datetime "modified_at"
@@ -246,7 +246,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.string   "name"
     t.string   "head_uuid"
     t.text     "properties"
-    t.datetime "updated_at"
+    t.datetime "updated_at",              :null => false
   end
 
   add_index "links", ["created_at"], :name => "index_links_on_created_at"
@@ -304,7 +304,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
   create_table "pipeline_instances", :force => true do |t|
     t.string   "uuid"
     t.string   "owner_uuid"
-    t.datetime "created_at"
+    t.datetime "created_at",                                 :null => false
     t.string   "modified_by_client_uuid"
     t.string   "modified_by_user_uuid"
     t.datetime "modified_at"
@@ -313,7 +313,7 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.text     "components"
     t.boolean  "success"
     t.boolean  "active",                  :default => false
-    t.datetime "updated_at"
+    t.datetime "updated_at",                                 :null => false
     t.text     "properties"
   end
 

commit 44480d99e71e1868f61024035d7d58acd69eac50
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 11:32:35 2014 -0400

    Remove _kind columns from schema.
    
    (Seemingly reintroduced by accident in
    cc5023d40182e503e8ba109fc86e09efd6337836)

diff --git a/services/api/db/schema.rb b/services/api/db/schema.rb
index e8268fc..59963de 100644
--- a/services/api/db/schema.rb
+++ b/services/api/db/schema.rb
@@ -247,8 +247,6 @@ ActiveRecord::Schema.define(:version => 20140421140924) do
     t.string   "head_uuid"
     t.text     "properties"
     t.datetime "updated_at"
-    t.string   "head_kind"
-    t.string   "tail_kind"
   end
 
   add_index "links", ["created_at"], :name => "index_links_on_created_at"

commit 448cff33fc343a54caa1a33f4a536d88e3e4eaa1
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 11:16:33 2014 -0400

    Expose generate_uuid class method, e.g., for making test fixtures.

diff --git a/services/api/lib/assign_uuid.rb b/services/api/lib/assign_uuid.rb
index 1c4ca81..50738aa 100644
--- a/services/api/lib/assign_uuid.rb
+++ b/services/api/lib/assign_uuid.rb
@@ -9,6 +9,12 @@ module AssignUuid
     def uuid_prefix
       Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[-5..-1]
     end
+    def generate_uuid
+      [Server::Application.config.uuid_prefix,
+       self.uuid_prefix,
+       rand(2**256).to_s(36)[-15..-1]].
+        join '-'
+    end
   end
 
   protected
@@ -20,9 +26,6 @@ module AssignUuid
   def assign_uuid
     return true if !self.respond_to_uuid?
     return true if uuid and current_user and current_user.is_admin
-    self.uuid = [Server::Application.config.uuid_prefix,
-                 self.class.uuid_prefix,
-                 rand(2**256).to_s(36)[-15..-1]].
-      join '-'
+    self.uuid = self.class.generate_uuid
   end
 end

commit 5588c452453499d0aa130abe6421df5e85cf5703
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 21 11:00:10 2014 -0400

    Add group_class attribute.

diff --git a/doc/api/schema/Group.html.textile.liquid b/doc/api/schema/Group.html.textile.liquid
index e0e092e..9d29ba0 100644
--- a/doc/api/schema/Group.html.textile.liquid
+++ b/doc/api/schema/Group.html.textile.liquid
@@ -6,9 +6,7 @@ title: Group
 
 ...
 
-
-
-A **Group** represents...
+A **Group** represents a set of objects. Groups allow you to organize content, define user roles, and apply permissions to sets of objects.
 
 h2. Methods
 
@@ -33,5 +31,6 @@ Each Group has, in addition to the usual "attributes of Arvados resources":{{sit
 table(table table-bordered table-condensed).
 |_. Attribute|_. Type|_. Description|_. Example|
 |name|string|||
+|group_class|string|Type of group. This does not affect behavior, but determines how the group is presented in the user interface.|@folder@|
 |description|text|||
 |updated_at|datetime|||
diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb
index 9666257..7391df5 100644
--- a/services/api/app/models/group.rb
+++ b/services/api/app/models/group.rb
@@ -5,6 +5,7 @@ class Group < ArvadosModel
 
   api_accessible :user, extend: :common do |t|
     t.add :name
+    t.add :group_class
     t.add :description
   end
 end
diff --git a/services/api/db/migrate/20140421140924_add_group_class_to_groups.rb b/services/api/db/migrate/20140421140924_add_group_class_to_groups.rb
new file mode 100644
index 0000000..de52983
--- /dev/null
+++ b/services/api/db/migrate/20140421140924_add_group_class_to_groups.rb
@@ -0,0 +1,6 @@
+class AddGroupClassToGroups < ActiveRecord::Migration
+  def change
+    add_column :groups, :group_class, :string
+    add_index :groups, :group_class
+  end
+end
diff --git a/services/api/db/schema.rb b/services/api/db/schema.rb
index e2301e5..e8268fc 100644
--- a/services/api/db/schema.rb
+++ b/services/api/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20140407184311) do
+ActiveRecord::Schema.define(:version => 20140421140924) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",                                           :null => false
@@ -120,9 +120,11 @@ ActiveRecord::Schema.define(:version => 20140407184311) do
     t.string   "name"
     t.text     "description"
     t.datetime "updated_at",              :null => false
+    t.string   "group_class"
   end
 
   add_index "groups", ["created_at"], :name => "index_groups_on_created_at"
+  add_index "groups", ["group_class"], :name => "index_groups_on_group_class"
   add_index "groups", ["modified_at"], :name => "index_groups_on_modified_at"
   add_index "groups", ["uuid"], :name => "index_groups_on_uuid", :unique => true
 
diff --git a/services/api/test/fixtures/groups.yml b/services/api/test/fixtures/groups.yml
index c2f2dde..7b215ef 100644
--- a/services/api/test/fixtures/groups.yml
+++ b/services/api/test/fixtures/groups.yml
@@ -43,3 +43,17 @@ testusergroup_admins:
   uuid: zzzzz-j7d0g-48foin4vonvc2at
   owner_uuid: zzzzz-tpzed-000000000000000
   name: Administrators of a subset of users
+
+afolder:
+  uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+  owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  name: A Folder
+  description: Test folder belonging to active user
+  group_class: folder
+
+asubfolder:
+  uuid: zzzzz-j7d0g-axqo7eu9pwvna1x
+  owner_uuid: zzzzz-j7d0g-v955i6s2oi1cbso
+  name: A Subfolder
+  description: Test folder belonging to active user's first test folder
+  group_class: folder
diff --git a/services/api/test/functional/arvados/v1/groups_controller_test.rb b/services/api/test/functional/arvados/v1/groups_controller_test.rb
index 2e3d6b8..1264997 100644
--- a/services/api/test/functional/arvados/v1/groups_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/groups_controller_test.rb
@@ -14,4 +14,17 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
     assert_response 403
   end
 
+  test "get list of folders" do
+    authorize_with :active
+    get :index, filters: [['group_class', '=', 'folder']], format: :json
+    assert_response :success
+    group_uuids = []
+    jresponse['items'].each do |group|
+      assert_equal 'folder', group['group_class']
+      group_uuids << group['uuid']
+    end
+    assert_not_nil group_uuids.index groups(:afolder).uuid
+    assert_not_nil group_uuids.index groups(:asubfolder).uuid
+  end
+
 end
diff --git a/services/api/test/test_helper.rb b/services/api/test/test_helper.rb
index a81bfdf..4a53b25 100644
--- a/services/api/test/test_helper.rb
+++ b/services/api/test/test_helper.rb
@@ -13,6 +13,10 @@ class ActiveSupport::TestCase
     self.request.headers["Accept"] = "text/json"
   end
 
+  def jresponse
+    @jresponse ||= ActiveSupport::JSON.decode @response.body
+  end
+
   def authorize_with(api_client_auth_name)
     self.request.env['HTTP_AUTHORIZATION'] = "OAuth2 #{api_client_authorizations(api_client_auth_name).api_token}"
   end
@@ -21,9 +25,6 @@ class ActiveSupport::TestCase
 end
 
 class ActionDispatch::IntegrationTest
-  def jresponse
-    @jresponse ||= ActiveSupport::JSON.decode @response.body
-  end
   def auth auth_fixture
     {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(auth_fixture).api_token}"}
   end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list