Class: Decidim::ActionAuthorizer
- Inherits:
-
Object
- Object
- Decidim::ActionAuthorizer
- Includes:
- Wisper::Publisher
- Defined in:
- app/services/decidim/action_authorizer.rb
Overview
This class is used to authorize a user against an action in the context of a feature.
Defined Under Namespace
Classes: AuthorizationError, AuthorizationStatus
Instance Method Summary collapse
-
#authorize ⇒ Object
Public: Broadcasts different events given the status of the authentication.
-
#initialize(user, feature, action) ⇒ ActionAuthorizer
constructor
Initializes the ActionAuthorizer.
Constructor Details
#initialize(user, feature, action) ⇒ ActionAuthorizer
Initializes the ActionAuthorizer.
user - The user to authorize against. feature - The feature to authenticate against. action - The action to authenticate.
14 15 16 17 18 |
# File 'app/services/decidim/action_authorizer.rb', line 14 def initialize(user, feature, action) @user = user @feature = feature @action = action.to_s if action end |
Instance Method Details
#authorize ⇒ Object
Public: Broadcasts different events given the status of the authentication.
Broadcasts:
failed - When no valid can be found.
- When an was found, but didn't match the credentials.
incomplete - An authorization was found, but lacks some required fields. User
should re-authenticate.
Returns nil.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/decidim/action_authorizer.rb', line 29 def raise AuthorizationError, "Missing data" unless feature && action return status(:ok) unless return status(:missing, handler: ) unless return status(:invalid, handler: , fields: unmatched_fields) if unmatched_fields.any? return status(:incomplete, handler: , fields: missing_fields) if missing_fields.any? status(:ok) end |