Created
March 5, 2009 10:43
-
-
Save lennartkoopmann/74290 to your computer and use it in GitHub Desktop.
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
def permission? | |
user = current_user | |
controller = params[:controller] | |
action = params[:action] | |
id = params[:id] | |
# Okay, the user is an administrator. Allow all access. | |
return true if user.admin | |
# Fine grained access rules. | |
# Allow changing own profile. | |
return true if controller == "users" and (action == "edit" or action == "update") and id == user.id.to_s | |
# User is no admin and no access rule allowed access. | |
flash[:error] = "Sorry. You must be an administrator to perform this action." | |
redirect_back_or_default('/') | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment