Sha256: 3df7197bf9b0466957bad925a21af2193a18cd554a3bd80d0772b69ac7137d84

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

puts "Loading ThecoreAuthCommons seeds"
email = ENV["ADMIN_EMAIL"].presence || "admin@example.com"
psswd = ENV["ADMIN_PASSWORD"].presence || "changeme"

unless User.where(admin: true).exists?
    u = User.find_or_initialize_by(email: email)
    u.username = "Administrator" if u.respond_to? :username=
    u.password = u.password_confirmation = psswd
    u.admin = true
    u.save(validate: false)
end

@values = {
    predicates: %i[can cannot],
    actions: %i[manage create read update destroy],
    targets: ApplicationRecord.subclasses.map {|d| d.to_s.underscore}.to_a.unshift(:all)
}

def fill table
    model = table.to_s.classify.constantize
    model.reset_column_information
    model.upsert_all @values[table].map { |p| {name: p, created_at: Time.now, updated_at: Time.now} }, unique_by: [:name]
end

fill :predicates
fill :actions
fill :targets

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thecore_auth_commons-3.0.8 db/seeds.rb