Skip to content

Instantly share code, notes, and snippets.

@jtushman
Created October 30, 2013 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtushman/7231061 to your computer and use it in GitHub Desktop.
Save jtushman/7231061 to your computer and use it in GitHub Desktop.
stashing some thoughts on how I want to port cancan to python
class User: pass
class Project: pass
class Assignment: pass
def current_user():
return User()
def can(action,classes):
raise NotImplementedException
class Ability:
def __init__(user):
if user.is_admin:
can(MANAGE, ALL)
else:
can(READ, ALL)
can(CREATE, Comment)
def can_edit_comment(comment):
return comment.author == user
can(UPDATE, Comment, can_edit_comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment