Skip to content

Commit

Permalink
forbid copyright licence for non moderator
Browse files Browse the repository at this point in the history
  • Loading branch information
ms950927 committed Oct 16, 2024
1 parent 659c98a commit 1a14a8a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
52 changes: 52 additions & 0 deletions c2corg_api/tests/views/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,58 @@ def test_change_image_type_collaborative(self):
self._prefix + '/' + str(self.image.document_id), body,
headers=headers, status=400)

def test_change_image_type_copyright(self):
"""Test that a non-moderator user cannot change the image_type
to copyright
"""
body = {
'message': 'Update',
'document': {
'document_id': self.image.document_id,
'version': self.image.version,
'filename': self.image.filename,
'quality': quality_types[1],
'activities': ['paragliding'],
'image_type': 'copyright',
'height': 1500,
'locales': [
{'lang': 'en', 'title': 'Mont Blanc from the air',
'description': '...',
'version': self.locale_en.version}
]
}
}
headers = self.add_authorization_header(username='contributor')
self.app_put_json(
self._prefix + '/' + str(self.image.document_id), body,
headers=headers, status=403)

def test_change_image_type_copyright_moderator(self):
"""Test that a moderator user can change the image_type
to copyright
"""
body = {
'message': 'Update',
'document': {
'document_id': self.image.document_id,
'version': self.image.version,
'filename': self.image.filename,
'quality': quality_types[1],
'activities': ['paragliding'],
'image_type': 'copyright',
'height': 1500,
'locales': [
{'lang': 'en', 'title': 'Mont Blanc from the air',
'description': '...',
'version': self.locale_en.version}
]
}
}
headers = self.add_authorization_header(username='moderator')
self.app_put_json(
self._prefix + '/' + str(self.image.document_id), body,
headers=headers, status=200)

def test_change_image_type_collaborative_moderator(self):
"""Test that a moderator can change the image_type
of collaborative images
Expand Down
9 changes: 6 additions & 3 deletions c2corg_api/views/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ def put(self):
image = DBSession.query(Image).get(image_id)
if image is None:
raise HTTPNotFound('No image found for id {}'.format(image_id))
if image.image_type == 'collaborative':
image_type = self.request.validated['document']['image_type']
if image_type != image.image_type:
new_image_type = self.request.validated['document']['image_type']
if new_image_type == 'copyright':
if new_image_type != image.image_type:
raise HTTPForbidden('No permission to change to copyright type')
elif image.image_type == 'collaborative':
if new_image_type != image.image_type:
raise HTTPBadRequest(
'Image type cannot be changed for collaborative images'
)
Expand Down

0 comments on commit 1a14a8a

Please sign in to comment.