From 0d82186a783f487e1f9df215524c9779107eccf4 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 14 Jun 2017 17:28:36 +0200 Subject: [PATCH] [bug] db:seed throw an error about admin creation --- CHANGELOG.md | 1 + db/seeds.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d887b9b3..e32b2bbdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## next release +- Fix a bug: when upgrading from version < 2.5.0, `db:seed` will throw an error if ADMIN_EMAIL does not match any admin in database - Fix a bug: hide spaces in public calendar when module is disabled - Fix a bug: confirmation message not shown after admin creation - add task `rake fablab:get_incoherent_invoice` allow find the invoices incoherent diff --git a/db/seeds.rb b/db/seeds.rb index c877a2b84..583af69cf 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -82,8 +82,8 @@ if Group.count == 0 ]) end -# Create the admin if it does not exist yet -if User.find_by(email: Rails.application.secrets.admin_email).nil? +# Create the default admin if none exists yet +if Role.find_by(name: 'admin').users.count === 0 admin = User.new(username: 'admin', email: Rails.application.secrets.admin_email, password: Rails.application.secrets.admin_password, password_confirmation: Rails.application.secrets.admin_password, group_id: Group.first.id, profile_attributes: {first_name: 'admin', last_name: 'admin', gender: true, phone: '0123456789', birthday: Time.now}) admin.add_role 'admin' admin.save!