Add tests, rename include_indirect to _linked, improve wording in
authorTom Clegg <tom@curoverse.com>
Wed, 23 Apr 2014 20:39:03 +0000 (16:39 -0400)
committerTom Clegg <tom@curoverse.com>
Wed, 23 Apr 2014 20:39:03 +0000 (16:39 -0400)
docs, improve offset/limit validation

doc/api/methods/groups.html.textile.liquid
doc/api/methods/users.html.textile.liquid
doc/api/schema/Group.html.textile.liquid
doc/api/schema/Link.html.textile.liquid
services/api/app/controllers/application_controller.rb
services/api/test/functional/arvados/v1/groups_controller_test.rb
services/api/test/functional/arvados/v1/users_controller_test.rb

index bf8b0be91efaf011ee1637dabaab7837391ddc17..7f52bc7a532fe4a4dfde77d9b6288e08157d5287 100644 (file)
@@ -85,7 +85,7 @@ Arguments:
 table(table table-bordered table-condensed).
 |_. Argument |_. Type |_. Description |_. Location |_. Example |
 {background:#ccffcc}.|uuid|string|The UUID of the group in question.|path||
-|include_indirect|boolean|If true, results will include items on which the given group has _can_manage_ permission, although they are owned by different users/groups.|path|{white-space:nowrap}. @false@ (default)
+|include_linked|boolean|If true, results will also include items on which the given group has _can_manage_ permission, even if they are owned by different users/groups.|path|{white-space:nowrap}. @false@ (default)
 @true@|
 
 h2. show
index 8908ab0081b3bf4a71839025811cee11a087875d..5fcc4c897676aa9b18937bd5e315a2de4f71b3ba 100644 (file)
@@ -104,7 +104,7 @@ Arguments:
 table(table table-bordered table-condensed).
 |_. Argument |_. Type |_. Description |_. Location |_. Example |
 {background:#ccffcc}.|uuid|string|The UUID of the user in question.|path||
-|include_indirect|boolean|If true, results will include items on which the given user has _can_manage_ permission, although they are owned by different users/groups.|path|{white-space:nowrap}. @false@ (default)
+|include_linked|boolean|If true, results will also include items on which the given user has _can_manage_ permission, even if they are owned by different users/groups.|path|{white-space:nowrap}. @false@ (default)
 @true@|
 
 h2. show
index 9d29ba0efa8b94acb19c4a7d25af90f2b92eddc2..624a930ae195446bdf67a3ce913316b0f829e957 100644 (file)
@@ -31,6 +31,7 @@ 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@|
+|group_class|string|Type of group. This does not affect behavior, but determines how the group is presented in the user interface. For example, @folder@ indicates that the group should be displayed by Workbench and arv-mount as a folder for organizing and naming objects.|@"folder"@
+null|
 |description|text|||
 |updated_at|datetime|||
index 6209a8c4ef66107484e93be63351df6b87d56e99..5660bec4b18026f2198763f3cfa7cb2fcb7fd44a 100644 (file)
@@ -53,9 +53,9 @@ table(table table-bordered table-condensed).
 |_. tail_type&rarr;head_type|_. name&rarr;head_uuid {properties}|_. Notes|
 |User&rarr;Group  |{white-space:nowrap}. can_manage &rarr; _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&rarr;Group  |can_read &rarr; _group uuid_  |The User can retrieve the Group itself and every object that is readable by the Group.|
-|User&rarr;Job|can_write &rarr; _job uuid_  |The User can read and update the Job. (This works for all object types, not just jobs.)|
-|User&rarr;Job|can_manage &rarr; _job uuid_  |The User can read, update, and change permissions for the Job. (This works for all object types, not just jobs.)|
-|Group&rarr;Job|can_manage &rarr; _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.)|
+|User&rarr;Job|can_write &rarr; _job uuid_  |The User can read and update the Job. (This works for all objects, not just jobs.)|
+|User&rarr;Job|can_manage &rarr; _job uuid_  |The User can read, update, and change permissions for the Job. (This works for all objects, not just jobs.)|
+|Group&rarr;Job|can_manage &rarr; _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 objects, not just jobs.)|
 
 h3. resources
 
