[ARVADOS] created: c3fd48d0728c140fbe0ab038ad148cfae8104c97

git at public.curoverse.com git at public.curoverse.com
Tue May 6 17:10:13 EDT 2014


        at  c3fd48d0728c140fbe0ab038ad148cfae8104c97 (commit)


commit c3fd48d0728c140fbe0ab038ad148cfae8104c97
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue May 6 17:10:04 2014 -0400

    Almost working sharing button.

diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index ce72d62..a9cc1c6 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -110,6 +110,10 @@ class CollectionsController < ApplicationController
     self.response_body = file_enumerator opts
   end
 
+  def search_scopes
+    ApiClientAuthorization.where(filters: [['scopes', '=', "/arvados/v1/collections/#{@object.uuid}"]])
+  end
+
   def show
     return super if !@object
     @provenance = []
@@ -117,6 +121,7 @@ class CollectionsController < ApplicationController
     @output2colorindex = {}
     @sourcedata = {params[:uuid] => {uuid: params[:uuid]}}
     @protected = {}
+    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
 
     colorindex = -1
     any_hope_left = true
@@ -172,12 +177,28 @@ class CollectionsController < ApplicationController
   end
 
   def sharing_popup
+    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
     respond_to do |format|
       format.html
       format.js
     end
   end
 
+  def share
+    a = ApiClientAuthorization.create(scopes: ["/arvados/v1/collections/#{@object.uuid}"])
+    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    render 'sharing_popup'
+  end
+
+  def unshare
+    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    @search_sharing.each do |s|
+      s.destroy
+    end
+    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    render 'sharing_popup'
+  end
+
   protected
 
   def find_usable_token
diff --git a/apps/workbench/app/views/collections/_sharing_popup.html.erb b/apps/workbench/app/views/collections/_sharing_popup.html.erb
index b19cb6f..b88cd58 100644
--- a/apps/workbench/app/views/collections/_sharing_popup.html.erb
+++ b/apps/workbench/app/views/collections/_sharing_popup.html.erb
@@ -1,10 +1,37 @@
-<div class="modal-dialog">
+
+<div class="modal-dialog" style="width: 90%">
   <div class="modal-content">
     <div class="modal-header">
       <button type="button" class="close" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">×</button>
       <h4 class="modal-title">Sharing</h4>
     </div>
     <div class="modal-body">
+      <div id="sharing-text" style="text-align: center">
+        <% if @search_sharing.any? %>
+          Use this link to share this collection:<br>
+          <big>
+          <% link = collection_url + "?api_token=#{@search_sharing.first.api_token}" %>
+          <%= link_to link, link %>
+          </big>
+        <% else %>
+          Not shared.
+        <% end %>
+      </div>
+      <div style="text-align: center; padding-top: 1em">
+      <% if @search_sharing and @search_sharing.any? %>
+        <%= link_to "Unshare", unshare_collection_url, {
+            class: 'btn btn-success',
+              remote: true,
+            method: 'post'
+            } %>
+      <% else %>
+        <%= link_to "Share", share_collection_url, {
+              class: 'btn btn-info',
+              remote: true,
+              method: 'post'
+            } %>
+      <% end %>
+      </div>
     </div>
   </div>
 </div>
diff --git a/apps/workbench/app/views/collections/_show_files.html.erb b/apps/workbench/app/views/collections/_show_files.html.erb
index 371493d..885d42f 100644
--- a/apps/workbench/app/views/collections/_show_files.html.erb
+++ b/apps/workbench/app/views/collections/_show_files.html.erb
@@ -10,7 +10,14 @@
   <div class="col-md-6"></div>
   <div class="col-md-6">
     <div class="pull-right">
-      <%= link_to "Share", sharing_popup_collection_url(id: @object.uuid),  {class: 'btn btn-primary', :remote => true, 'data-toggle' =>  "modal", 'data-target' => '#collection-sharing-modal-window'}  %>
+      <% if @search_sharing.any? %>
+        <% linktext = "Shared" %>
+        <% btnstyle = "btn-success" %>
+      <% else %>
+        <% linktext = "Share" %>
+        <% btnstyle = "btn-info" %>
+      <% end %>
+      <%= link_to linktext, sharing_popup_collection_url(id: @object.uuid),  {class: "btn #{btnstyle}", :remote => true, 'data-toggle' =>  "modal", 'data-target' => '#collection-sharing-modal-window'}  %>
       <span style="padding-left: 1em">Collection storage status:</span>
       <%= render partial: 'toggle_persist', locals: { uuid: @object.uuid, current_state: (@is_persistent ? 'persistent' : 'cache') } %>
 
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index cd9489e..43eb7ae 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -43,6 +43,8 @@ ArvadosWorkbench::Application.routes.draw do
   resources :collections do
     post 'set_persistent', on: :member
     get 'sharing_popup', :on => :member
