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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user