Sha256: 1c0beff98d63cb42d12307a60ca0461a543c055ba5699549aab35b5857c02bba

Contents?: true

Size: 1002 Bytes

Versions: 7

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

namespace :decidim_system do
  desc "Creates 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.29.2 lib/tasks/decidim_system.rake
decidim-system-0.29.1 lib/tasks/decidim_system.rake
decidim-system-0.29.0 lib/tasks/decidim_system.rake
decidim-system-0.29.0.rc4 lib/tasks/decidim_system.rake
decidim-system-0.29.0.rc3 lib/tasks/decidim_system.rake
decidim-system-0.29.0.rc2 lib/tasks/decidim_system.rake
decidim-system-0.29.0.rc1 lib/tasks/decidim_system.rake