Sha256: f2473c1a51bcd04bc6ccd760b36434a40d5eedb8a6a0d0bd8d71da044ec75f3c

Contents?: true

Size: 1001 Bytes

Versions: 7

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

namespace :decidim_system do
  desc "Create a new system admin"
  task create_admin: :environment do
    puts "Please, provide the following attributes to create a new system admin#{" (currently there are existing system admins)" if Decidim::System::Admin.exists?}:"
    email = prompt("email", hidden: false)
    password = prompt("Password")
    password_confirmation = prompt("Password confirmation")

    admin = Decidim::System::Admin.new(email:, password:, password_confirmation:)

    if admin.valid?
      admin.save!
      puts("System admin created successfully")
    else
      puts("Some errors prevented creation of admin:")
      admin.errors.full_messages.uniq.each do |message|
        puts "  * #{message}"
      end
    end
  end
end

def prompt(attribute, hidden: true)
  print("#{attribute}: ")
  input = if hidden
            $stdin.noecho(&:gets).chomp
          else
            $stdin.gets.chomp
          end
  print("\n") if hidden
  input
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-system-0.28.4 lib/tasks/decidim_system.rake
decidim-system-0.28.3 lib/tasks/decidim_system.rake
decidim-system-0.28.2 lib/tasks/decidim_system.rake
decidim-system-0.28.1 lib/tasks/decidim_system.rake
decidim-system-0.28.0 lib/tasks/decidim_system.rake
decidim-system-0.28.0.rc5 lib/tasks/decidim_system.rake
decidim-system-0.28.0.rc4 lib/tasks/decidim_system.rake