Commit 4dc99b0a authored by Vitali Stupin's avatar Vitali Stupin

Updating set-right

Undefined/missing organization or person names will not overwrite names in database, but empty names will.
parent 09d50bd0
......@@ -20,7 +20,7 @@ paths:
- admin
summary: Set right
operationId: setRight
description: Add or update person right
description: Add or update person right. Undefined/missing organization or person names will not overwrite names in database, but empty names will.
responses:
'201':
description: Right added
......
......@@ -56,11 +56,13 @@ def set_person(cur, code, first_name, last_name):
returning id""",
{'code': code, 'first_name': first_name, 'last_name': last_name})
return cur.fetchone()[0]
if current_first_name != first_name or current_last_name != last_name:
if (first_name is not None and current_first_name != first_name) \
or (last_name is not None and current_last_name != last_name):
cur.execute(
"""
update rights.person
set first_name=%(first_name)s, last_name=%(last_name)s
set first_name=COALESCE(%(first_name)s, first_name),
last_name=COALESCE(%(last_name)s, last_name)
where id=%(id)s""",
{'first_name': first_name, 'last_name': last_name, 'id': current_id})
return current_id
......@@ -89,7 +91,7 @@ def set_organization(cur, code, name):
returning id""",
{'code': code, 'name': name})
return cur.fetchone()[0]
if current_name != name:
if name is not None and current_name != name:
cur.execute(
"""
update rights.organization
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment