Created
October 30, 2013 11:23
-
-
Save jtushman/7231061 to your computer and use it in GitHub Desktop.
stashing some thoughts on how I want to port cancan to python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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