Commit 5eb48e2e authored by John Hope's avatar John Hope Committed by Tiger Watson

Fix notification when new Service Desk Issue is created

parent ca02d83c
...@@ -764,6 +764,7 @@ class User < ApplicationRecord ...@@ -764,6 +764,7 @@ class User < ApplicationRecord
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'
u.avatar = bot_avatar(image: 'support-bot.png') u.avatar = bot_avatar(image: 'support-bot.png')
u.confirmed_at = Time.zone.now
end end
end end
......
---
title: Fix notification when new Service Desk Issue is created
merge_request: 58803
author:
type: fixed
# frozen_string_literal: true
class ConfirmSupportBotUser < ActiveRecord::Migration[6.0]
SUPPORT_BOT_TYPE = 1
def up
users = Arel::Table.new(:users)
um = Arel::UpdateManager.new
um.table(users)
.where(users[:user_type].eq(SUPPORT_BOT_TYPE))
.where(users[:confirmed_at].eq(nil))
.set([[users[:confirmed_at], Arel::Nodes::NamedFunction.new('COALESCE', [users[:created_at], Arel::Nodes::SqlLiteral.new('NOW()')])]])
connection.execute(um.to_sql)
end
def down
# no op
# The up migration allows for the possibility that the support user might
# have already been manually confirmed. It's not reversible as this data is
# subsequently lost.
end
end
b5f83e3870dc7c70fbde6071725aa2acb3e99f7c2ed050633c34ed35e696ba1e
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe ConfirmSupportBotUser, :migration do
let(:users) { table(:users) }
context 'when support bot user is currently unconfirmed' do
let!(:support_bot) do
create_user!(
created_at: 2.days.ago,
user_type: User::USER_TYPES['support_bot']
)
end
it 'updates the `confirmed_at` attribute' do
expect { migrate! }.to change { support_bot.reload.confirmed_at }
end
it 'sets `confirmed_at` to be the same as their `created_at` attribute' do
migrate!
expect(support_bot.reload.confirmed_at).to eq(support_bot.created_at)
end
end
context 'when support bot user is already confirmed' do
let!(:confirmed_support_bot) do
create_user!(
user_type: User::USER_TYPES['support_bot'],
confirmed_at: 1.day.ago
)
end
it 'does not change their `confirmed_at` attribute' do
expect { migrate! }.not_to change { confirmed_support_bot.reload.confirmed_at }
end
end
context 'when support bot user created_at is null' do
let!(:support_bot) do
create_user!(
user_type: User::USER_TYPES['support_bot'],
confirmed_at: nil,
record_timestamps: false
)
end
it 'updates the `confirmed_at` attribute' do
expect { migrate! }.to change { support_bot.reload.confirmed_at }.from(nil)
end
it 'does not change the `created_at` attribute' do
expect { migrate!}.not_to change { support_bot.reload.created_at }.from(nil)
end
end
context 'with human users that are currently unconfirmed' do
let!(:unconfirmed_human) do
create_user!(
name: 'human',
email: 'human@example.com',
user_type: nil
)
end
it 'does not update their `confirmed_at` attribute' do
expect { migrate! }.not_to change { unconfirmed_human.reload.confirmed_at }
end
end
private
def create_user!(name: 'GitLab Support Bot', email: 'support@example.com', user_type:, created_at: Time.now, confirmed_at: nil, record_timestamps: true)
users.create!(
name: name,
email: email,
username: name,
projects_limit: 0,
user_type: user_type,
confirmed_at: confirmed_at,
record_timestamps: record_timestamps
)
end
end
...@@ -5508,6 +5508,12 @@ RSpec.describe User do ...@@ -5508,6 +5508,12 @@ RSpec.describe User do
it_behaves_like 'bot user avatars', :alert_bot, 'alert-bot.png' it_behaves_like 'bot user avatars', :alert_bot, 'alert-bot.png'
it_behaves_like 'bot user avatars', :support_bot, 'support-bot.png' it_behaves_like 'bot user avatars', :support_bot, 'support-bot.png'
it_behaves_like 'bot user avatars', :security_bot, 'security-bot.png' it_behaves_like 'bot user avatars', :security_bot, 'security-bot.png'
context 'when bot is the support_bot' do
subject { described_class.support_bot }
it { is_expected.to be_confirmed }
end
end end
describe '#confirmation_required_on_sign_in?' do describe '#confirmation_required_on_sign_in?' do
......
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