Merge remote-tracking branch 'origin/master' into 2044-share-button
[arvados.git] / apps / workbench / app / controllers / collections_controller.rb
index 3b4943f5889a1910815417157c351aa5f1ad7704..3e981e10d8b94de9e64c6b83029fc42495ebb55c 100644 (file)
@@ -120,6 +120,14 @@ class CollectionsController < ApplicationController
     self.response_body = file_enumerator opts
   end
 
+  def sharing_scopes
+    ["GET /arvados/v1/collections/#{@object.uuid}", "GET /arvados/v1/keep_services"]
+  end
+
+  def search_scopes
+    ApiClientAuthorization.where(filters: [['scopes', '=', sharing_scopes]])
+  end
+
   def show
     return super if !@object
     if current_user
@@ -142,6 +150,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'] }
     end
     @prov_svg = ProvenanceHelper::create_provenance_graph(@object.provenance, "provenance_svg",
                                                           {:request => request,
@@ -154,6 +163,29 @@ class CollectionsController < ApplicationController
                                                                :pdata_only => true}) rescue nil
   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: sharing_scopes)
+    @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(token_list)