Class: Decidim::ActionAuthorizer

Inherits:
Object
  • Object
show all
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

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

#authorizeObject

Public: Broadcasts different events given the status of the authentication.

Broadcasts:

failed       - When no valid authorization can be found.
unauthorized - When an authorization 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
# File 'app/services/decidim/action_authorizer.rb', line 29

def authorize
  status_code, fields = *status_data

  status(status_code, fields || {})
end