<commit_before>module Setup
  module CrossOriginShared
    extend ActiveSupport::Concern

    include CenitScoped
    include CrossOrigin::CenitDocument
    include Mongoid::Userstamp
    include Mongoid::Tracer

    TRACING_IGNORE_ATTRIBUTES = [:created_at, :updated_at, :creator_id, :updater_id, :tenant_id, :origin, :_type]

    included do
      origins :default, -> { Cenit::MultiTenancy.tenant_model.current && :owner }, :shared

      build_in_data_type.excluding(:origin, :tenant)

      shared_deny :delete

      trace_ignore TRACING_IGNORE_ATTRIBUTES

      belongs_to :tenant, class_name: Cenit::MultiTenancy.tenant_model_name, inverse_of: nil

      before_validation :validates_before

      before_destroy :validates_for_destroy
    end

    def validates_for_destroy
      unless origin == :default
        errors.add(:base, "#{try(:custom_title) || try(:name) || "#{self.class}##{id}"} is shared")
      end
      errors.blank?
    end

    def validates_before
      self.tenant = Account.current if new_record?
    end

    def tracing?
      (shared? || self.class.data_type.trace_by_default) && super
    end

    def trace_action_attributes
      attrs = super
      attrs[:origin] = origin
      attrs
    end

    def trace_model
      super.with(self.class.mongoid_root_class)
    end

    def not_shared?
      !shared?
    end

    def shared?
      origin != :default
    end

    def tenant_version
      # if version && (pin = Setup::Pin.for(self)) && pin.version < version
      #   undo nil, from: pin.version + 1, to: version
      # end<commit_msg>Trace attributes for action context<commit_after>module Setup
  module CrossOriginShared
    extend ActiveSupport::Concern

    include CenitScoped
    include CrossOrigin::CenitDocument
    include Mongoid::Userstamp
    include Mongoid::Tracer

    TRACING_IGNORE_ATTRIBUTES = [:created_at, :updated_at, :creator_id, :updater_id, :tenant_id, :origin, :_type]

    included do
      origins :default, -> { Cenit::MultiTenancy.tenant_model.current && :owner }, :shared

      build_in_data_type.excluding(:origin, :tenant)

      shared_deny :delete

      trace_ignore TRACING_IGNORE_ATTRIBUTES

      belongs_to :tenant, class_name: Cenit::MultiTenancy.tenant_model_name, inverse_of: nil

      before_validation :validates_before

      before_destroy :validates_for_destroy
    end

    def validates_for_destroy
      unless origin == :default
        errors.add(:base, "#{try(:custom_title) || try(:name) || "#{self.class}##{id}"} is shared")
      end
      errors.blank?
    end

    def validates_before
      self.tenant = Account.current if new_record?
    end

    def tracing?
      (shared? || self.class.data_type.trace_by_default) && super
    end

    def trace_action_attributes(action = nil)
      attrs = super
      attrs[:origin] = origin
      attrs
    end

    def trace_model
      super.with(self.class.mongoid_root_class)
    end

    def not_shared?
      !shared?
    end

    def shared?
      origin != :default
    end

    def tenant_version
      # if version && (pin = Setup::Pin.for(self)) && pin.version < version
      #   undo nil, from: pin.version + 1, to: version
      # end
{'fraction_non_alphanumeric': 0.0940625, 'fraction_numerical': 0.000625, 'mean_word_length': 2.9962546816479403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4506999', 'n_tokens_mistral': 1028, 'n_tokens_neox': 999, 'n_words': 224}