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

Commit

Permalink
Merge pull request milesrichardson#85 from mcastle/acl_patch
Browse files Browse the repository at this point in the history
ACL patch
  • Loading branch information
David Robinson committed Jan 30, 2015
2 parents 24237b4 + 3fe3810 commit 251b782
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,33 @@ star_func(movie="The Matrix")

ACLs
---------------
The ACL for an object can be updated using the `parse_rest.datatypes.ACL` class. Updating an ACL requires JSON to be passed to ACL. For example, using the User and gameScore examples from above:
The ACL for an object can be updated using the `parse_rest.datatypes.ACL` class. This class provides three methods for setting an ACL: set_user, set_role, and set_default. For example, using the User and gameScore examples from above:
~~~~~ {python}
from parse_rest.datatypes import ACL
from parse_rest.user import User
u = User.login('dhelmet', '12345')
gameScore.ACL = ACL({'*': {'read': True}, u.objectId: {'read': True, 'write': True}})
gameScore.ACL.set_user(u, read=True, write=True)
# allows user 'dhelmet' to read and write to gameScore
gameScore.ACL.set_default(read=True)
# allows public to read but not write to gameScore
gameScore.ACL.set_role('moderators', read=True, write=True)
# allows role 'moderators' to read and write to gameScore. Can alternatively pass the role object instead of the
# role name. See below for more info on Roles.
gameScore.save()
~~~~~

This updates the gameScore ACL and allows only the user 'dhelmet' to write to gameScore, while allowing 'dhelmet' and the public to read gameScore. Parse uses '*' to denote the public key.


Roles
---------------
You can create, update or delete roles as well, using the `parse_rest.role.Role` class. Creating a role requires you to pass a name and an ACL to Role.
~~~~~ {python}
from parse_rest.role import Role
from parse_rest.datatypes import ACL
admin_role = Role(name='moderators')
admin_role.ACL = ACL({'*': {'read': True}})
admin_role.ACL.set_default(read=True)
admin_role.save()
~~~~~

Expand Down
4 changes: 2 additions & 2 deletions parse_rest/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def set_default(self, read=False, write=False):

def set_role(self, role, read=False, write=False):
if isinstance(role, ParseResource):
self._set_permissions("role:%s" % role.name, read, write)
self._set_permission("role:%s" % role.name, read, write)
else:
self._set_permissions("role:%s" % role, read, write)
self._set_permission("role:%s" % role, read, write)

def set_user(self, user, read=False, write=False):
if isinstance(user, ParseResource):
Expand Down

0 comments on commit 251b782

Please sign in to comment.