mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: Do not send staff welcome message if user already has role
This commit is contained in:
@ -19,6 +19,7 @@ module Roleable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def grant_moderation!
|
def grant_moderation!
|
||||||
|
return if moderator
|
||||||
set_permission('moderator', true)
|
set_permission('moderator', true)
|
||||||
auto_approve_user
|
auto_approve_user
|
||||||
enqueue_staff_welcome_message(:moderator)
|
enqueue_staff_welcome_message(:moderator)
|
||||||
@ -29,6 +30,7 @@ module Roleable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def grant_admin!
|
def grant_admin!
|
||||||
|
return if admin
|
||||||
set_permission('admin', true)
|
set_permission('admin', true)
|
||||||
auto_approve_user
|
auto_approve_user
|
||||||
enqueue_staff_welcome_message(:admin)
|
enqueue_staff_welcome_message(:admin)
|
||||||
|
@ -164,6 +164,30 @@ describe User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'enqueue_staff_welcome_message' do
|
||||||
|
let!(:first_admin) { Fabricate(:admin) }
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
it 'enqueues message for admin' do
|
||||||
|
expect {
|
||||||
|
user.grant_admin!
|
||||||
|
}.to change { Jobs::SendSystemMessage.jobs.count }.by 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'enqueues message for moderator' do
|
||||||
|
expect {
|
||||||
|
user.grant_moderation!
|
||||||
|
}.to change { Jobs::SendSystemMessage.jobs.count }.by 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'skips the message if already an admin' do
|
||||||
|
user.update(admin: true)
|
||||||
|
expect {
|
||||||
|
user.grant_admin!
|
||||||
|
}.to change { Jobs::SendSystemMessage.jobs.count }.by 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '.set_default_tags_preferences' do
|
context '.set_default_tags_preferences' do
|
||||||
let(:tag) { Fabricate(:tag) }
|
let(:tag) { Fabricate(:tag) }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user