<commit_before>require "highline"
require "forwardable"

module TrustyCms
  class Setup

    class << self
      def bootstrap(config)
        setup = new
        setup.bootstrap(config)
        setup
      end
    end

    attr_accessor :config

    def bootstrap(config)
      @config = config
      @admin = create_admin_user(config[:admin_name], config[:admin_username], config[:admin_password])
      UserActionObserver.current_user = @admin
      load_default_configuration
      # load_database_template(config[:database_template])
      announce "Finished."
    end

    def create_admin_user(name, username, password)
      unless name and username and password
        announce "Create the admin user (press enter for defaults)."
        name = prompt_for_admin_name unless name
        username = prompt_for_admin_username unless username
        password = <PASSWORD> unless password
      end
      attributes = {
        :name => name,
        :login => username,
        :password => password,
        :password_confirmation => password,
        :admin => true
      }
      admin = User.find_by_login(username)
      admin = User.new unless admin
      admin.update_attributes(attributes)
      admin
    end

    def load_default_configuration
      feedback "\nInitializing configuration" do
        step { TrustyCms::Config['admin.title'   ] = 'TrustyCms CMS' }
        step { TrustyCms::Config['admin.subtitle'] = 'Publishing for Small Teams' }
        step { TrustyCms::Config['defaults.page.parts' ] = 'body, extended' }
        step { TrustyCms::Config['defaults.page.status' ] = 'Draft' }
        step { TrustyCms::Config['defaults.page.filter' ] = nil }
        step { TrustyCms::Config['defaults.page.fields'] = 'Keywords, Description' }
        step { TrustyCms::Config['session_timeout'] = 2.weeks }<commit_msg>setup.rb will now assign admin rights explicitely, not as mass assignment.<commit_after>require "highline"
require "forwardable"

module TrustyCms
  class Setup

    class << self
      def bootstrap(config)
        setup = new
        setup.bootstrap(config)
        setup
      end
    end

    attr_accessor :config

    def bootstrap(config)
      @config = config
      @admin = create_admin_user(config[:admin_name], config[:admin_username], config[:admin_password])
      UserActionObserver.current_user = @admin
      load_default_configuration
      # load_database_template(config[:database_template])
      announce "Finished."
    end

    def create_admin_user(name, username, password)
      unless name and username and password
        announce "Create the admin user (press enter for defaults)."
        name = prompt_for_admin_name unless name
        username = prompt_for_admin_username unless username
        password = prompt_for_admin_password unless password
      end
      attributes = {
        :name => name,
        :login => username,
        :password => password,
        :password_confirmation => password
      }
      admin = User.find_by_login(username)
      admin = User.new unless admin
      admin.update_attributes(attributes)
      admin.admin = true
      admin.save
      admin
    end

    def load_default_configuration
      feedback "\nInitializing configuration" do
        step { TrustyCms::Config['admin.title'   ] = 'TrustyCms CMS' }
        step { TrustyCms::Config['admin.subtitle'] = 'Publishing for Small Teams' }
        step { TrustyCms::Config['defaults.page.parts' ] = 'body, extended' }
        step { TrustyCms::Config['defaults.page.status' ] = 'Draft' }
        step { TrustyCms::Config['defaults.page.filter' ] = nil }
        step { TrustyCms::Config['defaults.page.fields'] = 'Keywords, Description' }
        step { TrustyCms::Config['session_timeout'] = 2.weeks }
{'fraction_non_alphanumeric': 0.09597030752916225, 'fraction_numerical': 0.0005302226935312832, 'mean_word_length': 2.86577868852459, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5289264', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1030, 'n_words': 251}