<commit_before>class Person < ActiveRecord::Base

  acts_as_annotation_source

  include Seek::Rdf::RdfGeneration
  include Seek::Taggable
  include Seek::Roles::AdminDefinedRoles

  auto_strip_attributes :email, :first_name, :last_name, :web_page

  alias_attribute :title, :name

  acts_as_yellow_pages
  scope :default_order, -> { order('last_name, first_name') }

  before_save :first_person_admin_and_add_to_default_project
  before_destroy :clean_up_and_assign_permissions

  acts_as_notifiee

  validates_presence_of :email

  validates :email, format: { with: RFC822::EMAIL }
  validates :web_page, url: { allow_nil: true, allow_blank: true }

  validates_uniqueness_of :email, case_sensitive: false

  has_and_belongs_to_many :disciplines

  has_many :group_memberships, dependent: :destroy, inverse_of: :person
  has_many :work_groups, through: :group_memberships, inverse_of: :people

  has_many :former_group_memberships, -> { where('time_left_at IS NOT NULL AND time_left_at <= ?', Time.now) },
           class_name: 'GroupMembership', dependent: :destroy
  has_many :former_work_groups, class_name: 'WorkGroup', through: :former_group_memberships,
                                source: :work_group

  has_many :current_group_memberships, -> { where('time_left_at IS NULL OR time_left_at > ?', Time.now) },
           class_name: 'GroupMembership', dependent: :destroy
  has_many :current_work_groups, class_name: 'WorkGroup', through: :current_group_memberships,
                                 source: :work_group

  has_many :institutions, -> { uniq }, through: :work_groups

  has_many :favourite_group_memberships, dependent: :destroy
  has_many :favourite_groups, through: :favourite_group_memberships

  has_many :studies_for_person, foreign_key: :contributor_id, class_name: 'Study'
  has_many :assays_for_person, foreign_key: :contributor_id, class_name: 'Assay'
  alias assays assays_for_person
  has_many :investigations_for_person, foreign_key: :contributor_id, class_name: 'Investigation'

  has_many :presentations_for_person, foreign_key: :contributor_id, class_name: 'Presentation'
  has_many :samples_for_person, foreign_key: :contributor_id, class_name: 'Sample'
  has_many :events_for_person, foreign_key: :contributor_id, class_name: 'Event'

  has_one :user, dependent: :destroy

  has_many :assets_creators, dependent: :destroy, foreign_key: 'creator_id'
  has_many :created_data_files, through: :assets_creators, source: :asset, source_type: 'DataFile'
  has_many :created_documents, through: :assets_creators, source: :asset, source_type: 'Document'
  has_many :created_models, through: :assets_creators, source: :asset, source_type: 'Model'
  has_many :created_sops, through: :assets_creators, source: :asset, source_type: 'Sop'
  has_many :created_publications, through: :assets_creators, source: :asset, source_type: 'Publication'
  has_many :created_presentations, through: :assets_creators, source: :asset, source_type: 'Presentation'
  has_many :created_samples, through: :assets_creators, source: :asset, source_type: 'Sample'

  has_many :created_investigations, through: :assets_creators, source: :asset, source_type: 'Investigation'
  has_many :created_studies, through: :assets_creators, source: :asset, source_type: 'Study'
  has_many :created_assays, through: :assets_creators, source: :asset, source_type: 'Assay'

  has_annotation_type :expertise, method_name: :expertise
  has_annotation_type :tool

  has_many :publication_authors

  if Seek::Config.solr_enabled
    searchable(auto_index: false) do
      text :project_positions
      text :disciplines do
        disciplines.map(&:title)
      end
    end
  end

  scope :with_group, -> { includes(:group_memberships).where('group_memberships.person_id IS NOT NULL').references(:group_memberships) }
  scope :without_group, -> { includes(:group_memberships).where('group_memberships.person_id IS NULL').references(:group_memberships) }
  scope :registered, -> { includes(:user).where('users.person_id != 0').references(:users) }
  scope :not_registered, -> { includes(:user).where('users.person_id IS NULL').references(:users) }

  alias_attribute :webpage, :web_page

  include Seek::Subscriptions::PersonProjectSubscriptions
  include Seek::OrcidSupport

  after_commit :queue_update_auth_table

  after_destroy :update_publication_authors_after_destroy

  # not registered profiles that match this email
  def self.not_registered_with_matching_email(email)<commit_msg>put back person.person for the time being<commit_after>class Person < ActiveRecord::Base

  acts_as_annotation_source

  include Seek::Rdf::RdfGeneration
  include Seek::Taggable
  include Seek::Roles::AdminDefinedRoles

  auto_strip_attributes :email, :first_name, :last_name, :web_page

  alias_attribute :title, :name

  acts_as_yellow_pages
  scope :default_order, -> { order('last_name, first_name') }

  before_save :first_person_admin_and_add_to_default_project
  before_destroy :clean_up_and_assign_permissions

  acts_as_notifiee

  validates_presence_of :email

  validates :email, format: { with: RFC822::EMAIL }
  validates :web_page, url: { allow_nil: true, allow_blank: true }

  validates_uniqueness_of :email, case_sensitive: false

  has_and_belongs_to_many :disciplines

  has_many :group_memberships, dependent: :destroy, inverse_of: :person
  has_many :work_groups, through: :group_memberships, inverse_of: :people

  has_many :former_group_memberships, -> { where('time_left_at IS NOT NULL AND time_left_at <= ?', Time.now) },
           class_name: 'GroupMembership', dependent: :destroy
  has_many :former_work_groups, class_name: 'WorkGroup', through: :former_group_memberships,
                                source: :work_group

  has_many :current_group_memberships, -> { where('time_left_at IS NULL OR time_left_at > ?', Time.now) },
           class_name: 'GroupMembership', dependent: :destroy
  has_many :current_work_groups, class_name: 'WorkGroup', through: :current_group_memberships,
                                 source: :work_group

  has_many :institutions, -> { uniq }, through: :work_groups

  has_many :favourite_group_memberships, dependent: :destroy
  has_many :favourite_groups, through: :favourite_group_memberships

  has_many :studies_for_person, foreign_key: :contributor_id, class_name: 'Study'
  has_many :assays_for_person, foreign_key: :contributor_id, class_name: 'Assay'
  alias assays assays_for_person
  has_many :investigations_for_person, foreign_key: :contributor_id, class_name: 'Investigation'

  has_many :presentations_for_person, foreign_key: :contributor_id, class_name: 'Presentation'
  has_many :samples_for_person, foreign_key: :contributor_id, class_name: 'Sample'
  has_many :events_for_person, foreign_key: :contributor_id, class_name: 'Event'

  has_one :user, dependent: :destroy

  has_many :assets_creators, dependent: :destroy, foreign_key: 'creator_id'
  has_many :created_data_files, through: :assets_creators, source: :asset, source_type: 'DataFile'
  has_many :created_documents, through: :assets_creators, source: :asset, source_type: 'Document'
  has_many :created_models, through: :assets_creators, source: :asset, source_type: 'Model'
  has_many :created_sops, through: :assets_creators, source: :asset, source_type: 'Sop'
  has_many :created_publications, through: :assets_creators, source: :asset, source_type: 'Publication'
  has_many :created_presentations, through: :assets_creators, source: :asset, source_type: 'Presentation'
  has_many :created_samples, through: :assets_creators, source: :asset, source_type: 'Sample'

  has_many :created_investigations, through: :assets_creators, source: :asset, source_type: 'Investigation'
  has_many :created_studies, through: :assets_creators, source: :asset, source_type: 'Study'
  has_many :created_assays, through: :assets_creators, source: :asset, source_type: 'Assay'

  has_annotation_type :expertise, method_name: :expertise
  has_annotation_type :tool

  has_many :publication_authors

  if Seek::Config.solr_enabled
    searchable(auto_index: false) do
      text :project_positions
      text :disciplines do
        disciplines.map(&:title)
      end
    end
  end

  scope :with_group, -> { includes(:group_memberships).where('group_memberships.person_id IS NOT NULL').references(:group_memberships) }
  scope :without_group, -> { includes(:group_memberships).where('group_memberships.person_id IS NULL').references(:group_memberships) }
  scope :registered, -> { includes(:user).where('users.person_id != 0').references(:users) }
  scope :not_registered, -> { includes(:user).where('users.person_id IS NULL').references(:users) }

  alias_attribute :webpage, :web_page

  include Seek::Subscriptions::PersonProjectSubscriptions
  include Seek::OrcidSupport

  after_commit :queue_update_auth_table

  after_destroy :update_publication_authors_after_destroy
  
  # to make it look like a User
  def person
    self
  end    

  # not registered profiles that match this email
  def self.not_registered_with_matching_email(email)
{'fraction_non_alphanumeric': 0.09694159213867727, 'fraction_numerical': 0.0008832946891906813, 'mean_word_length': 5.930374904361132, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6470001', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2876, 'n_words': 626}