Commit 59a5a626 authored by Doug Stull's avatar Doug Stull

Add helpful text to URL group validation and limit text

- better form validation.

Changelog: other
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65369
EE: true
parent 024ced02
...@@ -53,6 +53,10 @@ export default { ...@@ -53,6 +53,10 @@ export default {
type: RegExp, type: RegExp,
required: true, required: true,
}, },
groupUrlErrorMessage: {
type: String,
required: true,
},
}, },
data() { data() {
...@@ -261,6 +265,7 @@ export default { ...@@ -261,6 +265,7 @@ export default {
:group="group" :group="group"
:available-namespaces="availableNamespaces" :available-namespaces="availableNamespaces"
:group-path-regex="groupPathRegex" :group-path-regex="groupPathRegex"
:group-url-error-message="groupUrlErrorMessage"
@update-target-namespace="updateTargetNamespace(group.id, $event)" @update-target-namespace="updateTargetNamespace(group.id, $event)"
@update-new-name="updateNewName(group.id, $event)" @update-new-name="updateNewName(group.id, $event)"
@import-group="importGroups([group.id])" @import-group="importGroups([group.id])"
......
...@@ -44,6 +44,10 @@ export default { ...@@ -44,6 +44,10 @@ export default {
type: RegExp, type: RegExp,
required: true, required: true,
}, },
groupUrlErrorMessage: {
type: String,
required: true,
},
}, },
apollo: { apollo: {
...@@ -200,7 +204,7 @@ export default { ...@@ -200,7 +204,7 @@ export default {
/> />
<p v-if="isInvalid" class="gl-text-red-500 gl-m-0 gl-mt-2"> <p v-if="isInvalid" class="gl-text-red-500 gl-m-0 gl-mt-2">
<template v-if="!isNameValid"> <template v-if="!isNameValid">
{{ __('Please choose a group URL with no special characters.') }} {{ groupUrlErrorMessage }}
</template> </template>
<template v-else-if="invalidNameValidationMessage"> <template v-else-if="invalidNameValidationMessage">
{{ invalidNameValidationMessage }} {{ invalidNameValidationMessage }}
......
...@@ -17,6 +17,7 @@ export function mountImportGroupsApp(mountElement) { ...@@ -17,6 +17,7 @@ export function mountImportGroupsApp(mountElement) {
jobsPath, jobsPath,
sourceUrl, sourceUrl,
groupPathRegex, groupPathRegex,
groupUrlErrorMessage,
} = mountElement.dataset; } = mountElement.dataset;
const apolloProvider = new VueApollo({ const apolloProvider = new VueApollo({
defaultClient: createApolloClient({ defaultClient: createApolloClient({
...@@ -38,6 +39,7 @@ export function mountImportGroupsApp(mountElement) { ...@@ -38,6 +39,7 @@ export function mountImportGroupsApp(mountElement) {
props: { props: {
sourceUrl, sourceUrl,
groupPathRegex: new RegExp(`^(${groupPathRegex})$`), groupPathRegex: new RegExp(`^(${groupPathRegex})$`),
groupUrlErrorMessage,
}, },
}); });
}, },
......
...@@ -322,6 +322,10 @@ module GroupsHelper ...@@ -322,6 +322,10 @@ module GroupsHelper
s_("GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup.").html_safe % { ancestor_group: ancestor_group(group) } s_("GroupSettings|This setting is applied on %{ancestor_group} and has been overridden on this subgroup.").html_safe % { ancestor_group: ancestor_group(group) }
end end
def group_url_error_message
s_('GroupSettings|Please choose a group URL with no special characters or spaces.')
end
def issuables_count_service_class(type) def issuables_count_service_class(type)
if type == :issues if type == :issues
Groups::OpenIssuesCountService Groups::OpenIssuesCountService
......
...@@ -24,6 +24,7 @@ class Namespace < ApplicationRecord ...@@ -24,6 +24,7 @@ class Namespace < ApplicationRecord
NUMBER_OF_ANCESTORS_ALLOWED = 20 NUMBER_OF_ANCESTORS_ALLOWED = 20
SHARED_RUNNERS_SETTINGS = %w[disabled_and_unoverridable disabled_with_override enabled].freeze SHARED_RUNNERS_SETTINGS = %w[disabled_and_unoverridable disabled_with_override enabled].freeze
URL_MAX_LENGTH = 255
cache_markdown_field :description, pipeline: :description cache_markdown_field :description, pipeline: :description
...@@ -58,7 +59,7 @@ class Namespace < ApplicationRecord ...@@ -58,7 +59,7 @@ class Namespace < ApplicationRecord
validates :description, length: { maximum: 255 } validates :description, length: { maximum: 255 }
validates :path, validates :path,
presence: true, presence: true,
length: { maximum: 255 }, length: { maximum: URL_MAX_LENGTH },
namespace_path: true namespace_path: true
# Introduce minimal path length of 2 characters. # Introduce minimal path length of 2 characters.
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
id: 'import_group_path', id: 'import_group_path',
required: true, required: true,
pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
title: _('Please choose a group URL with no special characters.'), title: group_url_error_message,
maxlength: ::Namespace::URL_MAX_LENGTH,
"data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}" "data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}"
%p.validation-error.gl-field-error.field-validation.hide %p.validation-error.gl-field-error.field-validation.hide
= _("Group path is already taken. We've suggested one that is available.") = _("Group path is already taken. We've suggested one that is available.")
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
= f.text_field :path, placeholder: 'open-source', class: 'form-control', = f.text_field :path, placeholder: 'open-source', class: 'form-control',
autofocus: local_assigns[:autofocus] || false, required: true, autofocus: local_assigns[:autofocus] || false, required: true,
pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
title: s_('GroupSettings|Please choose a group URL with no special characters.'), title: group_url_error_message,
maxlength: ::Namespace::URL_MAX_LENGTH,
"data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}" "data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}"
= f.submit s_('GroupSettings|Change group URL'), class: 'btn gl-button btn-warning' = f.submit s_('GroupSettings|Change group URL'), class: 'btn gl-button btn-warning'
......
...@@ -7,4 +7,5 @@ ...@@ -7,4 +7,5 @@
create_bulk_import_path: import_bulk_imports_path(format: :json), create_bulk_import_path: import_bulk_imports_path(format: :json),
jobs_path: realtime_changes_import_bulk_imports_path(format: :json), jobs_path: realtime_changes_import_bulk_imports_path(format: :json),
source_url: @source_url, source_url: @source_url,
group_path_regex: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS } } group_path_regex: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
group_url_error_message: group_url_error_message } }
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
= f.text_field :path, placeholder: _('my-awesome-group'), class: 'form-control js-validate-group-path js-autofill-group-path', data: { qa_selector: 'group_path_field' }, = f.text_field :path, placeholder: _('my-awesome-group'), class: 'form-control js-validate-group-path js-autofill-group-path', data: { qa_selector: 'group_path_field' },
autofocus: local_assigns[:autofocus] || false, required: true, autofocus: local_assigns[:autofocus] || false, required: true,
pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
title: _('Please choose a group URL with no special characters.'), title: group_url_error_message,
maxlength: ::Namespace::URL_MAX_LENGTH,
"data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}" "data-bind-in" => "#{'create_chat_team' if Gitlab.config.mattermost.enabled}"
%p.validation-error.gl-field-error.field-validation.hide %p.validation-error.gl-field-error.field-validation.hide
= _("Group path is already taken. We've suggested one that is available.") = _("Group path is already taken. We've suggested one that is available.")
......
...@@ -33,7 +33,8 @@ ...@@ -33,7 +33,8 @@
= f.text_field :path, class: 'form-control js-validate-group-path js-autofill-group-path', = f.text_field :path, class: 'form-control js-validate-group-path js-autofill-group-path',
required: true, required: true,
pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
title: _('Please choose a group URL with no special characters.') title: group_url_error_message,
maxlength: ::Namespace::URL_MAX_LENGTH
%p.validation-error.gl-field-error.field-validation.hide %p.validation-error.gl-field-error.field-validation.hide
= _("Group path is already taken. We've suggested one that is available.") = _("Group path is already taken. We've suggested one that is available.")
%p.validation-success.gl-field-success.field-validation.hide= _('Group path is available.') %p.validation-success.gl-field-success.field-validation.hide= _('Group path is available.')
......
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
= f.text_field :path, class: 'form-control js-validate-group-path', = f.text_field :path, class: 'form-control js-validate-group-path',
autofocus: local_assigns[:autofocus] || false, required: true, autofocus: local_assigns[:autofocus] || false, required: true,
pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS,
title: _('Please choose a group URL with no special characters.') title: group_url_error_message,
maxlength: ::Namespace::URL_MAX_LENGTH
%p.validation-error.gl-field-error.field-validation.hide %p.validation-error.gl-field-error.field-validation.hide
= _("Group path is already taken. We've suggested one that is available.") = _("Group path is already taken. We've suggested one that is available.")
%p.validation-success.gl-field-success.field-validation.hide= _('Group path is available.') %p.validation-success.gl-field-success.field-validation.hide= _('Group path is available.')
......
...@@ -15892,7 +15892,7 @@ msgstr "" ...@@ -15892,7 +15892,7 @@ msgstr ""
msgid "GroupSettings|Pipeline settings was updated for the group" msgid "GroupSettings|Pipeline settings was updated for the group"
msgstr "" msgstr ""
msgid "GroupSettings|Please choose a group URL with no special characters." msgid "GroupSettings|Please choose a group URL with no special characters or spaces."
msgstr "" msgstr ""
msgid "GroupSettings|Prevent forking outside of the group" msgid "GroupSettings|Prevent forking outside of the group"
...@@ -24533,9 +24533,6 @@ msgstr "" ...@@ -24533,9 +24533,6 @@ msgstr ""
msgid "Please choose a file" msgid "Please choose a file"
msgstr "" msgstr ""
msgid "Please choose a group URL with no special characters."
msgstr ""
msgid "Please complete your profile with email address" msgid "Please complete your profile with email address"
msgstr "" msgstr ""
......
...@@ -52,7 +52,7 @@ RSpec.describe 'Group' do ...@@ -52,7 +52,7 @@ RSpec.describe 'Group' do
click_button 'Create group' click_button 'Create group'
expect(current_path).to eq(new_group_path) expect(current_path).to eq(new_group_path)
expect(page).to have_text('Please choose a group URL with no special characters.') expect(page).to have_text('Please choose a group URL with no special characters or spaces.')
end end
end end
......
...@@ -70,6 +70,7 @@ describe('import table row', () => { ...@@ -70,6 +70,7 @@ describe('import table row', () => {
propsData: { propsData: {
availableNamespaces: availableNamespacesFixture, availableNamespaces: availableNamespacesFixture,
groupPathRegex: /.*/, groupPathRegex: /.*/,
groupUrlErrorMessage: 'Please choose a group URL with no special characters or spaces.',
...props, ...props,
}, },
}); });
...@@ -198,7 +199,9 @@ describe('import table row', () => { ...@@ -198,7 +199,9 @@ describe('import table row', () => {
groupPathRegex: /^[a-zA-Z]+$/, groupPathRegex: /^[a-zA-Z]+$/,
}); });
expect(wrapper.text()).toContain('Please choose a group URL with no special characters.'); expect(wrapper.text()).toContain(
'Please choose a group URL with no special characters or spaces.',
);
}); });
it('reports invalid group name if relevant validation error exists', async () => { it('reports invalid group name if relevant validation error exists', async () => {
......
...@@ -62,6 +62,7 @@ describe('import table', () => { ...@@ -62,6 +62,7 @@ describe('import table', () => {
propsData: { propsData: {
groupPathRegex: /.*/, groupPathRegex: /.*/,
sourceUrl: SOURCE_URL, sourceUrl: SOURCE_URL,
groupUrlErrorMessage: 'Please choose a group URL with no special characters or spaces.',
}, },
stubs: { stubs: {
GlSprintf, GlSprintf,
......
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