3170: Merge branch 'master' into 3170-refresh-tab-pane
authorTom Clegg <tom@curoverse.com>
Mon, 21 Jul 2014 17:00:42 +0000 (13:00 -0400)
committerTom Clegg <tom@curoverse.com>
Mon, 21 Jul 2014 17:00:42 +0000 (13:00 -0400)
22 files changed:
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/views/application/_projects_tree_menu.html.erb
apps/workbench/app/views/layouts/application.html.erb
apps/workbench/test/functional/projects_controller_test.rb
sdk/python/.gitignore
sdk/python/MANIFEST.in [new file with mode: 0644]
sdk/python/README.rst [new file with mode: 0644]
sdk/python/requirements.txt [deleted file]
sdk/python/setup.py
sdk/python/tests/__init__.py [new file with mode: 0644]
sdk/python/tests/test_arv_put.py
services/api/app/controllers/user_sessions_controller.rb
services/api/app/models/api_client_authorization.rb
services/api/app/models/arvados_model.rb
services/api/test/fixtures/users.yml
services/api/test/unit/permission_test.rb
services/fuse/MANIFEST.in [new file with mode: 0644]
services/fuse/README.rst [new file with mode: 0644]
services/fuse/readme.llfuse [deleted file]
services/fuse/requirements.txt [deleted file]
services/fuse/setup.py
services/fuse/tests/__init__.py [new file with mode: 0644]

index 7d7ea9534b381b74cf27d7ac6bd15b9ce436c1fc..c32bac46bf5764d34dc930617e840c5b3d6850fc 100644 (file)
@@ -258,7 +258,7 @@ class ApplicationController < ActionController::Base
       if @object.name and @object.name != ''
         @object.name = "Copy of #{@object.name}"
       else
-        @object.name = "Copy of unnamed #{@object.class_for_display.downcase}"
+        @object.name = ""
       end
     end
     @object.save!
index 390ef772f930d2455360c3a31e6adad32f4cee24..33349129923ca5df8c26b41f226e12977befb642 100644 (file)
@@ -16,7 +16,7 @@
                   <% end %>
                 </li>
               <% end %>
-              <li class="divider">
+              <li class="divider" />
               <li role="presentation" class="dropdown-header">
                 Projects shared with me
               </li>
index 63de6c267e1b308dd8ffc5a8cd233ced20649169..ec2c98bdcb181d10f189c500e3e5972d96a6c773 100644 (file)
                     link_to(project_path(pnode[:object].uuid), data: {object_uuid: pnode[:object].uuid, name: 'name'}, &block)
                   end,
                   :top_button => Proc.new do %>
-                    <% link_to projects_path('project[owner_uuid]' => current_project_uuid), method: 'post', class: 'btn btn-xs btn-default pull-right' do %>
+                    <% link_to projects_path, method: 'post', class: 'btn btn-xs btn-default pull-right' do %>
                       <i class="fa fa-plus"></i> New project
                     <% end %>
                   <% end %>
index b338aa818687b92f9cadf5847f30ccd7dacaad35..a991cedd634022777b4d0627643290df66d2b183 100644 (file)
@@ -9,4 +9,23 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_template 'user_agreements/index',
     "Inactive user was not presented with a user agreement at the front page"
   end
+
+  [[:active, true],
+   [:project_viewer, false]].each do |which_user, should_show|
+    test "create subproject button #{'not ' unless should_show} shown to #{which_user}" do
+      readonly_project_uuid = api_fixture('groups')['aproject']['uuid']
+      get :show, {
+        id: readonly_project_uuid
+      }, session_for(which_user)
+      buttons = css_select('[data-method=post]').select do |el|
+        el.attributes['href'].match /project.*owner_uuid.*#{readonly_project_uuid}/
+      end
+      if should_show
+        assert_not_empty(buttons, "did not offer to create a subproject")
+      else
+        assert_empty(buttons.collect(&:to_s),
+                     "offered to create a subproject in a non-writable project")
+      end
+    end
+  end
 end
