<commit_before>class User < ActiveRecord::Base
  include NotifyWith::NotificationReceiver
  include NotifyWith::NotificationAttachedObject
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :async
  rolify

  # enable OmniAuth authentication only if needed
  devise :omniauthable, :omniauth_providers => [AuthProvider.active.strategy_name.to_sym] unless AuthProvider.active.providable_type == DatabaseProvider.name

  extend FriendlyId
  friendly_id :username, use: :slugged

  has_one :profile, dependent: :destroy
  accepts_nested_attributes_for :profile

  has_many :my_projects, foreign_key: :author_id, class_name: 'Project', dependent: :destroy
  has_many :project_users, dependent: :destroy
  has_many :projects, through: :project_users

  has_many :reservations, dependent: :destroy
  accepts_nested_attributes_for :reservations, allow_destroy: true

  # Les formations sont déjà faites
  has_many :user_trainings, dependent: :destroy
  has_many :trainings, through: :user_trainings

  belongs_to :group

  has_many :subscriptions, dependent: :destroy
  accepts_nested_attributes_for :subscriptions, allow_destroy: true

  has_many :users_credits, dependent: :destroy
  has_many :credits, through: :users_credits

  has_many :training_credits, through: :users_credits, source: :training_credit
  has_many :machine_credits, through: :users_credits, source: :machine_credit

  has_many :invoices, dependent: :destroy

  has_many :user_tags, dependent: :destroy
  has_many :tags, through: :user_tags
  accepts_nested_attributes_for :tags, allow_destroy: true

  has_one :wallet, dependent: :destroy

  has_many :exports, dependent: :destroy

  # fix for create admin user
  before_save do
    self.email.downcase! if self.email
  end

  before_create :assign_default_role
  after_create :create_a_wallet
  after_commit :create_stripe_customer, on: [:create]
  after_commit :notify_admin_when_user_is_created, on: :create
  after_update :notify_admin_invoicing_changed, if: :invoicing_disabled_changed?
  after_update :notify_group_changed, if: :group_id_changed?<commit_msg>[bug] unable to delete admin<commit_after>class User < ActiveRecord::Base
  include NotifyWith::NotificationReceiver
  include NotifyWith::NotificationAttachedObject
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :async
  rolify

  # enable OmniAuth authentication only if needed
  devise :omniauthable, :omniauth_providers => [AuthProvider.active.strategy_name.to_sym] unless AuthProvider.active.providable_type == DatabaseProvider.name

  extend FriendlyId
  friendly_id :username, use: :slugged

  has_one :profile, dependent: :destroy
  accepts_nested_attributes_for :profile

  has_many :my_projects, foreign_key: :author_id, class_name: 'Project', dependent: :destroy
  has_many :project_users, dependent: :destroy
  has_many :projects, through: :project_users

  has_many :reservations, dependent: :destroy
  accepts_nested_attributes_for :reservations, allow_destroy: true

  # Les formations sont déjà faites
  has_many :user_trainings, dependent: :destroy
  has_many :trainings, through: :user_trainings

  belongs_to :group

  has_many :subscriptions, dependent: :destroy
  accepts_nested_attributes_for :subscriptions, allow_destroy: true

  has_many :users_credits, dependent: :destroy
  has_many :credits, through: :users_credits

  has_many :training_credits, through: :users_credits, source: :training_credit
  has_many :machine_credits, through: :users_credits, source: :machine_credit

  has_many :invoices, dependent: :destroy

  has_many :user_tags, dependent: :destroy
  has_many :tags, through: :user_tags
  accepts_nested_attributes_for :tags, allow_destroy: true

  has_one :wallet, dependent: :destroy
  has_many :wallet_transactions, dependent: :destroy

  has_many :exports, dependent: :destroy

  # fix for create admin user
  before_save do
    self.email.downcase! if self.email
  end

  before_create :assign_default_role
  after_create :create_a_wallet
  after_commit :create_stripe_customer, on: [:create]
  after_commit :notify_admin_when_user_is_created, on: :create
  after_update :notify_admin_invoicing_changed, if: :invoicing_disabled_changed?
  after_update :notify_group_changed, if: :group_id_changed?
{'fraction_non_alphanumeric': 0.07679033649698015, 'fraction_numerical': 0.0, 'mean_word_length': 6.234009360374415, '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': '2802492', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1405, 'n_words': 359}