Class: ActiveElement::Components::TextSearch::Authorization

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

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 permission_for(model:, field:)
  "can_text_search_#{application_name}_#{model.name.underscore.pluralize}_with_#{field}"
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/active_element/components/text_search/authorization.rb', line 31

def authorized?
  return true if authorized_model? && authorized_user?
  return false.tap { ActiveElement.warning(message) } unless Rails.env.development?

  ActiveElement.warning(development_message)
  true
end

#message(colorize: true) ⇒ Object



39
40
41
42
43
44
# File 'lib/active_element/components/text_search/authorization.rb', line 39

def message(colorize: true)
  [
    missing_authorization_message(colorize: colorize),
    missing_permissions_message(colorize: colorize)
  ].compact.join(paintbrush(colorize: colorize) { red '. ' })
end