Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
f7ac455a
Commit
f7ac455a
authored
4 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent updating an element's zone to an invalid image
parent
f48813bd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!913
Prevent updating an element's zone to an invalid image
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/elements.py
+3
-1
3 additions, 1 deletion
arkindex/documents/serializers/elements.py
arkindex/documents/tests/test_patch_elements.py
+21
-0
21 additions, 0 deletions
arkindex/documents/tests/test_patch_elements.py
with
24 additions
and
1 deletion
arkindex/documents/serializers/elements.py
+
3
−
1
View file @
f7ac455a
...
...
@@ -251,7 +251,6 @@ class ElementSerializer(ElementSlimSerializer):
return
instance
def
update
(
self
,
instance
,
validated_data
):
image
=
validated_data
.
pop
(
'
image
'
,
None
)
polygon
=
validated_data
.
pop
(
'
polygon
'
,
None
)
if
polygon
or
image
:
...
...
@@ -263,6 +262,9 @@ class ElementSerializer(ElementSlimSerializer):
})
image
=
instance
.
zone
.
image
if
image
.
width
==
0
or
image
.
height
==
0
:
raise
ValidationError
({
'
image
'
:
[
'
This image does not have valid dimensions.
'
]})
if
not
polygon
:
if
instance
.
zone
:
polygon
=
instance
.
zone
.
polygon
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_patch_elements.py
+
21
−
0
View file @
f7ac455a
...
...
@@ -195,6 +195,27 @@ class TestPatchElements(FixtureAPITestCase):
self
.
assertEqual
(
self
.
vol
.
zone
.
polygon
.
width
,
20
)
self
.
assertEqual
(
self
.
vol
.
zone
.
polygon
.
height
,
10
)
def
test_patch_element_invalid_dimensions
(
self
):
self
.
client
.
force_login
(
self
.
user
)
self
.
assertIsNone
(
self
.
vol
.
zone
)
bad_image
=
self
.
imgsrv
.
images
.
create
(
path
=
'
oh-no
'
,
status
=
S3FileStatus
.
Unchecked
,
width
=
0
,
height
=
0
,
)
response
=
self
.
client
.
patch
(
reverse
(
'
api:element-retrieve
'
,
kwargs
=
{
'
pk
'
:
str
(
self
.
vol
.
id
)}),
data
=
{
'
image
'
:
str
(
bad_image
.
id
),
'
polygon
'
:
[[
10
,
20
],
[
10
,
30
],
[
30
,
30
],
[
30
,
20
],
[
10
,
20
]],
},
format
=
'
json
'
,
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
image
'
:
[
'
This image does not have valid dimensions.
'
]})
self
.
assertIsNone
(
self
.
vol
.
zone
)
def
test_element_patch_type_allowed_transcription
(
self
):
"""
The base number of requests is increased by 1 because
...
...
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