I have two datastore model, Group & Products. Products contains two category: Secure & Non Secure. And Each product belongs to a group.
We have 3 type of users: Admin, Normal Users and Group Members (A user can belongs to more than one group).
Admin users have access to all the groups. Normal users(Not belong to any group) have access to only Non Secure products.
Group Members have access to all the products of the groups which he belongs to and All non secure products of groups which he not belongs to.
And We need to query the list of products based on the datastore cursor to fetch 15 records at a time and results should be ordered by last_updated_date.
For Admin, Query:
Select * from Product where Group IN ( Select GroupID from User where firstname.lastname@example.org')
Select * from Product where Secure = No
group_ids_of_user = ['G1', 'G3', 'G5'] query = Product.query(ndb.OR(Product.secure == False, ndb.AND(Product.secure == True, Product.group.IN(group_ids_of_user))))