Class: ActiveElement::Components::TextSearch::Authorization
- Inherits:
-
Object
- Object
- ActiveElement::Components::TextSearch::Authorization
- Includes:
- Paintbrush
- Defined in:
- lib/active_element/components/text_search/authorization.rb
Overview
Manages authorization for text search, ensures model is configured for text search and that user has correct permissions.
Class Method Summary collapse
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize(model:, params:, user:, search_columns:, value_column:) ⇒ Authorization
constructor
A new instance of Authorization.
- #message(colorize: true) ⇒ Object
Constructor Details
#initialize(model:, params:, user:, search_columns:, value_column:) ⇒ Authorization
Returns a new instance of Authorization.
23 24 25 26 27 28 29 |
# File 'lib/active_element/components/text_search/authorization.rb', line 23 def initialize(model:, params:, user:, search_columns:, value_column:) @model = model @params = params @user = user @search_columns = search_columns @value_column = value_column end |
Class Method Details
.permission_for(model:, field:) ⇒ Object
12 13 14 |
# File 'lib/active_element/components/text_search/authorization.rb', line 12 def (model:, field:) "can_text_search_#{application_name}_#{model.name.underscore.pluralize}_with_#{field}" end |
Instance Method Details
#authorized? ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/active_element/components/text_search/authorization.rb', line 31 def return true if && return false.tap { ActiveElement.warning() } unless Rails.env.development? ActiveElement.warning() true end |
#message(colorize: true) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/active_element/components/text_search/authorization.rb', line 39 def (colorize: true) [ (colorize: colorize), (colorize: colorize) ].compact.join(paintbrush(colorize: colorize) { red '. ' }) end |