Commit 3151d060 authored by James Fargher's avatar James Fargher

Merge branch 'issue_63781-improve_error_message' into 'master'

Add service desk project key validation error message

See merge request gitlab-org/gitlab!64352
parents 162cd6d9 e022f59b
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert, GlSafeHtmlDirective } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import ServiceDeskSetting from './service_desk_setting.vue'; import ServiceDeskSetting from './service_desk_setting.vue';
...@@ -9,6 +9,9 @@ export default { ...@@ -9,6 +9,9 @@ export default {
GlAlert, GlAlert,
ServiceDeskSetting, ServiceDeskSetting,
}, },
directives: {
SafeHtml: GlSafeHtmlDirective,
},
inject: { inject: {
initialIsEnabled: { initialIsEnabled: {
default: false, default: false,
...@@ -121,7 +124,7 @@ export default { ...@@ -121,7 +124,7 @@ export default {
<template> <template>
<div> <div>
<gl-alert v-if="isAlertShowing" class="mb-3" :variant="alertVariant" @dismiss="onDismiss"> <gl-alert v-if="isAlertShowing" class="mb-3" :variant="alertVariant" @dismiss="onDismiss">
{{ alertMessage }} <span v-safe-html="alertMessage"></span>
</gl-alert> </gl-alert>
<service-desk-setting <service-desk-setting
:is-enabled="isEnabled" :is-enabled="isEnabled"
......
...@@ -8,7 +8,10 @@ class ServiceDeskSetting < ApplicationRecord ...@@ -8,7 +8,10 @@ class ServiceDeskSetting < ApplicationRecord
validate :valid_issue_template validate :valid_issue_template
validate :valid_project_key validate :valid_project_key
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 :project_key,
length: { maximum: 255 },
allow_blank: true,
format: { with: /\A[a-z0-9_]+\z/, message: -> (setting, data) { _("can contain only lowercase letters, digits, and '_'.") } }
scope :with_project_key, ->(key) { where(project_key: key) } scope :with_project_key, ->(key) { where(project_key: key) }
......
...@@ -37898,6 +37898,9 @@ msgstr "" ...@@ -37898,6 +37898,9 @@ msgstr ""
msgid "can contain only letters of the Base64 alphabet (RFC4648) with the addition of '@', ':' and '.'" msgid "can contain only letters of the Base64 alphabet (RFC4648) with the addition of '@', ':' and '.'"
msgstr "" msgstr ""
msgid "can contain only lowercase letters, digits, and '_'."
msgstr ""
msgid "can only be changed by a group admin." msgid "can only be changed by a group admin."
msgstr "" msgstr ""
......
...@@ -10,7 +10,7 @@ RSpec.describe ServiceDeskSetting do ...@@ -10,7 +10,7 @@ RSpec.describe ServiceDeskSetting do
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_length_of(:project_key).is_at_most(255) }
it { is_expected.to allow_value('abc123_').for(: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('abc 12').for(:project_key).with_message("can contain only lowercase letters, digits, and '_'.") }
it { is_expected.not_to allow_value('Big val').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
......
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