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
64ef225a
Commit
64ef225a
authored
Jan 22, 2021
by
peterhegman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update frontend to support displaying backend error messages
Display error message from the backend if it exists
parent
2af55ede
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
26 deletions
+94
-26
app/assets/javascripts/members/store/actions.js
app/assets/javascripts/members/store/actions.js
+2
-2
app/assets/javascripts/members/store/mutations.js
app/assets/javascripts/members/store/mutations.js
+22
-8
changelogs/unreleased/217155-role-can-t-be-changed-for-users-not-meeting-domain-restriction.yml
...t-be-changed-for-users-not-meeting-domain-restriction.yml
+6
-0
spec/frontend/members/store/actions_spec.js
spec/frontend/members/store/actions_spec.js
+8
-4
spec/frontend/members/store/mutations_spec.js
spec/frontend/members/store/mutations_spec.js
+56
-12
No files found.
app/assets/javascripts/members/store/actions.js
View file @
64ef225a
...
...
@@ -11,7 +11,7 @@ export const updateMemberRole = async ({ state, commit }, { memberId, accessLeve
commit
(
types
.
RECEIVE_MEMBER_ROLE_SUCCESS
,
{
memberId
,
accessLevel
});
}
catch
(
error
)
{
commit
(
types
.
RECEIVE_MEMBER_ROLE_ERROR
);
commit
(
types
.
RECEIVE_MEMBER_ROLE_ERROR
,
{
error
}
);
throw
error
;
}
...
...
@@ -37,7 +37,7 @@ export const updateMemberExpiration = async ({ state, commit }, { memberId, expi
expiresAt
:
expiresAt
?
formatDate
(
expiresAt
,
'
isoUtcDateTime
'
)
:
null
,
});
}
catch
(
error
)
{
commit
(
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
);
commit
(
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
,
{
error
}
);
throw
error
;
}
...
...
app/assets/javascripts/members/store/mutations.js
View file @
64ef225a
...
...
@@ -13,10 +13,17 @@ export default {
Vue
.
set
(
member
,
'
accessLevel
'
,
accessLevel
);
},
[
types
.
RECEIVE_MEMBER_ROLE_ERROR
](
state
)
{
state
.
errorMessage
=
s__
(
"
Members|An error occurred while updating the member's role, please try again.
"
,
);
[
types
.
RECEIVE_MEMBER_ROLE_ERROR
](
state
,
{
error
})
{
const
message
=
error
.
response
?.
data
?.
message
;
if
(
message
)
{
state
.
errorMessage
=
message
;
}
else
{
state
.
errorMessage
=
s__
(
"
Members|An error occurred while updating the member's role, please try again.
"
,
);
}
state
.
showError
=
true
;
},
[
types
.
RECEIVE_MEMBER_EXPIRATION_SUCCESS
](
state
,
{
memberId
,
expiresAt
})
{
...
...
@@ -28,10 +35,17 @@ export default {
Vue
.
set
(
member
,
'
expiresAt
'
,
expiresAt
);
},
[
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
](
state
)
{
state
.
errorMessage
=
s__
(
"
Members|An error occurred while updating the member's expiration date, please try again.
"
,
);
[
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
](
state
,
{
error
})
{
const
message
=
error
.
response
?.
data
?.
message
;
if
(
message
)
{
state
.
errorMessage
=
message
;
}
else
{
state
.
errorMessage
=
s__
(
"
Members|An error occurred while updating the member's expiration date, please try again.
"
,
);
}
state
.
showError
=
true
;
},
[
types
.
HIDE_ERROR
](
state
)
{
...
...
changelogs/unreleased/217155-role-can-t-be-changed-for-users-not-meeting-domain-restriction.yml
0 → 100644
View file @
64ef225a
---
title
:
Display error message if group member can not be updated because their email
does not match the list of allowed domains
merge_request
:
52014
author
:
type
:
fixed
spec/frontend/members/store/actions_spec.js
View file @
64ef225a
...
...
@@ -57,15 +57,17 @@ describe('Vuex members actions', () => {
describe
(
'
unsuccessful request
'
,
()
=>
{
it
(
`commits
${
types
.
RECEIVE_MEMBER_ROLE_ERROR
}
mutation and throws error`
,
async
()
=>
{
mock
.
onPut
().
networkError
();
const
error
=
new
Error
(
'
Network Error
'
);
mock
.
onPut
().
reply
(()
=>
Promise
.
reject
(
error
));
await
expect
(
testAction
(
updateMemberRole
,
payload
,
state
,
[
{
type
:
types
.
RECEIVE_MEMBER_ROLE_ERROR
,
payload
:
{
error
},
},
]),
).
rejects
.
toThrowError
(
new
Error
(
'
Network Error
'
)
);
).
rejects
.
toThrowError
(
error
);
});
});
});
...
...
@@ -108,15 +110,17 @@ describe('Vuex members actions', () => {
describe
(
'
unsuccessful request
'
,
()
=>
{
it
(
`commits
${
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
}
mutation and throws error`
,
async
()
=>
{
mock
.
onPut
().
networkError
();
const
error
=
new
Error
(
'
Network Error
'
);
mock
.
onPut
().
reply
(()
=>
Promise
.
reject
(
error
));
await
expect
(
testAction
(
updateMemberExpiration
,
{
memberId
,
expiresAt
},
state
,
[
{
type
:
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
,
payload
:
{
error
},
},
]),
).
rejects
.
toThrowError
(
new
Error
(
'
Network Error
'
)
);
).
rejects
.
toThrowError
(
error
);
});
});
});
...
...
spec/frontend/members/store/mutations_spec.js
View file @
64ef225a
...
...
@@ -28,13 +28,35 @@ describe('Vuex members mutations', () => {
});
describe
(
types
.
RECEIVE_MEMBER_ROLE_ERROR
,
()
=>
{
it
(
'
shows error message
'
,
()
=>
{
mutations
[
types
.
RECEIVE_MEMBER_ROLE_ERROR
](
state
);
describe
(
'
when error does not have a message
'
,
()
=>
{
it
(
'
shows default error message
'
,
()
=>
{
mutations
[
types
.
RECEIVE_MEMBER_ROLE_ERROR
](
state
,
{
error
:
new
Error
(
'
Network Error
'
),
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
"
An error occurred while updating the member's role, please try again.
"
,
);
});
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
"
An error occurred while updating the member's role, please try again.
"
,
);
describe
(
'
when error has a message
'
,
()
=>
{
it
(
'
shows error message
'
,
()
=>
{
const
error
=
new
Error
(
'
Request failed with status code 422
'
);
error
.
response
=
{
data
:
{
message
:
'
User email "john.smith@gmail.com" does not match the allowed domain of example.com
'
,
},
};
mutations
[
types
.
RECEIVE_MEMBER_ROLE_ERROR
](
state
,
{
error
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
'
User email "john.smith@gmail.com" does not match the allowed domain of example.com
'
,
);
});
});
});
...
...
@@ -52,13 +74,35 @@ describe('Vuex members mutations', () => {
});
describe
(
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
,
()
=>
{
it
(
'
shows error message
'
,
()
=>
{
mutations
[
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
](
state
);
describe
(
'
when error does not have a message
'
,
()
=>
{
it
(
'
shows default error message
'
,
()
=>
{
mutations
[
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
](
state
,
{
error
:
new
Error
(
'
Network Error
'
),
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
"
An error occurred while updating the member's expiration date, please try again.
"
,
);
});
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
"
An error occurred while updating the member's expiration date, please try again.
"
,
);
describe
(
'
when error has a message
'
,
()
=>
{
it
(
'
shows error message
'
,
()
=>
{
const
error
=
new
Error
(
'
Request failed with status code 422
'
);
error
.
response
=
{
data
:
{
message
:
'
User email "john.smith@gmail.com" does not match the allowed domain of example.com
'
,
},
};
mutations
[
types
.
RECEIVE_MEMBER_EXPIRATION_ERROR
](
state
,
{
error
});
expect
(
state
.
showError
).
toBe
(
true
);
expect
(
state
.
errorMessage
).
toBe
(
'
User email "john.smith@gmail.com" does not match the allowed domain of example.com
'
,
);
});
});
});
});
...
...
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