Skip to content
Newer
Older
100644 54 lines (46 sloc) 1.93 KB
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
1 module CanCan
2 # A general CanCan exception
3 class Error < StandardError; end
dfd84a1 @ryanb improving inline documentation
authored
4
ec616ae @ryanb moving accessible_by out into ModelAdditions module
authored
5 # Raised when behavior is not implemented, usually used in an abstract class.
6 class NotImplemented < Error; end
7
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
8 # Raised when removed code is called, an alternative solution is provided in message.
9 class ImplementationRemoved < Error; end
dfd84a1 @ryanb improving inline documentation
authored
10
1af6c6f @ryanb adding check_authorization and skip_authorization controller class me…
authored
11 # Raised when using check_authorization without calling authorized!
12 class AuthorizationNotPerformed < Error; end
13
346ca2c @ryanb check authorization is sufficient in an after_filter when doing enabl…
authored
14 # Raised when enable_authorization is used and not fully authorized by the end of the action
15 class InsufficientAuthorizationCheck < Error; end
16
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
17 # This error is raised when a user isn't allowed to access a given controller action.
283f58e @ryanb improving readme with links to wiki
authored
18 # This usually happens within a call to ControllerAdditions#authorize! but can be
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
19 # raised manually.
dfd84a1 @ryanb improving inline documentation
authored
20 #
cf2896f @ryanb renaming AccessDenied exception to Unauthorized
authored
21 # raise CanCan::Unauthorized.new("Not authorized!", :read, Article)
dfd84a1 @ryanb improving inline documentation
authored
22 #
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
23 # The passed message, action, and subject are optional and can later be retrieved when
24 # rescuing from the exception.
dfd84a1 @ryanb improving inline documentation
authored
25 #
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
26 # exception.message # => "Not authorized!"
27 # exception.action # => :read
28 # exception.subject # => Article
dfd84a1 @ryanb improving inline documentation
authored
29 #
30 # If the message is not specified (or is nil) it will default to "You are not authorized
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
31 # to access this page." This default can be overridden by setting default_message.
dfd84a1 @ryanb improving inline documentation
authored
32 #
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
33 # exception.default_message = "Default error message"
34 # exception.message # => "Default error message"
dfd84a1 @ryanb improving inline documentation
authored
35 #
cf2896f @ryanb renaming AccessDenied exception to Unauthorized
authored
36 # See ControllerAdditions#authorize! for more information on rescuing from this exception
bf9b8ad @ryanb filling in some inline documentation for 1.4
authored
37 # and customizing the message using I18n.
cf2896f @ryanb renaming AccessDenied exception to Unauthorized
authored
38 class Unauthorized < Error
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
39 attr_reader :action, :subject
40 attr_writer :default_message
dfd84a1 @ryanb improving inline documentation
authored
41
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
42 def initialize(message = nil, action = nil, subject = nil)
43 @message = message
44 @action = action
45 @subject = subject
1c3e617 @nhocki Change the i18n default name to :"unauthorized.default"
nhocki authored
46 @default_message = I18n.t(:"unauthorized.default", :default => "You are not authorized to access this page.")
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
47 end
dfd84a1 @ryanb improving inline documentation
authored
48
8903fee @ryanb removing unauthorized! in favor of authorize! and including more info…
authored
49 def to_s
50 @message || @default_message
51 end
52 end
53 end
Something went wrong with that request. Please try again.