Use str2id(x) instead of ObjectId(x)
The latter produces an internal server error if 'x' is not a valid ObjectId, whereas the fromer produces a 400 Bad Request.
This commit is contained in:
@@ -41,6 +41,8 @@ def project_manage_users():
|
|||||||
No changes are done on the project itself.
|
No changes are done on the project itself.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from pillar.api.utils import str2id
|
||||||
|
|
||||||
projects_collection = current_app.data.driver.db['projects']
|
projects_collection = current_app.data.driver.db['projects']
|
||||||
users_collection = current_app.data.driver.db['users']
|
users_collection = current_app.data.driver.db['users']
|
||||||
|
|
||||||
@@ -57,8 +59,8 @@ def project_manage_users():
|
|||||||
|
|
||||||
# The request is not a form, since it comes from the API sdk
|
# The request is not a form, since it comes from the API sdk
|
||||||
data = json.loads(request.data)
|
data = json.loads(request.data)
|
||||||
project_id = ObjectId(data['project_id'])
|
project_id = str2id(data['project_id'])
|
||||||
target_user_id = ObjectId(data['user_id'])
|
target_user_id = str2id(data['user_id'])
|
||||||
action = data['action']
|
action = data['action']
|
||||||
current_user_id = g.current_user['user_id']
|
current_user_id = g.current_user['user_id']
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user