Class: RubyCms::RunSetupAdmin

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/cli.rb

Overview

Logic for the interactive first-admin setup. Uses Thor::Shell for prompts.

Constant Summary collapse

ADMIN_PERMISSION_KEYS =
%w[
  manage_admin manage_permissions manage_content_blocks manage_visitor_errors manage_analytics
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell:) ⇒ RunSetupAdmin

Returns a new instance of RunSetupAdmin.



34
35
36
# File 'lib/ruby_cms/cli.rb', line 34

def initialize(shell:)
  @shell = shell
end

Class Method Details

.call(shell: Thor::Shell::Basic.new) ⇒ Object



29
30
31
# File 'lib/ruby_cms/cli.rb', line 29

def call(shell: Thor::Shell::Basic.new)
  new(shell:).call
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_cms/cli.rb', line 38

def call
  RubyCms::Permission.ensure_defaults!
  user_class = Rails.application.config.ruby_cms.user_class_name.constantize
  email_attr = user_class.column_names.include?("email_address") ? :email_address : :email

  user = choose_or_create_user(user_class, email_attr)
  return if user.nil?

  grant_permissions(user)
  notify_success(user, email_attr)
end