Commit 4df97b08 authored by Yorick Peterse's avatar Yorick Peterse

Move EE specific code out of the User model

parent 9b83acfd
......@@ -22,8 +22,6 @@ class User < ActiveRecord::Base
include OptionallySearch
include FromUnion
prepend EE::User
DEFAULT_NOTIFICATION_LEVEL = :participating
ignore_column :external_email
......@@ -230,8 +228,6 @@ class User < ActiveRecord::Base
delegate :notes_filter_for, to: :user_preference
delegate :set_notes_filter, to: :user_preference
accepts_nested_attributes_for :namespace
state_machine :state, initial: :active do
event :block do
transition active: :blocked
......@@ -268,11 +264,6 @@ class User < ActiveRecord::Base
scope :external, -> { where(external: true) }
scope :active, -> { with_state(:active).non_internal }
scope :without_projects, -> { joins('LEFT JOIN project_authorizations ON users.id = project_authorizations.user_id').where(project_authorizations: { user_id: nil }) }
scope :subscribed_for_admin_email, -> { where(admin_email_unsubscribed_at: nil) }
scope :ldap, -> { joins(:identities).where('identities.provider LIKE ?', 'ldap%') }
scope :with_provider, ->(provider) do
joins(:identities).where(identities: { provider: provider })
end
scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'DESC')) }
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) }
scope :confirmed, -> { where.not(confirmed_at: nil) }
......@@ -370,10 +361,6 @@ class User < ActiveRecord::Base
from_union([users, emails])
end
def existing_member?(email)
User.where(email: email).any? || Email.where(email: email).any?
end
def filter(filter_name)
case filter_name
when 'admins'
......@@ -476,7 +463,7 @@ class User < ActiveRecord::Base
def find_by_personal_access_token(token_string)
return unless token_string
PersonalAccessTokensFinder.new(state: 'active').find_by(token: token_string)&.user # rubocop: disable CodeReuse/Finder
PersonalAccessTokensFinder.new(state: 'active').find_by_token(token_string)&.user # rubocop: disable CodeReuse/Finder
end
# Returns a user for the given SSH key.
......@@ -489,11 +476,6 @@ class User < ActiveRecord::Base
namespace&.owner
end
def non_ldap
joins('LEFT JOIN identities ON identities.user_id = users.id')
.where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%')
end
def reference_prefix
'@'
end
......@@ -1111,10 +1093,6 @@ class User < ActiveRecord::Base
end
# rubocop: enable CodeReuse/ServiceClass
def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now
end
def starred?(project)
starred_projects.exists?(project.id)
end
......@@ -1491,15 +1469,6 @@ class User < ActiveRecord::Base
end
end
def generate_token(token_field)
if token_field == :incoming_email_token
# Needs to be all lowercase and alphanumeric because it's gonna be used in an email address.
SecureRandom.hex.to_i(16).to_s(36)
else
super
end
end
def self.unique_internal(scope, username, email_pattern, &block)
scope.first || create_unique_internal(scope, username, email_pattern, &block)
end
......@@ -1542,3 +1511,5 @@ class User < ActiveRecord::Base
Gitlab::ExclusiveLease.cancel(lease_key, uuid)
end
end
User.prepend(EE::User)
......@@ -42,6 +42,14 @@ module EE
scope :excluding_guests, -> { joins(:members).where('members.access_level > ?', ::Gitlab::Access::GUEST).distinct }
scope :subscribed_for_admin_email, -> { where(admin_email_unsubscribed_at: nil) }
scope :ldap, -> { joins(:identities).where('identities.provider LIKE ?', 'ldap%') }
scope :with_provider, ->(provider) do
joins(:identities).where(identities: { provider: provider })
end
accepts_nested_attributes_for :namespace
enum roadmap_layout: { weeks: 1, months: 4, quarters: 12 }
end
......@@ -59,6 +67,15 @@ module EE
def internal_attributes
super + [:support_bot]
end
def non_ldap
joins('LEFT JOIN identities ON identities.user_id = users.id')
.where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%')
end
def existing_member?(email)
::User.where(email: email).any? || ::Email.where(email: email).any?
end
end
def cannot_be_admin_and_auditor
......@@ -161,5 +178,9 @@ module EE
def ldap_sync_time
::Gitlab.config.ldap['sync_time']
end
def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now
end
end
end
......@@ -184,7 +184,7 @@ describe Gitlab::Checks::ChangeAccess do
let(:push_rule) { create(:push_rule, member_check: true) }
before do
allow(User).to receive(:existing_member?).and_return(false)
allow(EE::User).to receive(:existing_member?).and_return(false)
allow_any_instance_of(Commit).to receive(:author_email).and_return('some@mail.com')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment