forked from 0x2620/pandora
{me}
This commit is contained in:
parent
e56faadb95
commit
a19de36f3e
1 changed files with 16 additions and 5 deletions
|
@ -14,7 +14,7 @@ import utils
|
|||
from ox.django.query import QuerySet
|
||||
|
||||
|
||||
def parseCondition(condition, user):
|
||||
def parseCondition(condition, user, owner=None):
|
||||
'''
|
||||
condition: {
|
||||
value: "war"
|
||||
|
@ -60,6 +60,17 @@ def parseCondition(condition, user):
|
|||
if k == 'list':
|
||||
key_type = ''
|
||||
|
||||
if v == '{me}' and op == '==':
|
||||
if not owner:
|
||||
owner = user
|
||||
if k == 'user':
|
||||
v = ownder.username
|
||||
elif k == 'groups':
|
||||
q = Q(groups__in=owner.groups.all())
|
||||
if exclude:
|
||||
q = ~q
|
||||
return q
|
||||
|
||||
if (not exclude and op == '=' or op in ('$', '^')) and v == '':
|
||||
return Q()
|
||||
elif k == 'filename' and (user.is_anonymous() or \
|
||||
|
@ -159,7 +170,7 @@ def parseCondition(condition, user):
|
|||
data = l.query
|
||||
q = parseConditions(data.get('conditions', []),
|
||||
data.get('operator', '&'),
|
||||
user)
|
||||
user, l.user)
|
||||
else:
|
||||
q = Q(id__in=l.items.all())
|
||||
if exclude:
|
||||
|
@ -205,7 +216,7 @@ def parseCondition(condition, user):
|
|||
q = ~q
|
||||
return q
|
||||
|
||||
def parseConditions(conditions, operator, user):
|
||||
def parseConditions(conditions, operator, user, owner=None):
|
||||
'''
|
||||
conditions: [
|
||||
{
|
||||
|
@ -228,9 +239,9 @@ def parseConditions(conditions, operator, user):
|
|||
for condition in conditions:
|
||||
if 'conditions' in condition:
|
||||
q = parseConditions(condition['conditions'],
|
||||
condition.get('operator', '&'), user)
|
||||
condition.get('operator', '&'), user, owner)
|
||||
else:
|
||||
q = parseCondition(condition, user)
|
||||
q = parseCondition(condition, user, owner)
|
||||
if isinstance(q, list):
|
||||
conn += q
|
||||
elif q:
|
||||
|
|
Loading…
Reference in a new issue