+    post 'share', :on => :member
+    post 'unshare', :on => :member
   end
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
   resources :folders do
diff --git a/services/api/app/controllers/arvados/v1/api_client_authorizations_controller.rb b/services/api/app/controllers/arvados/v1/api_client_authorizations_controller.rb
index dc95b2f..4a2bafd 100644
--- a/services/api/app/controllers/arvados/v1/api_client_authorizations_controller.rb
+++ b/services/api/app/controllers/arvados/v1/api_client_authorizations_controller.rb
@@ -27,6 +27,8 @@ class Arvados::V1::ApiClientAuthorizationsController < ApplicationController
       # translate UUID to numeric ID here.
       resource_attrs[:user_id] =
         User.where(uuid: resource_attrs.delete(:owner_uuid)).first.andand.id
+    elsif not resource_attrs[:user_id]
+      resource_attrs[:user_id] = current_user.id
     end
     resource_attrs[:api_client_id] = Thread.current[:api_client].id
     super
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 2bf1376..290e156 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -187,27 +187,29 @@ class ArvadosModel < ActiveRecord::Base
 
   def ensure_owner_uuid_is_permitted
     raise PermissionDeniedError if !current_user
-    self.owner_uuid ||= current_user.uuid
-    if self.owner_uuid_changed?
-      if 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
+    if self.respond_to? :owner_uuid=
+      self.owner_uuid ||= current_user.uuid
+      if self.owner_uuid_changed?
+        if 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
+          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 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}"
+        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}"
         raise PermissionDeniedError
       end
     end
-    if new_record?
-      return true
-    elsif 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}"
-      raise PermissionDeniedError
-    end
   end
 
   def ensure_permission_to_save

commit 35bc4e20adcc706ffdda3b1c9aeed1b34a20c51b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Tue May 6 14:52:54 2014 -0400

    Added empty sharing popup.

diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 4178e38..ce72d62 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -171,6 +171,13 @@ class CollectionsController < ApplicationController
     end
   end
 
+  def sharing_popup
+    respond_to do |format|
+      format.html
+      format.js
+    end
+  end
+
   protected
 
   def find_usable_token
diff --git a/apps/workbench/app/views/collections/_sharing_popup.html.erb b/apps/workbench/app/views/collections/_sharing_popup.html.erb
new file mode 100644
index 0000000..b19cb6f
--- /dev/null
+++ b/apps/workbench/app/views/collections/_sharing_popup.html.erb
@@ -0,0 +1,10 @@
+<div class="modal-dialog">
+  <div class="modal-content">
+    <div class="modal-header">
+      <button type="button" class="close" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">×</button>
+      <h4 class="modal-title">Sharing</h4>
+    </div>
+    <div class="modal-body">
+    </div>
+  </div>
+</div>
diff --git a/apps/workbench/app/views/collections/_show_files.html.erb b/apps/workbench/app/views/collections/_show_files.html.erb
index 4b63162..371493d 100644
--- a/apps/workbench/app/views/collections/_show_files.html.erb
+++ b/apps/workbench/app/views/collections/_show_files.html.erb
@@ -10,8 +10,10 @@
   <div class="col-md-6"></div>
   <div class="col-md-6">
     <div class="pull-right">
-      Collection storage status:
+      <%= link_to "Share", sharing_popup_collection_url(id: @object.uuid),  {class: 'btn btn-primary', :remote => true, 'data-toggle' =>  "modal", 'data-target' => '#collection-sharing-modal-window'}  %>
+      <span style="padding-left: 1em">Collection storage status:</span>
       <%= render partial: 'toggle_persist', locals: { uuid: @object.uuid, current_state: (@is_persistent ? 'persistent' : 'cache') } %>
+
     </div>
   </div>
 </div>
@@ -73,3 +75,7 @@
     <% end; end %>
   </tbody>
 </table>
+
+<% content_for :footer_html do %>
+<div id="collection-sharing-modal-window" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
+<% end %>
diff --git a/apps/workbench/app/views/collections/sharing_popup.js.erb b/apps/workbench/app/views/collections/sharing_popup.js.erb
new file mode 100644
index 0000000..fea8593
--- /dev/null
+++ b/apps/workbench/app/views/collections/sharing_popup.js.erb
@@ -0,0 +1 @@
+$("#collection-sharing-modal-window").html("<%= escape_javascript(render partial: 'sharing_popup') %>");
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index e8862c2..cd9489e 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -42,6 +42,7 @@ ArvadosWorkbench::Application.routes.draw do
   match '/collections/graph' => 'collections#graph'
   resources :collections do
     post 'set_persistent', on: :member
+    get 'sharing_popup', :on => :member
   end
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
   resources :folders do

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list