Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forbid copyright licence for non moderator #1890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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