index 2e3c4ebd30bc595a2acad73dbfcda510a39cc342..77a40713d5fed505e546514dc5ae0944e132d2e9 100644 (file)
@@ -62,7 +62,7 @@ class ApplicationController < ActionController::Base
   def self._owned_items_requires_parameters
     _index_requires_parameters.
       merge({
-              include_indirect: {
+              include_linked: {
                 type: 'boolean', required: false, default: false
               },
             })
@@ -72,10 +72,6 @@ class ApplicationController < ActionController::Base
     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 = {}
-
     # Trick apply_where_limit_order_params into applying suitable
     # per-table values. *_all are the real ones we'll apply to the
     # aggregate set.
@@ -98,7 +94,7 @@ class ApplicationController < ActionController::Base
         @objects = klass.readable_by(current_user)
         cond_sql = "#{klass.table_name}.owner_uuid = ?"
         cond_params = [@object.uuid]
-        if params[:include_indirect]
+        if params[:include_linked]
           @objects = @objects.
             joins("LEFT JOIN links mng_links"\
                   " ON mng_links.link_class=#{klass.sanitize 'permission'}"\
@@ -213,21 +209,19 @@ class ApplicationController < ActionController::Base
 
   def load_limit_offset_order_params
     if params[:limit]
-      begin
-        @limit = params[:limit].to_i
-      rescue
+      unless params[:limit].to_s.match(/^\d+$/)
         raise ArgumentError.new("Invalid value for limit parameter")
       end
+      @limit = params[:limit].to_i
     else
       @limit = DEFAULT_LIMIT
     end
 
     if params[:offset]
-      begin
-        @offset = params[:offset].to_i
-      rescue
+      unless params[:offset].to_s.match(/^\d+$/)
         raise ArgumentError.new("Invalid value for offset parameter")
       end
+      @offset = params[:offset].to_i
     else
       @offset = 0
     end
index d9cbac0a129b252df1713df992bf50bc3dc9ba25..017984c2f522cc56b04ac4d3969414f37287a6c3 100644 (file)
@@ -23,8 +23,35 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
       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
+    assert_includes group_uuids, groups(:afolder).uuid
+    assert_includes group_uuids, groups(:asubfolder).uuid
+    assert_not_includes group_uuids, groups(:system_group).uuid
+    assert_not_includes group_uuids, groups(:private).uuid
+  end
+
+  test "get list of groups that are not folders" do
+    authorize_with :active
+    get :index, filters: [['group_class', '=', nil]], format: :json
+    assert_response :success
+    group_uuids = []
+    jresponse['items'].each do |group|
+      assert_equal nil, group['group_class']
+      group_uuids << group['uuid']
+    end
+    assert_not_includes group_uuids, groups(:afolder).uuid
+    assert_not_includes group_uuids, groups(:asubfolder).uuid
+    assert_includes group_uuids, groups(:private).uuid
+  end
+
+  test "get list of groups with bogus group_class" do
+    authorize_with :active
+    get :index, {
+      filters: [['group_class', '=', 'nogrouphasthislittleclass']],
+      format: :json,
+    }
+    assert_response :success
+    assert_equal [], jresponse['items']
+    assert_equal 0, jresponse['items_available']
   end
 
   test 'get group-owned objects' do
@@ -75,7 +102,7 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
     assert_equal 0, jresponse['items_available']
   end
 
-  test 'get group-owned objects without include_indirect' do
+  test 'get group-owned objects without include_linked' do
     unexpected_uuid = specimens(:in_afolder_linked_from_asubfolder).uuid
     authorize_with :active
     get :owned_items, {
@@ -87,12 +114,12 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase
     assert_equal nil, uuids.index(unexpected_uuid)
   end
 
-  test 'get group-owned objects with include_indirect' do
+  test 'get group-owned objects with include_linked' do
     expected_uuid = specimens(:in_afolder_linked_from_asubfolder).uuid
     authorize_with :active
     get :owned_items, {
       id: groups(:asubfolder).uuid,
-      include_indirect: true,
+      include_linked: true,
       format: :json,
     }
     assert_response :success
index 2639516f4b77242ed5a2a2ad10c86229738d4710..948b601f88f5e0b31215e5a62debf42653c0b5de 100644 (file)
@@ -897,7 +897,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
   end
 
   [false, true].each do |inc_ind|
-    test "get all pages of user-owned #{'and -indirect ' if inc_ind}objects" do
+    test "get all pages of user-owned #{'and -linked ' if inc_ind}objects" do
       authorize_with :active
       limit = 5
       offset = 0
@@ -910,7 +910,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
         @jresponse = nil
         get :owned_items, {
           id: users(:active).uuid,
-          include_indirect: inc_ind,
+          include_linked: inc_ind,
           limit: limit,
           offset: offset,
           format: :json,
@@ -938,7 +938,21 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
       end
       if inc_ind
         assert_operator 0, :<, (jresponse.keys - [users(:active).uuid]).count,
-        "Set include_indirect=true but did not receive any indirect items"
+        "Set include_linked=true but did not receive any non-owned items"
+      end
+    end
+  end
+
+  %w(offset limit).each do |arg|
+    ['foo', '', '1234five', '0x10', '-8'].each do |val|
+      test "Raise error on bogus #{arg} parameter #{val.inspect}" do
+        authorize_with :active
+        get :owned_items, {
+          :id => users(:active).uuid,
+          :format => :json,
+          arg => val,
+        }
+        assert_response 422
       end
     end
   end