Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web
Commits
2dad88b4
Commit
2dad88b4
authored
3 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
mailmaps: Make error handling more robust when 'from_email' is missing/empty.
parent
0bcfbb21
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!719
mailmaps: Make error handling more robust when 'from_email' is missing/empty.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/web/auth/mailmap.py
+11
-6
11 additions, 6 deletions
swh/web/auth/mailmap.py
swh/web/tests/auth/test_mailmap.py
+3
-2
3 additions, 2 deletions
swh/web/tests/auth/test_mailmap.py
with
14 additions
and
8 deletions
swh/web/auth/mailmap.py
+
11
−
6
View file @
2dad88b4
...
...
@@ -41,12 +41,18 @@ def profile_add_mailmap(request: Request) -> HttpResponse:
if
not
request
.
user
.
has_perm
(
MAILMAP_PERMISSION
):
return
HttpResponseForbidden
()
from_email
=
request
.
data
.
pop
(
"
from_email
"
,
None
)
if
not
from_email
:
return
HttpResponseBadRequest
(
"'
from_email
'
must be provided and non-empty.
"
)
try
:
UserMailmap
.
objects
.
create
(
user_id
=
str
(
request
.
user
.
id
),
**
request
.
data
)
UserMailmap
.
objects
.
create
(
user_id
=
str
(
request
.
user
.
id
),
from_email
=
from_email
,
**
request
.
data
)
except
IntegrityError
:
return
HttpResponseBadRequest
(
"
This
'
from_email
'
already exists.
"
)
mm
=
UserMailmap
.
objects
.
get
(
user_id
=
str
(
request
.
user
.
id
),
from_email
=
request
.
data
.
get
(
"
from_email
"
)
user_id
=
str
(
request
.
user
.
id
),
from_email
=
from_email
)
return
Response
(
UserMailmapSerializer
(
mm
).
data
)
...
...
@@ -56,10 +62,9 @@ def profile_update_mailmap(request: Request) -> HttpResponse:
if
not
request
.
user
.
has_perm
(
MAILMAP_PERMISSION
):
return
HttpResponseForbidden
()
try
:
from_email
=
request
.
data
.
pop
(
"
from_email
"
)
except
KeyError
:
return
HttpResponseBadRequest
(
"
Missing from_email value
"
)
from_email
=
request
.
data
.
pop
(
"
from_email
"
,
None
)
if
not
from_email
:
return
HttpResponseBadRequest
(
"'
from_email
'
must be provided and non-empty.
"
)
user_id
=
str
(
request
.
user
.
id
)
...
...
This diff is collapsed.
Click to expand it.
swh/web/tests/auth/test_mailmap.py
+
3
−
2
View file @
2dad88b4
...
...
@@ -85,11 +85,12 @@ def test_mailmap_endpoints_error_response(api_client, mailmap_user):
api_client
.
force_login
(
mailmap_user
)
url
=
reverse
(
"
profile-mailmap-add
"
)
resp
=
check_api_post_response
(
api_client
,
url
,
status_code
=
5
00
)
assert
"
exception
"
in
resp
.
data
resp
=
check_api_post_response
(
api_client
,
url
,
status_code
=
4
00
)
assert
b
"
from_email
"
in
resp
.
content
url
=
reverse
(
"
profile-mailmap-update
"
)
resp
=
check_api_post_response
(
api_client
,
url
,
status_code
=
400
)
assert
b
"
from_email
"
in
resp
.
content
@pytest.mark.django_db
(
transaction
=
True
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment