app/controllers/user_workspaces_controller.rb
# delete all files from a submission
delete all files from a submission
delete all files from a submission
def delete_submission_files
    begin
      user_client = user_fire_cloud_client(current_user, @user_workspace.namespace)
      workspace = user_client.get_workspace(@user_workspace.namespace, @user_workspace.name)
      ws_attributes = workspace['workspace']['attributes']
      if ws_attributes['deleted_submissions'].blank?
        ws_attributes['deleted_submissions'] = [params[:submission_id]]
      else
        ws_attributes['deleted_submissions']['items'] << params[:submission_id]
      end
      logger.info "Adding #{params[:submission_id]} to workspace delete_submissions attribute in #{@user_workspace.name}"
      user_client.set_workspace_attributes(@user_workspace.namespace, @user_workspace.name, ws_attributes)
      logger.info "Starting submission #{params[:submission_id]} deletion in #{@user_workspace.name}"
      submission_files = ApplicationController.gcs_client.execute_gcloud_method(:get_workspace_files, 0, @user_workspace.namespace,
                                                           @user_workspace.name, prefix: params[:submission_id])
      submission_files.each do |file|
        ApplicationController.gcs_client.execute_gcloud_method(:delete_workspace_file, 0, @user_workspace.namespace,
                                          @user_workspace.name, file.name)
      end
      render '/user_workspaces/submissions/delete_submission_files'
    rescue => e
      logger.error "Unable to remove submission #{params[:submission_id]} files from #{@user_workspace.name} due to #{e.class.name}:#{e.message}"
      @alert = "Unable to delete the outputs for #{params[:submission_id]} due to the following error: #{e.message}"
      render '/user_workspaces/submissions/display_modal'
    end
  end
def delete_submission_files begin user_client = user_fire_cloud_client ( current_user , @user_workspace . namespace ) workspace = user_client . get_workspace ( @user_workspace . namespace , @user_workspace . name ) ws_attributes = workspace [ 'workspace' ] [ 'attributes' ] if ws_attributes [ 'deleted_submissions' ] . blank? ws_attributes [ 'deleted_submissions' ] = [ params [ :submission_id ] ] else ws_attributes [ 'deleted_submissions' ] [ 'items' ] << params [ :submission_id ] end logger . info "Adding #{params[:submission_id]} to workspace delete_submissions attribute in #{@user_workspace.name}" user_client . set_workspace_attributes ( @user_workspace . namespace , @user_workspace . name , ws_attributes ) logger . info "Starting submission #{params[:submission_id]} deletion in #{@user_workspace.name}" submission_files = ApplicationController . gcs_client . execute_gcloud_method ( :get_workspace_files , 0 , @user_workspace . namespace , @user_workspace . name , prefix : params [ :submission_id ] ) submission_files . each do | file | ApplicationController . gcs_client . execute_gcloud_method ( :delete_workspace_file , 0 , @user_workspace . namespace , @user_workspace . name , file . name ) end render '/user_workspaces/submissions/delete_submission_files' rescue => e logger . error "Unable to remove submission #{params[:submission_id]} files from #{@user_workspace.name} due to #{e.class.name}:#{e.message}" @alert = "Unable to delete the outputs for #{params[:submission_id]} due to the following error: #{e.message}" render '/user_workspaces/submissions/display_modal' end end
delete all files from a submission
delete all files from a submission
# instantiate user client for updating workspace attributes # first, add submission to list of 'deleted_submissions' in workspace attributes (will hide submission in list) # use GCS Admin client to get/delete files