<commit_before>class PapersPolicy < ApplicationPolicy
  allow_params :paper

  def show?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer? || can_view_manuscript_manager?
  end

  def edit?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  def create?
    current_user.present?
  end

  def update?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  def upload?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer? || can_view_manuscript_manager?
  end

  def download?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  private

  %w(PaperRole::ALL_ROLES).each do |role|
    define_method "paper_#{role}?" do
      paper.role_for(role: role, user: current_user).exists?
    end
  end

  def can_view_manuscript_manager?
    current_user.roles.where(journal_id: paper.journal).where(can_view_all_manuscript_managers: true).exists?
  end

  def author?
    author_of_paper? paper
  end
end
<commit_msg>Don't use %w when you shouldn't.<commit_after>class PapersPolicy < ApplicationPolicy
  allow_params :paper

  def show?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer? || can_view_manuscript_manager?
  end

  def edit?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  def create?
    current_user.present?
  end

  def update?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  def upload?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer? || can_view_manuscript_manager?
  end

  def download?
    current_user.admin? || author? || paper_collaborator? || paper_admin? || paper_editor? || paper_reviewer?
  end

  private

  PaperRole::ALL_ROLES.each do |role|
    define_method "paper_#{role}?" do
      paper.role_for(role: role, user: current_user).exists?
    end
  end

  def can_view_manuscript_manager?
    current_user.roles.where(journal_id: paper.journal).where(can_view_all_manuscript_managers: true).exists?
  end

  def author?
    author_of_paper? paper
  end
end

{'fraction_non_alphanumeric': 0.11499390491670053, 'fraction_numerical': 0.0, 'mean_word_length': 4.532584269662921, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1756342', 'n_tokens_mistral': 835, 'n_tokens_neox': 807, 'n_words': 167}