Skip to content

Commit

Permalink
template: fix permissions/JSON schema
Browse files Browse the repository at this point in the history
* Fixes templates permissions for update method.
* Fixes JSON schema :
  - user can't update template_type for a template.
  - description field is now displayed as a textarea.

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Sep 14, 2020
1 parent fc16257 commit 2ab20bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
"description": {
"title": "Description",
"type": "string",
"minLength": 1
"minLength": 1,
"form": {
"type": "textarea",
"templateOptions": {
"rows": 3
}
}
},
"organisation": {
"title": "Organisation",
Expand Down Expand Up @@ -75,6 +81,7 @@
"private"
],
"form": {
"fieldMap": "visibility",
"type": "selectWithSort",
"wrappers": [
"form-field-horizontal"
Expand Down Expand Up @@ -106,10 +113,7 @@
"patrons"
],
"form": {
"type": "selectWithSort",
"wrappers": [
"form-field-horizontal"
],
"hideExpression": "true",
"options": [
{
"label": "documents",
Expand All @@ -127,12 +131,7 @@
"label": "patrons",
"value": "patrons"
}
],
"templateOptions": {
"selectWithSortOptions": {
"order": "label"
}
}
]
}
},
"data": {
Expand Down
8 changes: 5 additions & 3 deletions rero_ils/modules/templates/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ def update(cls, user, record):
# - 'librarian' can only update his own private records
# He cannot change the visibility
elif current_patron.is_librarian:
new_template = request.get_json()
if new_template is not None and \
record['visibility'] != new_template['visibility']:
incoming_record = request.get_json(silent=True) or {}
# a librarian cannot change visibility of a template
if incoming_record and incoming_record.get('visibility') \
!= record.get('visibility'):
return False
# a librarian can update its own private record
elif record.is_private and \
record.creator_pid == current_patron.pid:
return True
Expand Down

0 comments on commit 2ab20bd

Please sign in to comment.