<commit_before>class ProjectPolicy < ApplicationPolicy

  self::UserScope = Struct.new(:current_user, :user, :scope) do
    def resolve
      if current_user.try(:admin?) || current_user == user
        scope.without_state('deleted')
      else
        scope.without_state(['deleted', 'draft', 'in_analysis', 'rejected'])
      end
    end
  end

  def create?
    done_by_owner_or_admin?
  end

  def push_to_online?
    done_by_owner_or_admin?
  end

  def update?
    create?
  end

  def push_to_flex?
    is_admin?
  end

  def update_account?
    record.account.new_record? || !record.published? || is_admin?
  end

  def send_to_analysis?
    create?
  end

  def publish?
    done_by_owner_or_admin?
  end

  def validate_publish?
    done_by_owner_or_admin?
  end

  def permitted_attributes
    if user.present? && (user.admin? || (record.draft? || record.rejected? || record.in_analysis? || record.approved?))
      p_attr = record.attribute_names.map(&:to_sym)
      p_attr << :all_tags
      p_attr << user_attributes
      p_attr << budget_attributes
      p_attr << posts_attributes
      p_attr << reward_attributes
      p_attr << account_attributes

      p_attr.flatten

      # TODO: This code is to prevent not allowed
      # fields without admin for legacy dashboard
      unless user.admin?
        not_allowed = [
          :audited_user_name, :audited_user_cpf, :audited_user_phone_number,
          :state, :origin_id, :service_fee, :total_installments,
          :recommended, :created_at, :updated_at
        ]
        p_attr.delete_if { |key| not_allowed.include?(key) }<commit_msg>exclude expires_at from allowed params when draft [Fix #121015703]<commit_after>class ProjectPolicy < ApplicationPolicy

  self::UserScope = Struct.new(:current_user, :user, :scope) do
    def resolve
      if current_user.try(:admin?) || current_user == user
        scope.without_state('deleted')
      else
        scope.without_state(['deleted', 'draft', 'in_analysis', 'rejected'])
      end
    end
  end

  def create?
    done_by_owner_or_admin?
  end

  def push_to_online?
    done_by_owner_or_admin?
  end

  def update?
    create?
  end

  def push_to_flex?
    is_admin?
  end

  def update_account?
    record.account.new_record? || !record.published? || is_admin?
  end

  def send_to_analysis?
    create?
  end

  def publish?
    done_by_owner_or_admin?
  end

  def validate_publish?
    done_by_owner_or_admin?
  end

  def permitted_attributes
    if user.present? && (user.admin? || (record.draft? || record.rejected? || record.in_analysis? || record.approved?))
      p_attr = record.attribute_names.map(&:to_sym)
      p_attr << :all_tags
      p_attr << user_attributes
      p_attr << budget_attributes
      p_attr << posts_attributes
      p_attr << reward_attributes
      p_attr << account_attributes

      p_attr.flatten

      # TODO: This code is to prevent not allowed
      # fields without admin for legacy dashboard
      unless user.admin?
        not_allowed = [
          :audited_user_name, :audited_user_cpf, :audited_user_phone_number,
          :state, :origin_id, :service_fee, :total_installments,
          :recommended, :created_at, :updated_at, :expires_at
        ]
        p_attr.delete_if { |key| not_allowed.include?(key) }
{'fraction_non_alphanumeric': 0.09513677811550152, 'fraction_numerical': 0.002735562310030395, 'mean_word_length': 3.042997542997543, 'pattern_counts': {'":': 0, '<': 29, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033408', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1057, 'n_words': 231}