Commit 9f1088dc authored by Peter Leitzen's avatar Peter Leitzen

Remove User#internal_attributes method

It's not needed anymore as we've replaced boolean `support_bot` with
enum `bot_type`.
parent 73be26e8
...@@ -537,20 +537,16 @@ class User < ApplicationRecord ...@@ -537,20 +537,16 @@ class User < ApplicationRecord
username username
end end
def self.internal_attributes
[:ghost]
end
def internal? def internal?
self.class.internal_attributes.any? { |a| self[a] } ghost?
end end
def self.internal def self.internal
where(Hash[internal_attributes.zip([true] * internal_attributes.size)]) where(ghost: true)
end end
def self.non_internal def self.non_internal
where(internal_attributes.map { |attr| "#{attr} IS NOT TRUE" }.join(" AND ")) where('ghost IS NOT TRUE')
end end
# #
......
...@@ -70,21 +70,32 @@ module EE ...@@ -70,21 +70,32 @@ module EE
# Note: When adding an option, it's value MUST equal to the last value + 1. # Note: When adding an option, it's value MUST equal to the last value + 1.
enum group_view: { details: 1, security_dashboard: 2 }, _prefix: true enum group_view: { details: 1, security_dashboard: 2 }, _prefix: true
scope :group_view_details, -> { where('group_view = ? OR group_view IS NULL', group_view[:details]) } scope :group_view_details, -> { where('group_view = ? OR group_view IS NULL', group_view[:details]) }
enum bot_type: {
support_bot: 1
}
end end
class_methods do class_methods do
extend ::Gitlab::Utils::Override
def support_bot def support_bot
email_pattern = "support%s@#{Settings.gitlab.host}" email_pattern = "support%s@#{Settings.gitlab.host}"
unique_internal(where(support_bot: true), 'support-bot', email_pattern) do |u| unique_internal(where(bot_type: :support_bot), 'support-bot', email_pattern) do |u|
u.bio = 'The GitLab support bot used for Service Desk' u.bio = 'The GitLab support bot used for Service Desk'
u.name = 'GitLab Support Bot' u.name = 'GitLab Support Bot'
end end
end end
# override override :internal
def internal_attributes def internal
super + [:support_bot] super.or(where.not(bot_type: nil))
end
override :non_internal
def non_internal
super.where(bot_type: nil)
end end
def non_ldap def non_ldap
...@@ -224,6 +235,14 @@ module EE ...@@ -224,6 +235,14 @@ module EE
super super
end end
def internal?
super || bot?
end
def bot?
bot_type.present?
end
protected protected
override :password_required? override :password_required?
......
...@@ -519,4 +519,31 @@ describe User do ...@@ -519,4 +519,31 @@ describe User do
end end
end end
end end
describe 'internal methods' do
let!(:user) { create(:user) }
let!(:ghost) { User.ghost }
let!(:support_bot) { User.support_bot }
let!(:non_internal) { [user] }
let!(:internal) { [ghost, support_bot] }
it 'returns non internal users' do
expect(User.internal).to eq(internal)
expect(internal.all?(&:internal?)).to eq(true)
end
it 'returns internal users' do
expect(User.non_internal).to eq(non_internal)
expect(non_internal.all?(&:internal?)).to eq(false)
end
describe '#bot?' do
it 'marks bot users' do
expect(user.bot?).to eq(false)
expect(ghost.bot?).to eq(false)
expect(support_bot.bot?).to eq(true)
end
end
end
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