Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
40bcda62
Commit
40bcda62
authored
Aug 18, 2020
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add server-sent name-field validation errors
parent
34ac2c84
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
ee/app/assets/javascripts/approvals/components/rule_form.vue
ee/app/assets/javascripts/approvals/components/rule_form.vue
+30
-7
No files found.
ee/app/assets/javascripts/approvals/components/rule_form.vue
View file @
40bcda62
...
...
@@ -13,6 +13,10 @@ const DEFAULT_NAME_FOR_LICENSE_REPORT = 'License-Check';
const
DEFAULT_NAME_FOR_VULNERABILITY_CHECK
=
'
Vulnerability-Check
'
;
const
READONLY_NAMES
=
[
DEFAULT_NAME_FOR_LICENSE_REPORT
,
DEFAULT_NAME_FOR_VULNERABILITY_CHECK
];
function
mapServerResponseToValidationErrors
(
messages
)
{
return
Object
.
entries
(
messages
).
flatMap
(([
key
,
msgs
])
=>
msgs
.
map
(
msg
=>
`
${
key
}
${
msg
}
`
));
}
export
default
{
components
:
{
ApproversList
,
...
...
@@ -50,6 +54,7 @@ export default {
showValidation
:
false
,
isFallback
:
false
,
containsHiddenGroups
:
false
,
serverValidationErrors
:
[],
...
this
.
getInitialData
(),
};
// TODO: Remove feature flag in https://gitlab.com/gitlab-org/gitlab/-/issues/235114
...
...
@@ -98,11 +103,17 @@ export default {
return
invalidObject
;
},
invalidName
()
{
if
(
!
this
.
isMultiSubmission
)
{
return
''
;
let
error
=
''
;
if
(
this
.
isMultiSubmission
)
{
if
(
this
.
serverValidationErrors
.
includes
(
'
name has already been taken
'
))
{
error
=
__
(
'
Rule name is already taken.
'
);
}
else
if
(
!
this
.
name
)
{
error
=
__
(
'
Please provide a name
'
);
}
}
return
!
this
.
name
?
__
(
'
Please provide a name
'
)
:
''
;
return
error
;
},
invalidApprovalsRequired
()
{
if
(
!
isNumber
(
this
.
approvalsRequired
))
{
...
...
@@ -204,15 +215,27 @@ export default {
* - Multi rule?
*/
submit
()
{
let
submission
;
this
.
serverValidationErrors
=
[];
if
(
!
this
.
validate
())
{
return
Promise
.
resolve
();
submission
=
Promise
.
resolve
();
}
else
if
(
this
.
isFallbackSubmission
)
{
return
this
.
submitFallback
();
submission
=
this
.
submitFallback
();
}
else
if
(
!
this
.
isMultiSubmission
)
{
return
this
.
submitSingleRule
();
submission
=
this
.
submitSingleRule
();
}
else
{
submission
=
this
.
submitRule
();
}
return
this
.
submitRule
();
submission
.
catch
(
failureResponse
=>
{
this
.
serverValidationErrors
=
mapServerResponseToValidationErrors
(
failureResponse
?.
response
?.
data
?.
message
||
{},
);
});
return
submission
;
},
/**
* Submit the rule, by either put-ing or post-ing.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment