Skip to content

Commit

Permalink
Merge pull request #1890 from msdegetel/fix/1213-forbid-some-licence
Browse files Browse the repository at this point in the history
forbid copyright licence for non moderator
  • Loading branch information
brunobesson authored Feb 6, 2025
2 parents b588c7b + 721f5bb commit 03bec42
Show file tree
Hide file tree
Showing 2 changed files with 60 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
11 changes: 8 additions & 3 deletions c2corg_api/views/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ 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 03bec42

Please sign in to comment.