A user should not be able to vote on own content

This should be hidden in the UI as well, but the backend should support this too.
We also want to set initial rating of 1 for contents that need it.

This commit includes a new unittest for this case.

Reviewers: sybren

Differential Revision: https://developer.blender.org/D2825
This commit is contained in:
Dalai Felinto
2017-09-04 21:27:30 +02:00
parent eb467474f8
commit 216b9278af
2 changed files with 19 additions and 1 deletions

View File

@@ -41,11 +41,15 @@ def vote_comment(user_id, node_id, patch):
'$or': [{'properties.ratings.$.user': {'$exists': False}},
{'properties.ratings.$.user': user_id}]}
node = nodes_coll.find_one(node_query,
projection={'properties': 1})
projection={'properties': 1, 'user': 1})
if node is None:
log.warning('User %s wanted to patch non-existing node %s' % (user_id, node_id))
raise wz_exceptions.NotFound('Node %s not found' % node_id)
# We don't allow the user to down/upvote their own nodes.
if user_id == node['user']:
raise wz_exceptions.Forbidden('You cannot vote on your own node')
props = node['properties']
# Find the current rating (if any)