1 class ActionsController < ApplicationController
3 skip_filter :require_thread_api_token, only: [:report_issue_popup, :report_issue]
4 skip_filter :check_user_agreements, only: [:report_issue_popup, :report_issue]
7 def self.expose_action method, &block
8 @@exposed_actions[method] = true
9 define_method method, block
13 ArvadosBase::resource_class_for_uuid(params[:uuid])
17 @object = model_class.andand.find(params[:uuid])
18 if @object.is_a? Link and
19 @object.link_class == 'name' and
20 ArvadosBase::resource_class_for_uuid(@object.head_uuid) == Collection
21 redirect_to collection_path(id: @object.uuid)
25 raise ActiveRecord::RecordNotFound
30 params.keys.collect(&:to_sym).each do |param|
31 if @@exposed_actions[param]
32 return self.send(param)
38 expose_action :copy_selections_into_project do
42 expose_action :move_selections_into_project do
46 def move_or_copy action
47 uuids_to_add = params["selection"]
48 uuids_to_add = [ uuids_to_add ] unless uuids_to_add.is_a? Array
50 collect { |x| ArvadosBase::resource_class_for_uuid(x) }.
52 each do |resource_class|
53 resource_class.filter([['uuid','in',uuids_to_add]]).each do |src|
54 if resource_class == Collection and not Collection.attribute_info.include?(:name)
55 dst = Link.new(owner_uuid: @object.uuid,
56 tail_uuid: @object.uuid,
64 if dst.respond_to? :'name='
66 dst.name = "Copy of #{dst.name}"
68 dst.name = "Copy of unnamed #{dst.class_for_display.downcase}"
71 if resource_class == Collection
72 dst.manifest_text = Collection.select([:manifest_text]).where(uuid: src.uuid).first.manifest_text
77 raise ArgumentError.new "Unsupported action #{action}"
79 dst.owner_uuid = @object.uuid
80 dst.tail_uuid = @object.uuid if dst.class == Link
85 dst.name += " (#{Time.now.localtime})" if dst.respond_to? :name=
93 def arv_normalize mt, *opts
96 merge({'ARVADOS_API_HOST' =>
97 arvados_api_client.arvados_v1_base.
98 sub(/\/arvados\/v1/, '').
99 sub(/^https?:\/\//, ''),
100 'ARVADOS_API_TOKEN' => 'x',
101 'ARVADOS_API_HOST_INSECURE' =>
102 Rails.configuration.arvados_insecure_https ? 'true' : 'false'
104 IO.popen([env, 'arv-normalize'] + opts, 'w+b') do |io|
107 while buf = io.read(2**16)
114 expose_action :combine_selected_files_into_collection do
117 params["selection"].each do |s|
118 a = ArvadosBase::resource_class_for_uuid s
122 m = CollectionsHelper.match(Link.find(s).head_uuid)
126 m = CollectionsHelper.match(s)
129 if m and m[1] and m[2]
130 lst.append(m[1] + m[2])
135 collections = Collection.where(uuid: lst)
138 collections.each do |c|
145 mt = chash[m[1]+m[2]].manifest_text
147 combined += arv_normalize mt, '--extract', m[4][1..-1]
149 combined += chash[m[1]+m[2]].manifest_text
153 normalized = arv_normalize combined
154 newc = Collection.new({:manifest_text => normalized})
160 head_uuid: newc.uuid,
161 link_class: "provenance",
167 redirect_to controller: 'collections', action: :show, id: newc.uuid
170 def report_issue_popup
171 respond_to do |format|
178 logger.warn "report_issue: #{params.inspect}"
180 respond_to do |format|
181 IssueReporter.send_report(current_user, params).deliver
182 format.js {render nothing: true}