Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Handle adding and removing relations from Roles.
Browse files Browse the repository at this point in the history
This adds addRelation and removeRelation capabilities to Role, making it possible to add users to the users column and roles to the roles column in a Role object, for example. This prevents the error of Role not having the attribute addRelation or removeRelation when trying to add users or roles to a Role, which is critical for Role functionality.
  • Loading branch information
Marlon committed Jan 16, 2015
1 parent bcbce7c commit 08247c2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions parse_rest/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ def className(self):

def __repr__(self):
return '<Role:%s (Id %s)>' % (getattr(self, 'name', None), self.objectId)

def removeRelation(self, key, className, objectsId):
self.manageRelation('RemoveRelation', key, className, objectsId)

def addRelation(self, key, className, objectsId):
self.manageRelation('AddRelation', key, className, objectsId)

def manageRelation(self, action, key, className, objectsId):
objects = [{
"__type": "Pointer",
"className": className,
"objectId": objectId
} for objectId in objectsId]

payload = {
key: {
"__op": action,
"objects": objects
}
}
self.__class__.PUT(self._absolute_url, **payload)
self.__dict__[key] = ''


Role.Query = QueryManager(Role)

0 comments on commit 08247c2

Please sign in to comment.