Commit 76c48f7f authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'sdesk-name-db' into 'master'

Add project_key column

See merge request gitlab-org/gitlab!24063
parents 064696e1 38416e8c
---
title: Added migration which adds project_key column to service_desk_settings.
merge_request: 24063
author:
type: added
# frozen_string_literal: true
class AddServiceDeskProjectKey < ActiveRecord::Migration[5.2]
DOWNTIME = false
def change
add_column :service_desk_settings, :project_key, :string, limit: 255
end
end
...@@ -3797,6 +3797,7 @@ ActiveRecord::Schema.define(version: 2020_02_04_131054) do ...@@ -3797,6 +3797,7 @@ ActiveRecord::Schema.define(version: 2020_02_04_131054) do
create_table "service_desk_settings", primary_key: "project_id", id: :bigint, default: nil, force: :cascade do |t| create_table "service_desk_settings", primary_key: "project_id", id: :bigint, default: nil, force: :cascade do |t|
t.string "issue_template_key", limit: 255 t.string "issue_template_key", limit: 255
t.string "outgoing_name", limit: 255 t.string "outgoing_name", limit: 255
t.string "project_key", limit: 255
end end
create_table "services", id: :serial, force: :cascade do |t| create_table "services", id: :serial, force: :cascade do |t|
......
...@@ -196,6 +196,12 @@ module EE ...@@ -196,6 +196,12 @@ module EE
joins('LEFT JOIN services ON services.project_id = projects.id AND services.type = \'GitlabSlackApplicationService\' AND services.active IS true') joins('LEFT JOIN services ON services.project_id = projects.id AND services.type = \'GitlabSlackApplicationService\' AND services.active IS true')
.where('services.id IS NULL') .where('services.id IS NULL')
end end
def find_by_service_desk_project_key(key)
# project_key is not indexed for now
# see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24063#note_282435524 for details
joins(:service_desk_setting).find_by('service_desk_settings.project_key' => key)
end
end end
def can_store_security_reports? def can_store_security_reports?
......
...@@ -7,6 +7,8 @@ class ServiceDeskSetting < ApplicationRecord ...@@ -7,6 +7,8 @@ class ServiceDeskSetting < ApplicationRecord
validates :project_id, presence: true validates :project_id, presence: true
validate :valid_issue_template validate :valid_issue_template
validates :outgoing_name, length: { maximum: 255 }, allow_blank: true validates :outgoing_name, length: { maximum: 255 }, allow_blank: true
validates :project_key, length: { maximum: 255 }, allow_blank: true, format: { with: /\A[a-z0-9_]+\z/ }
validates_uniqueness_of :project_key
def issue_template_content def issue_template_content
strong_memoize(:issue_template_content) do strong_memoize(:issue_template_content) do
......
...@@ -170,6 +170,20 @@ describe Project do ...@@ -170,6 +170,20 @@ describe Project do
expect(described_class.with_active_prometheus_service).not_to include(project_without_active_prometheus_service) expect(described_class.with_active_prometheus_service).not_to include(project_without_active_prometheus_service)
end end
end end
describe '.find_by_service_desk_project_key' do
it 'returns the correct project' do
project2 = create(:project)
create(:service_desk_setting, project: project, project_key: 'key1')
create(:service_desk_setting, project: project2, project_key: 'key2')
expect(Project.find_by_service_desk_project_key('key2')).to eq(project2)
end
it 'returns nil if there is no project with the key' do
expect(Project.find_by_service_desk_project_key('some_key')).to be_nil
end
end
end end
describe 'validations' do describe 'validations' do
......
...@@ -4,8 +4,15 @@ require 'spec_helper' ...@@ -4,8 +4,15 @@ require 'spec_helper'
describe ServiceDeskSetting do describe ServiceDeskSetting do
describe 'validations' do describe 'validations' do
subject(:service_desk_setting) { create(:service_desk_setting) }
it { is_expected.to validate_presence_of(:project_id) } it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_length_of(:outgoing_name).is_at_most(255) } it { is_expected.to validate_length_of(:outgoing_name).is_at_most(255) }
it { is_expected.to validate_length_of(:project_key).is_at_most(255) }
it { is_expected.to validate_uniqueness_of(:project_key) }
it { is_expected.to allow_value('abc123_').for(:project_key) }
it { is_expected.not_to allow_value('abc 12').for(:project_key) }
it { is_expected.not_to allow_value('Big val').for(:project_key) }
describe '.valid_issue_template' do describe '.valid_issue_template' do
let_it_be(:project) { create(:project, :custom_repo, files: { '.gitlab/issue_templates/service_desk.md' => 'template' }) } let_it_be(:project) { create(:project, :custom_repo, files: { '.gitlab/issue_templates/service_desk.md' => 'template' }) }
......
...@@ -783,6 +783,7 @@ ZoomMeeting: ...@@ -783,6 +783,7 @@ ZoomMeeting:
ServiceDeskSetting: ServiceDeskSetting:
- project_id - project_id
- issue_template_key - issue_template_key
- project_key
ContainerExpirationPolicy: ContainerExpirationPolicy:
- created_at - created_at
- updated_at - updated_at
......
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