<commit_before>class MappingPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      # TODO base this on the map policy
      # it would be nice if we could also base this on the mappable, but that
      # gets really complicated. Devin thinks it's OK to SHOW a mapping for
      # a private topic, since you can't see the private topic anyways
      visible = ['public', 'commons']
      permission = 'maps.permission IN (?)'
      if user
        scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)
      else
        scope.where(permission, visible)
      end 
    end
  end

  def show?
    map_policy.show? && mappable_policy.show?
  end

  def create?
    map_policy.update?
  end

  def update?
    record.mappable_type == 'Topic' && map_policy.update?
  end

  def destroy?
    map_policy.update? || admin_override<commit_msg>avoid pundit error if no map specified with a mapping<commit_after>class MappingPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      # TODO base this on the map policy
      # it would be nice if we could also base this on the mappable, but that
      # gets really complicated. Devin thinks it's OK to SHOW a mapping for
      # a private topic, since you can't see the private topic anyways
      visible = ['public', 'commons']
      permission = 'maps.permission IN (?)'
      if user
        scope.joins(:maps).where(permission + ' OR maps.user_id = ?', visible, user.id)
      else
        scope.where(permission, visible)
      end 
    end
  end

  def show?
    map_policy.show? && mappable_policy.show?
  end

  def create?
    record.map.present? && map_policy.update?
  end

  def update?
    record.mappable_type == 'Topic' && map_policy.update?
  end

  def destroy?
    map_policy.update? || admin_override
{'fraction_non_alphanumeric': 0.08429752066115702, 'fraction_numerical': 0.0, 'mean_word_length': 2.721311475409836, 'pattern_counts': {'":': 0, '<': 7, '<?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': '495234', 'n_tokens_mistral': 548, 'n_tokens_neox': 532, 'n_words': 191}