Commit 556649ef authored by http://jneen.net/'s avatar http://jneen.net/ Committed by Felipe Artur

expose service_desk_enabled and refresh the key

... automatically when it goes from false to true
parent 03fb2a56
......@@ -349,6 +349,7 @@ class ProjectsController < Projects::ApplicationController
mirror_user_id
repository_size_limit
reset_approvals_on_push
service_desk_enabled
]
end
......
......@@ -14,6 +14,8 @@ module EE
delegate :actual_shared_runners_minutes_limit,
:shared_runners_minutes_used?, to: :namespace
before_validation :refresh_service_desk_key
end
def shared_runners_available?
......@@ -23,5 +25,15 @@ module EE
def shared_runners_minutes_limit_enabled?
!public? && shared_runners_enabled? && namespace.shared_runners_minutes_limit_enabled?
end
private
def refresh_service_desk_key
return unless ::Gitlab::EE::ServiceDesk.enabled?
return unless self.service_desk_enabled?
if service_desk_mail_key.blank? || service_desk_enabled_changed?
self.service_desk_mail_key = Devise.friendly_token(16)
end
end
end
end
......@@ -115,4 +115,33 @@ describe Project, models: true do
it { is_expected.to be_falsey }
end
end
describe '#regenerate_service_desk_key' do
subject { create(:project) }
it 'leaves it blank by default' do
expect(subject.service_desk_mail_key).to be_blank
end
it 'updates when enabled' do
subject.service_desk_enabled = true
subject.validate
expect(subject.service_desk_mail_key).not_to be_blank
end
it 'changes when enabled' do
subject.update!(service_desk_mail_key: '12345')
subject.service_desk_enabled = true
expect { subject.validate }.to change { subject.service_desk_mail_key }
end
it 'ensures mail key is never nil when enabled' do
subject.update!(service_desk_enabled: true)
expect { subject.update!(service_desk_mail_key: nil) }
.to change { subject.service_desk_mail_key }
expect(subject.service_desk_mail_key).not_to be_blank
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