2871: some more comments
[arvados.git] / apps / workbench / app / controllers / collections_controller.rb
index 3e981e10d8b94de9e64c6b83029fc42495ebb55c..218ba893fc43d6c089be664a80baf7e570d2e6be 100644 (file)
@@ -121,11 +121,15 @@ class CollectionsController < ApplicationController
   end
 
   def sharing_scopes
-    ["GET /arvados/v1/collections/#{@object.uuid}", "GET /arvados/v1/keep_services"]
+    ["GET /arvados/v1/collections/#{@object.uuid}", "GET /arvados/v1/collections/#{@object.uuid}/", "GET /arvados/v1/keep_services/accessible"]
   end
 
   def search_scopes
-    ApiClientAuthorization.where(filters: [['scopes', '=', sharing_scopes]])
+    begin
+      ApiClientAuthorization.filter([['scopes', '=', sharing_scopes]]).results
+    rescue ArvadosApiClient::AccessForbiddenException
+      nil
+    end
   end
 
   def show
@@ -150,7 +154,7 @@ class CollectionsController < ApplicationController
         .where(head_uuid: @object.uuid, tail_uuid: current_user.uuid,
                link_class: 'resources', name: 'wants')
         .results.any?
-      @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+      @search_sharing = search_scopes
     end
     @prov_svg = ProvenanceHelper::create_provenance_graph(@object.provenance, "provenance_svg",
                                                           {:request => request,
@@ -164,25 +168,31 @@ class CollectionsController < ApplicationController
   end
 
   def sharing_popup
-    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    @search_sharing = search_scopes
     respond_to do |format|
       format.html
       format.js
     end
   end
 
+  helper_method :download_link
+
+  def download_link
+    collections_url + "/download/#{@object.uuid}/#{@search_sharing.first.api_token}"
+  end
+
   def share
     a = ApiClientAuthorization.create(scopes: sharing_scopes)
-    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    @search_sharing = search_scopes
     render 'sharing_popup'
   end
 
   def unshare
-    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    @search_sharing = search_scopes
     @search_sharing.each do |s|
       s.destroy
     end
-    @search_sharing = search_scopes.select { |s| s.scopes != ['all'] }
+    @search_sharing = search_scopes
     render 'sharing_popup'
   end