<commit_before># == Schema Information
#
# Table name: submissions
#
#  id                :integer          not null, primary key
#  user_id           :integer
#  title             :string           not null
#  journal           :string
#  doi               :string
#  agreed_to_license :boolean
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  documents         :string
#  status            :string
#  handle            :string
#  uuid              :string
#  pub_date          :datetime
#  funders           :string
#

class SubmissionsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_s3_direct_post, only: [:new, :create]
  load_and_authorize_resource

  def index
    @submissions = if current_user.admin?
                     filtered_submissions
                   else
                     current_user.submissions.order(created_at: :desc)
                   end
  end

  def new
    @submission = Submission.new
    @submission.user = current_user
  end

  def create
    @submission = Submission.new(submission_params)
    @submission.user = current_user
    if @submission.save
      SwordSubmitJob.perform_later(@submission, callback_uri)
      flash.notice = 'Your Submission is now in progress'
      redirect_to submissions_path
    else
      render 'new'
    end
  end

  def package
    @submission = Submission.find_by_id(params[:id])
    @submission.to_sword_package(callback_uri)
    send_file(@submission.sword_path)
  end

  def resubmit
    @submission = Submission.find_by_id(params[:id])
    SwordSubmitJob.perform_later(@submission, callback_uri)
    flash.notice = 'Submission has been resubmitted to the job queue'
    redirect_to submissions_path
  end

  def show
  end

  private

  def filtered_submissions
    if params[:filter]
      Submission.where(status: params[:filter])
    else
      Submission.all.order(created_at: :desc)
    end
  end

  def set_s3_direct_post
    @s3_direct_post = S3_BUCKET.presigned_post(
      key: "uploads/#{SecureRandom.uuid}/${filename}",
      success_action_status: '201',
      acl: 'public-read')
  end

  def callback_uri
    callback_submission_status_url(@submission)
  end

  def submission_params
    params.require(:submission).permit(:title, :agreed_to_license, :pub_date,
                                       :journal, :doi, :documents_cache,
                                       documents: [], funders: [])
  end
end<commit_msg>Use UUID in callback URI<commit_after># == Schema Information
#
# Table name: submissions
#
#  id                :integer          not null, primary key
#  user_id           :integer
#  title             :string           not null
#  journal           :string
#  doi               :string
#  agreed_to_license :boolean
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  documents         :string
#  status            :string
#  handle            :string
#  uuid              :string
#  pub_date          :datetime
#  funders           :string
#

class SubmissionsController < ApplicationController
  before_action :authenticate_user!
  before_action :set_s3_direct_post, only: [:new, :create]
  load_and_authorize_resource

  def index
    @submissions = if current_user.admin?
                     filtered_submissions
                   else
                     current_user.submissions.order(created_at: :desc)
                   end
  end

  def new
    @submission = Submission.new
    @submission.user = current_user
  end

  def create
    @submission = Submission.new(submission_params)
    @submission.user = current_user
    if @submission.save
      SwordSubmitJob.perform_later(@submission, callback_uri)
      flash.notice = 'Your Submission is now in progress'
      redirect_to submissions_path
    else
      render 'new'
    end
  end

  def package
    @submission = Submission.find_by_id(params[:id])
    @submission.to_sword_package(callback_uri)
    send_file(@submission.sword_path)
  end

  def resubmit
    @submission = Submission.find_by_id(params[:id])
    SwordSubmitJob.perform_later(@submission, callback_uri)
    flash.notice = 'Submission has been resubmitted to the job queue'
    redirect_to submissions_path
  end

  def show
  end

  private

  def filtered_submissions
    if params[:filter]
      Submission.where(status: params[:filter])
    else
      Submission.all.order(created_at: :desc)
    end
  end

  def set_s3_direct_post
    @s3_direct_post = S3_BUCKET.presigned_post(
      key: "uploads/#{SecureRandom.uuid}/${filename}",
      success_action_status: '201',
      acl: 'public-read')
  end

  def callback_uri
    "#{root_url}/callbacks/status/#{@submission.uuid}"
  end

  def submission_params
    params.require(:submission).permit(:title, :agreed_to_license, :pub_date,
                                       :journal, :doi, :documents_cache,
                                       documents: [], funders: [])
  end
end
{'fraction_non_alphanumeric': 0.07829888712241653, 'fraction_numerical': 0.0027821939586645467, 'mean_word_length': 2.278827361563518, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926595', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1468, 'n_words': 331}