lib/simple_auth/authentication.rb in di-simple_auth-0.2.1 vs lib/simple_auth/authentication.rb in di-simple_auth-0.2.2
- old
+ new
@@ -22,10 +22,15 @@
#
# @return [User, nil]
def current_user
@_current_user ||= user_from_cookie
end
+
+
+ def current_permission(invoice)
+ @_current_permission ||= permission_from_token(invoice)
+ end
# Set the current user
#
# @param [User]
def current_user=(user)
@@ -93,9 +98,17 @@
protected
def user_from_cookie
if token = cookies[:remember_token]
::User.find_by_remember_token(token)
+ end
+ end
+
+ def permission_from_token(invoice)
+ if current_user
+ current_user.permissions(invoice).max(&:index)
+ elsif params[:token][10..-1]
+ ::Permission.find_by_token(token)
end
end
def store_location
if request.get?
\ No newline at end of file