index 7f9c17b7433633f9447d0b3cc575fbe5c7182bca..090c08e4c22a7a2138ff7778db3293b2c17f0424 100644 (file)
@@ -1,4 +1,5 @@
 /build/
 /dist/
+/*.egg
 /*.egg-info
 /tmp
diff --git a/sdk/python/MANIFEST.in b/sdk/python/MANIFEST.in
new file mode 100644 (file)
index 0000000..9561fb1
--- /dev/null
@@ -0,0 +1 @@
+include README.rst
diff --git a/sdk/python/README.rst b/sdk/python/README.rst
new file mode 100644 (file)
index 0000000..10e01a4
--- /dev/null
@@ -0,0 +1,63 @@
+=====================
+Arvados Python Client
+=====================
+
+Overview
+--------
+
+This package provides the ``arvados`` module, an API client for
+Arvados_.  It also includes higher-level functions to help you write
+Crunch scripts, and command-line tools to store and retrieve data in
+the Keep storage server.
+
+.. _Arvados: https://arvados.org/
+
+Installation
+------------
+
+Installing under your user account
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This method lets you install the package without root access.
+However, other users on the same system won't be able to use it.
+
+1. Run ``pip install --user arvados-python-client``.
+
+2. In your shell configuration, make sure you add ``$HOME/.local/bin``
+   to your PATH environment variable.  For example, you could add the
+   command ``PATH=$PATH:$HOME/.local/bin`` to your ``.bashrc`` file.
+
+3. Reload your shell configuration.  For example, bash users could run
+   ``source ~/.bashrc``.
+
+Installing on Debian systems
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+1. Add this Arvados repository to your sources list::
+
+     deb http://apt.arvados.org/ wheezy main
+
+2. Update your package list.
+
+3. Install the ``python-arvados-python-client`` package.
+
+Configuration
+-------------
+
+This client software needs two pieces of information to connect to
+Arvados: the DNS name of the API server, and an API authorization
+token.  You can set these in environment variables, or the file
+``$HOME/.config/arvados/settings.conf``.  `The Arvados user
+documentation
+<http://doc.arvados.org/user/reference/api-tokens.html>`_ describes
+how to find this information in the Arvados Workbench, and install it
+on your system.
+
+Testing and Development
+-----------------------
+
+This package is one part of the Arvados source package, and it has
+integration tests to check interoperability with other Arvados
+components.  Our `hacking guide
+<https://arvados.org/projects/arvados/wiki/Hacking_Python_SDK>`_
+describes how to set up a development environment and run tests.
diff --git a/sdk/python/requirements.txt b/sdk/python/requirements.txt
deleted file mode 100644 (file)
index f9d7505..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-google-api-python-client>=1.2
-httplib2>=0.7
-python-gflags>=1.5
-urllib3>=1.3
-ws4py>=0.3
-PyYAML>=3.0
index 9f9c96284e3ae4a56ac587f917bfca6f72b811e1..2c51e8f1d0f6a5d56c06c73016ccf7ef1418f770 100644 (file)
@@ -1,8 +1,15 @@
+#!/usr/bin/env python
+
+import os
+
 from setuptools import setup, find_packages
 
+README = os.path.join(os.path.dirname(__file__), 'README.rst')
+
 setup(name='arvados-python-client',
       version='0.1',
       description='Arvados client library',
+      long_description=open(README).read(),
       author='Arvados',
       author_email='info@arvados.org',
       url="https://arvados.org",
@@ -24,4 +31,6 @@ setup(name='arvados-python-client',
         'urllib3',
         'ws4py'
         ],
+      test_suite='tests',
+      tests_require=['PyYAML'],
       zip_safe=False)
diff --git a/sdk/python/tests/__init__.py b/sdk/python/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 676e9b7f21a3bbd395afa4374fdf2906b69b0df4..1a107a5c3d48664444c9380deef43e16cf68c29e 100644 (file)
@@ -442,29 +442,6 @@ class ArvadosPutTest(ArvadosKeepLocalStoreTestCase):
             arv_put.ResumeCache.CACHE_DIR = orig_cachedir
             os.chmod(cachedir, 0o700)
 
-    def test_short_put_from_stdin(self):
-        # Have to run this separately since arv-put can't read from the
-        # tests' stdin.
-        # arv-put usually can't stat(os.path.realpath('/dev/stdin')) in this
-        # case, because the /proc entry is already gone by the time it tries.
-        pipe = subprocess.Popen(
-            [sys.executable, arv_put.__file__, '--stream'],
-            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-            stderr=subprocess.STDOUT)
-        pipe.stdin.write('stdin test\n')
-        pipe.stdin.close()
-        deadline = time.time() + 5
-        while (pipe.poll() is None) and (time.time() < deadline):
-            time.sleep(.1)
-        returncode = pipe.poll()
-        if returncode is None:
-            pipe.terminate()
-            self.fail("arv-put did not PUT from stdin within 5 seconds")
-        elif returncode != 0:
-            sys.stdout.write(pipe.stdout.read())
-            self.fail("arv-put returned exit code {}".format(returncode))
-        self.assertIn('4a9c8b735dce4b5fa3acf221a0b13628+11', pipe.stdout.read())
-
     def test_link_without_project_uuid_aborts(self):
         self.assertRaises(SystemExit, self.call_main_with_args,
                           ['--name', 'test without project UUID', '/dev/null'])
@@ -476,6 +453,8 @@ class ArvadosPutTest(ArvadosKeepLocalStoreTestCase):
 
 class ArvPutIntegrationTest(unittest.TestCase):
     PROJECT_UUID = run_test_server.fixture('groups')['aproject']['uuid']
+    ENVIRON = os.environ
+    ENVIRON['PYTHONPATH'] = ':'.join(sys.path)
 
     @classmethod
     def setUpClass(cls):
@@ -524,6 +503,29 @@ class ArvPutIntegrationTest(unittest.TestCase):
         else:
             self.assertFalse(result, "incorrectly found nonexistent project")
 
+    def test_short_put_from_stdin(self):
+        # Have to run this as an integration test since arv-put can't
+        # read from the tests' stdin.
+        # arv-put usually can't stat(os.path.realpath('/dev/stdin')) in this
+        # case, because the /proc entry is already gone by the time it tries.
+        pipe = subprocess.Popen(
+            [sys.executable, arv_put.__file__, '--stream'],
+            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT, env=self.ENVIRON)
+        pipe.stdin.write('stdin test\n')
+        pipe.stdin.close()
+        deadline = time.time() + 5
+        while (pipe.poll() is None) and (time.time() < deadline):
+            time.sleep(.1)
+        returncode = pipe.poll()
+        if returncode is None:
+            pipe.terminate()
+            self.fail("arv-put did not PUT from stdin within 5 seconds")
+        elif returncode != 0:
+            sys.stdout.write(pipe.stdout.read())
+            self.fail("arv-put returned exit code {}".format(returncode))
+        self.assertIn('4a9c8b735dce4b5fa3acf221a0b13628+11', pipe.stdout.read())
+
     def test_ArvPutSignedManifest(self):
         # ArvPutSignedManifest runs "arv-put foo" and then attempts to get
         # the newly created manifest from the API server, testing to confirm
@@ -541,7 +543,7 @@ class ArvPutIntegrationTest(unittest.TestCase):
         with open(os.path.join(datadir, "foo"), "w") as f:
             f.write("The quick brown fox jumped over the lazy dog")
         p = subprocess.Popen([sys.executable, arv_put.__file__, datadir],
-                             stdout=subprocess.PIPE)
+                             stdout=subprocess.PIPE, env=self.ENVIRON)
         (arvout, arverr) = p.communicate()
         self.assertEqual(p.returncode, 0)
         self.assertEqual(arverr, None)
@@ -562,8 +564,8 @@ class ArvPutIntegrationTest(unittest.TestCase):
         pipe = subprocess.Popen(
             [sys.executable, arv_put.__file__,
              '--project-uuid', self.PROJECT_UUID] + extra_args,
-            stdin=subprocess.PIPE,
-            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE, env=self.ENVIRON)
         stdout, stderr = pipe.communicate(text)
         link_list = arvados.api('v1', cache=False).links().list(
             filters=[['head_uuid', '=', stdout.strip()],
index 0b80877bc25624e9b66a38f8c0c35c75b468cc0f..696ae026c597069a044ca0584feb5c9a609d48f1 100644 (file)
@@ -42,7 +42,11 @@ class UserSessionsController < ApplicationController
                       :first_name => omniauth['info']['first_name'],
                       :last_name => omniauth['info']['last_name'],
                       :identity_url => omniauth['info']['identity_url'],
-                      :is_active => Rails.configuration.new_users_are_active)
+                      :is_active => Rails.configuration.new_users_are_active,
+                      :owner_uuid => system_user_uuid)
+      act_as_system_user do
+        user.save or raise Exception.new(user.errors.messages)
+      end
     else
       user.email = omniauth['info']['email']
       user.first_name = omniauth['info']['first_name']
index 82dd0ec2b6177847f72460b87b492950b66a605a..5817ff6648f933d15d34f8c91064bf778712a964 100644 (file)
@@ -30,7 +30,7 @@ class ApiClientAuthorization < ArvadosModel
     self.user.andand.uuid
   end
   def owner_uuid_was
-    self.user_id_changed? ? User.find(self.user_id_was).andand.uuid : self.user.andand.uuid
+    self.user_id_changed? ? User.where(id: self.user_id_was).first.andand.uuid : self.user.andand.uuid
   end
   def owner_uuid_changed?
     self.user_id_changed?
index 1ea9332484e793f3d069a03fd8e0cc4605e59dd5..5cd0c77c496b973e90026d6d77d25ccff3991b72 100644 (file)
@@ -206,29 +206,25 @@ class ArvadosModel < ActiveRecord::Base
 
   def ensure_owner_uuid_is_permitted
     raise PermissionDeniedError if !current_user
-    if respond_to? :owner_uuid=
+    if new_record? and respond_to? :owner_uuid=
       self.owner_uuid ||= current_user.uuid
     end
-    if self.owner_uuid_changed?
-      if new_record?
-        return true
-      elsif current_user.uuid == self.owner_uuid or
-          current_user.can? write: self.owner_uuid
-        # current_user is, or has :write permission on, the new owner
-      else
-        logger.warn "User #{current_user.uuid} tried to change owner_uuid of #{self.class.to_s} #{self.uuid} to #{self.owner_uuid} but does not have permission to write to #{self.owner_uuid}"
-        raise PermissionDeniedError
-      end
-    end
-    if new_record?
-      return true
-    elsif current_user.uuid == self.owner_uuid_was or
+    # Verify permission to write to old owner (unless owner_uuid was
+    # nil -- or hasn't changed, in which case the following
+    # "permission to write to new owner" block will take care of us)
+    unless !owner_uuid_changed? or
+        owner_uuid_was.nil? or
+        current_user.uuid == self.owner_uuid_was or
         current_user.uuid == self.uuid or
         current_user.can? write: self.owner_uuid_was
-      # current user is, or has :write permission on, the previous owner
-      return true
-    else
-      logger.warn "User #{current_user.uuid} tried to modify #{self.class.to_s} #{self.uuid} but does not have permission to write #{self.owner_uuid_was}"
+      logger.warn "User #{current_user.uuid} tried to modify #{self.class.to_s} #{uuid} but does not have permission to write old owner_uuid #{owner_uuid_was}"
+      errors.add :owner_uuid, "cannot be changed without write permission on old owner"
+      raise PermissionDeniedError
+    end
+    # Verify permission to write to new owner
+    unless current_user == self or current_user.can? write: owner_uuid
+      logger.warn "User #{current_user.uuid} tried to modify #{self.class.to_s} #{uuid} but does not have permission to write new owner_uuid #{owner_uuid}"
+      errors.add :owner_uuid, "cannot be changed without write permission on new owner"
       raise PermissionDeniedError
     end
   end
index f6d5b21f2e4f640030809ed8d13972fde5ce62cb..72a5aa3cc14c139ee1cdc1a3f65aab9c779c6dce 100644 (file)
@@ -1,6 +1,7 @@
 # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
 
 admin:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-d9tiejq69daie8f
   email: admin@arvados.local
   first_name: TestCase
@@ -11,6 +12,7 @@ admin:
   prefs: {}
 
 miniadmin:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-2bg9x0oeydcw5hm
   email: miniadmin@arvados.local
   first_name: TestCase
@@ -21,6 +23,7 @@ miniadmin:
   prefs: {}
 
 rominiadmin:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-4hvxm4n25emegis
   email: rominiadmin@arvados.local
   first_name: TestCase
@@ -31,6 +34,7 @@ rominiadmin:
   prefs: {}
 
 active:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-xurymjxw79nv3jz
   email: active-user@arvados.local
   first_name: Active
@@ -41,6 +45,7 @@ active:
   prefs: {}
 
 project_viewer:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-projectviewer1a
   email: project-viewer@arvados.local
   first_name: Project
@@ -51,6 +56,7 @@ project_viewer:
   prefs: {}
 
 spectator:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-l1s2piq4t4mps8r
   email: spectator@arvados.local
   first_name: Spect
@@ -61,6 +67,7 @@ spectator:
   prefs: {}
 
 inactive_uninvited:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-rf2ec3ryh4vb5ma
   email: inactive-uninvited-user@arvados.local
   first_name: Inactive and Uninvited
@@ -71,6 +78,7 @@ inactive_uninvited:
   prefs: {}
 
 inactive:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-x9kqpd79egh49c7
   email: inactive-user@arvados.local
   first_name: Inactive
@@ -81,6 +89,7 @@ inactive:
   prefs: {}
 
 inactive_but_signed_user_agreement:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-7sg468ezxwnodxs
   email: inactive-user-signed-ua@arvados.local
   first_name: Inactive But Agreeable
@@ -91,6 +100,7 @@ inactive_but_signed_user_agreement:
   prefs: {}
 
 anonymous:
+  owner_uuid: zzzzz-tpzed-000000000000000
   uuid: zzzzz-tpzed-anonymouspublic
   email: anonymouspublic
   first_name: anonymouspublic
index 748c7907a29ec4dcc2ca2775ae5dfeb2c0056a98..1ea1419147686e5117e0f5d2b794777f350854d7 100644 (file)
@@ -131,4 +131,35 @@ class PermissionTest < ActiveSupport::TestCase
       perm_link.save
     end
   end
+
+  test "cannot create with owner = unwritable user" do
+    set_user_from_auth :rominiadmin
+    assert_raises ArvadosModel::PermissionDeniedError, "created with owner = unwritable user" do
+      Specimen.create!(owner_uuid: users(:active).uuid)
+    end
+  end
+
+  test "cannot change owner to unwritable user" do
+    set_user_from_auth :rominiadmin
+    ob = Specimen.create!
+    assert_raises ArvadosModel::PermissionDeniedError, "changed owner to unwritable user" do
+      ob.update_attributes!(owner_uuid: users(:active).uuid)
+    end
+  end
+
+  test "cannot create with owner = unwritable group" do
+    set_user_from_auth :rominiadmin
+    assert_raises ArvadosModel::PermissionDeniedError, "created with owner = unwritable group" do
+      Specimen.create!(owner_uuid: groups(:aproject).uuid)
+    end
+  end
+
+  test "cannot change owner to unwritable group" do
+    set_user_from_auth :rominiadmin
+    ob = Specimen.create!
+    assert_raises ArvadosModel::PermissionDeniedError, "changed owner to unwritable group" do
+      ob.update_attributes!(owner_uuid: groups(:aproject).uuid)
+    end
+  end
+
 end
diff --git a/services/fuse/MANIFEST.in b/services/fuse/MANIFEST.in
new file mode 100644 (file)
index 0000000..9561fb1
--- /dev/null
@@ -0,0 +1 @@
+include README.rst
diff --git a/services/fuse/README.rst b/services/fuse/README.rst
new file mode 100644 (file)
index 0000000..d9a9a07
--- /dev/null
@@ -0,0 +1,62 @@
+========================
+Arvados Keep FUSE Driver
+========================
+
+Overview
+--------
+
+This package provides a FUSE driver for Keep, the Arvados_ storage
+system.  It allows you to read data from your collections as if they
+were on the local filesystem.
+
+.. _Arvados: https://arvados.org/
+
+Installation
+------------
+
+Installing under your user account
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+This method lets you install the package without root access.
+However, other users on the same system won't be able to use it.
+
+1. Run ``pip install --user arvados_fuse``.
+
+2. In your shell configuration, make sure you add ``$HOME/.local/bin``
+   to your PATH environment variable.  For example, you could add the
+   command ``PATH=$PATH:$HOME/.local/bin`` to your ``.bashrc`` file.
+
+3. Reload your shell configuration.  For example, bash users could run
+   ``source ~/.bashrc``.
+
+Installing on Debian systems
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+1. Add this Arvados repository to your sources list::
+
+     deb http://apt.arvados.org/ wheezy main
+
+2. Update your package list.
+
+3. Install the ``python-arvados-fuse`` package.
+
+Configuration
+-------------
+
+This driver needs two pieces of information to connect to
+Arvados: the DNS name of the API server, and an API authorization
+token.  You can set these in environment variables, or the file
+``$HOME/.config/arvados/settings.conf``.  `The Arvados user
+documentation
+<http://doc.arvados.org/user/reference/api-tokens.html>`_ describes
+how to find this information in the Arvados Workbench, and install it
+on your system.
+
+Testing and Development
+-----------------------
+
+This package is one part of the Arvados source package, and it has
+integration tests to check interoperability with other Arvados
+components.  Our `hacking guide
+<https://arvados.org/projects/arvados/wiki/Hacking_Python_SDK>`_
+describes how to set up a development environment and run tests.
diff --git a/services/fuse/readme.llfuse b/services/fuse/readme.llfuse
deleted file mode 100644 (file)
index f88a59b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-apt-get install python-dev libattr1-dev libfuse-dev pkg-config
diff --git a/services/fuse/requirements.txt b/services/fuse/requirements.txt
deleted file mode 100644 (file)
index 2b49d57..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-arvados-python-client>=0.1
-llfuse>=0.37
-python-daemon>=1.5
index fd774b7ff37d2ec2903b81bd692109536be74dda..d9fe797b8ee06df097381f8bd896a03e8db46589 100644 (file)
@@ -1,10 +1,15 @@
 #!/usr/bin/env python
 
-from setuptools import setup
+import os
+
+from setuptools import setup, find_packages
+
+README = os.path.join(os.path.dirname(__file__), 'README.rst')
 
 setup(name='arvados_fuse',
       version='0.1',
       description='Arvados FUSE driver',
+      long_description=open(README).read(),
       author='Arvados',
       author_email='info@arvados.org',
       url="https://arvados.org",
@@ -19,4 +24,6 @@ setup(name='arvados_fuse',
         'llfuse',
         'python-daemon'
         ],
+      test_suite='tests',
+      tests_require=['PyYAML'],
       zip_safe=False)
diff --git a/services/fuse/tests/__init__.py b/services/fuse/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29