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 ...@@ -22,8 +22,6 @@ class User < ActiveRecord::Base
include OptionallySearch include OptionallySearch
include FromUnion include FromUnion
prepend EE::User
DEFAULT_NOTIFICATION_LEVEL = :participating DEFAULT_NOTIFICATION_LEVEL = :participating
ignore_column :external_email ignore_column :external_email
...@@ -230,8 +228,6 @@ class User < ActiveRecord::Base ...@@ -230,8 +228,6 @@ class User < ActiveRecord::Base
delegate :notes_filter_for, to: :user_preference delegate :notes_filter_for, to: :user_preference
delegate :set_notes_filter, to: :user_preference delegate :set_notes_filter, to: :user_preference
accepts_nested_attributes_for :namespace
state_machine :state, initial: :active do state_machine :state, initial: :active do
event :block do event :block do
transition active: :blocked transition active: :blocked
...@@ -268,11 +264,6 @@ class User < ActiveRecord::Base ...@@ -268,11 +264,6 @@ class User < ActiveRecord::Base
scope :external, -> { where(external: true) } scope :external, -> { where(external: true) }
scope :active, -> { with_state(:active).non_internal } 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 :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_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 :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) }
scope :confirmed, -> { where.not(confirmed_at: nil) } scope :confirmed, -> { where.not(confirmed_at: nil) }
...@@ -370,10 +361,6 @@ class User < ActiveRecord::Base ...@@ -370,10 +361,6 @@ class User < ActiveRecord::Base
from_union([users, emails]) from_union([users, emails])
end end
def existing_member?(email)
User.where(email: email).any? || Email.where(email: email).any?
end
def filter(filter_name) def filter(filter_name)
case filter_name case filter_name
when 'admins' when 'admins'
...@@ -476,7 +463,7 @@ class User < ActiveRecord::Base ...@@ -476,7 +463,7 @@ class User < ActiveRecord::Base
def find_by_personal_access_token(token_string) def find_by_personal_access_token(token_string)
return unless 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 end
# Returns a user for the given SSH key. # Returns a user for the given SSH key.
...@@ -489,11 +476,6 @@ class User < ActiveRecord::Base ...@@ -489,11 +476,6 @@ class User < ActiveRecord::Base
namespace&.owner namespace&.owner
end 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 def reference_prefix
'@' '@'
end end
...@@ -1111,10 +1093,6 @@ class User < ActiveRecord::Base ...@@ -1111,10 +1093,6 @@ class User < ActiveRecord::Base
end end
# rubocop: enable CodeReuse/ServiceClass # rubocop: enable CodeReuse/ServiceClass
def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now
end
def starred?(project) def starred?(project)
starred_projects.exists?(project.id) starred_projects.exists?(project.id)
end end
...@@ -1491,15 +1469,6 @@ class User < ActiveRecord::Base ...@@ -1491,15 +1469,6 @@ class User < ActiveRecord::Base
end end
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) def self.unique_internal(scope, username, email_pattern, &block)
scope.first || create_unique_internal(scope, username, email_pattern, &block) scope.first || create_unique_internal(scope, username, email_pattern, &block)
end end
...@@ -1542,3 +1511,5 @@ class User < ActiveRecord::Base ...@@ -1542,3 +1511,5 @@ class User < ActiveRecord::Base
Gitlab::ExclusiveLease.cancel(lease_key, uuid) Gitlab::ExclusiveLease.cancel(lease_key, uuid)
end end
end end
User.prepend(EE::User)
...@@ -42,6 +42,14 @@ module EE ...@@ -42,6 +42,14 @@ module EE
scope :excluding_guests, -> { joins(:members).where('members.access_level > ?', ::Gitlab::Access::GUEST).distinct } 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 } enum roadmap_layout: { weeks: 1, months: 4, quarters: 12 }
end end
...@@ -59,6 +67,15 @@ module EE ...@@ -59,6 +67,15 @@ module EE
def internal_attributes def internal_attributes
super + [:support_bot] super + [:support_bot]
end 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 end
def cannot_be_admin_and_auditor def cannot_be_admin_and_auditor
...@@ -161,5 +178,9 @@ module EE ...@@ -161,5 +178,9 @@ module EE
def ldap_sync_time def ldap_sync_time
::Gitlab.config.ldap['sync_time'] ::Gitlab.config.ldap['sync_time']
end end
def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now
end
end end
end end
...@@ -184,7 +184,7 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -184,7 +184,7 @@ describe Gitlab::Checks::ChangeAccess do
let(:push_rule) { create(:push_rule, member_check: true) } let(:push_rule) { create(:push_rule, member_check: true) }
before do 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') allow_any_instance_of(Commit).to receive(:author_email).and_return('some@mail.com')
end 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