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
5b367f1d
Commit
5b367f1d
authored
4 years ago
by
Manon Blanco
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow corpus admin to delete transcriptions from worker
parent
e4b0fd82
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/api/ml.py
+5
-3
5 additions, 3 deletions
arkindex/documents/api/ml.py
arkindex/documents/tests/test_edit_transcriptions.py
+36
-3
36 additions, 3 deletions
arkindex/documents/tests/test_edit_transcriptions.py
with
41 additions
and
6 deletions
arkindex/documents/api/ml.py
+
5
−
3
View file @
5b367f1d
...
...
@@ -111,7 +111,8 @@ class TranscriptionCreate(CreateAPIView):
class
TranscriptionEdit
(
RetrieveUpdateDestroyAPIView
):
"""
Retrieve or edit a transcription
Edition and deletion are allowed for manual transcriptions only
Edition and deletion are allowed for manual transcriptions
Edition and deletion of non-manual transcriptions are allowed for the admin
"""
serializer_class
=
TranscriptionSerializer
permission_classes
=
(
IsVerified
,
)
...
...
@@ -133,10 +134,11 @@ class TranscriptionEdit(RetrieveUpdateDestroyAPIView):
rights
=
transcription
.
element
.
corpus
.
get_acl_rights
(
request
.
user
)
errors
=
defaultdict
(
list
)
non_manual_transcription
=
bool
(
transcription
.
worker_version
or
transcription
.
source
and
transcription
.
source
.
slug
!=
'
manual
'
)
if
Right
.
Write
not
in
rights
:
errors
[
'
__all__
'
].
append
(
'
A write access to transcription element corpus is required.
'
)
if
transcription
.
worker_version
or
transcription
.
source
and
transcription
.
source
.
slug
!=
'
manual
'
:
errors
[
'
__all__
'
].
append
(
'
Only manual transcription
s can be edited
.
'
)
if
Right
.
Admin
not
in
rights
and
non_manual_transcription
:
errors
[
'
__all__
'
].
append
(
'
Only
admins can edit non-
manual transcription.
'
)
if
(
errors
):
raise
PermissionDenied
(
errors
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_edit_transcriptions.py
+
36
−
3
View file @
5b367f1d
...
...
@@ -29,6 +29,11 @@ class TestEditTranscription(FixtureAPITestCase):
cls
.
private_read_user
.
verified_email
=
True
cls
.
private_read_user
.
save
()
private_corpus
.
corpus_right
.
create
(
user
=
cls
.
private_read_user
)
# Create an user with a write right only on the corpus
cls
.
write_user
=
User
.
objects
.
create_user
(
'
bla@bla.bla
'
,
'
aa
'
)
cls
.
write_user
.
verified_email
=
True
cls
.
write_user
.
save
()
cls
.
corpus
.
corpus_right
.
create
(
user
=
cls
.
write_user
,
can_write
=
True
)
def
setUp
(
self
):
self
.
manual_source
=
DataSource
.
objects
.
create
(
type
=
MLToolType
.
Recognizer
,
slug
=
'
manual
'
,
internal
=
False
)
...
...
@@ -101,6 +106,34 @@ class TestEditTranscription(FixtureAPITestCase):
self
.
assertEqual
(
data
.
get
(
'
id
'
),
str
(
self
.
manual_transcription
.
id
))
self
.
assertEqual
(
data
.
get
(
'
text
'
),
'
Once upon a time in a castle
'
)
def
test_transcription_patch_not_manual
(
self
):
# self.user is the admin of the corpus, he can edit a worker transcription
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
patch
(
reverse
(
'
api:transcription-edit
'
,
kwargs
=
{
'
pk
'
:
self
.
ml_transcription
.
id
}),
format
=
'
json
'
,
data
=
{
'
text
'
:
'
Once upon a time in a castle
'
}
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
data
=
response
.
json
()
self
.
assertEqual
(
data
.
get
(
'
id
'
),
str
(
self
.
ml_transcription
.
id
))
self
.
assertEqual
(
data
.
get
(
'
text
'
),
'
Once upon a time in a castle
'
)
def
test_transcription_patch_internal_user
(
self
):
self
.
private_read_user
.
is_internal
=
True
self
.
private_read_user
.
save
()
self
.
client
.
force_login
(
self
.
private_read_user
)
response
=
self
.
client
.
patch
(
reverse
(
'
api:transcription-edit
'
,
kwargs
=
{
'
pk
'
:
self
.
ml_transcription
.
id
}),
format
=
'
json
'
,
data
=
{
'
text
'
:
'
He used to play the Bumbulum
'
}
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
data
=
response
.
json
()
self
.
assertEqual
(
data
.
get
(
'
id
'
),
str
(
self
.
ml_transcription
.
id
))
self
.
assertEqual
(
data
.
get
(
'
text
'
),
'
He used to play the Bumbulum
'
)
def
test_transcription_patch_text_only
(
self
):
"""
Assert only transcription text can be updated
...
...
@@ -154,11 +187,11 @@ class TestEditTranscription(FixtureAPITestCase):
'
__all__
'
:
[
'
A write access to transcription element corpus is required.
'
]
})
def
test_transcription_patch_
not_manual
(
self
):
def
test_transcription_patch_
admin_right
(
self
):
"""
Updating a transcription produced by a ML worker is forbidden
"""
self
.
client
.
force_login
(
self
.
user
)
self
.
client
.
force_login
(
self
.
write_
user
)
response
=
self
.
client
.
patch
(
reverse
(
'
api:transcription-edit
'
,
kwargs
=
{
'
pk
'
:
self
.
ml_transcription
.
id
}),
format
=
'
json
'
,
...
...
@@ -166,7 +199,7 @@ class TestEditTranscription(FixtureAPITestCase):
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
self
.
assertDictEqual
(
response
.
json
(),
{
'
__all__
'
:
[
'
Only manual transcription
s can be edited
.
'
]
'
__all__
'
:
[
'
Only
admins can edit non-
manual transcription.
'
]
})
def
test_manual_transcription_delete
(
self
):
...
...
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