From b0c5d8ec66dba6749b5cd97b7b39f06caf2667e5 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 11 Jun 2018 14:49:42 +0000 Subject: [PATCH 1/2] Rakefile: add task to create initial users --- README.md | 11 ++--------- Rakefile | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2145c51e4..215480a7e 100644 --- a/README.md +++ b/README.md @@ -81,16 +81,9 @@ Dans le fichier `config/intializers/token.rb`, ajouter *Note : les valeurs pour ces paramètres sont renseignées dans le Keepass* -## Création des comptes initiaux - - bin/rails console - > email = "" - > password = "" - > Administration.create(email: email, password: password) - > Administrateur.create(email: email, password: password) - > Gestionnaire.create(email: email, password: password) - > User.create(email: email, password: password) +## Création d'un compte de test initial en local + bin/rake create_test_account -- --email=EMAIL --password=PASSWORD ## Lancement de l'application diff --git a/Rakefile b/Rakefile index 186e5b1ed..fd0227a64 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,27 @@ require File.expand_path('config/application', __dir__) Rails.application.load_tasks +desc "Create a test account that includes all roles" +task :create_test_account => :environment do + email, password = nil + optparse = OptionParser.new do |opts| + opts.banner = "Usage: rake create_test_account -- --email=EMAIL --password=PASSWORD" + opts.on("--email ARG", String) { |e| email = e } + opts.on("--password ARG", String) { |p| password = p } + end + args = optparse.order!(ARGV) {} + optparse.parse!(args) + + raise optparse.banner if email.nil? || password.nil? + raise "Password must be at least 8 characters." if password.length < 8 + + Administration.create!(email: email, password: password) + Administrateur.create!(email: email, password: password) + Gestionnaire.create!(email: email, password: password) + User.create!(email: email, password: password, confirmed_at: DateTime.now) + puts "Test account #{email} created" +end + task :deploy do domains = %w(37.187.249.111 149.202.72.152 149.202.198.6) domains.each do |domain| From e50cc68e75f83ce4bcf8dd242188057e4385a52b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 12 Jun 2018 11:45:16 +0000 Subject: [PATCH 2/2] Rakefile: move first user creation to db/seeds.rb --- README.md | 10 ++++------ Rakefile | 21 --------------------- db/seeds.rb | 14 +++++++++++--- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 215480a7e..c9373aa70 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Les informations nécessaire à l'initialisation de la base doivent être pré-c Afin de générer la BDD de l'application, il est nécessaire d'exécuter les commandes suivantes : - # Create and load the schema for both databases - bin/rails db:create db:schema:load + # Create and initialize the database + bin/rails db:create db:schema:load db:seed # Migrate the development database and the test database bin/rails db:migrate @@ -81,14 +81,12 @@ Dans le fichier `config/intializers/token.rb`, ajouter *Note : les valeurs pour ces paramètres sont renseignées dans le Keepass* -## Création d'un compte de test initial en local - - bin/rake create_test_account -- --email=EMAIL --password=PASSWORD - ## Lancement de l'application overmind s +Un utilisateur de test est disponible, avec les identifiants `test@exemple.fr`/`testpassword`. + ## Programmation des jobs AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later diff --git a/Rakefile b/Rakefile index fd0227a64..186e5b1ed 100644 --- a/Rakefile +++ b/Rakefile @@ -5,27 +5,6 @@ require File.expand_path('config/application', __dir__) Rails.application.load_tasks -desc "Create a test account that includes all roles" -task :create_test_account => :environment do - email, password = nil - optparse = OptionParser.new do |opts| - opts.banner = "Usage: rake create_test_account -- --email=EMAIL --password=PASSWORD" - opts.on("--email ARG", String) { |e| email = e } - opts.on("--password ARG", String) { |p| password = p } - end - args = optparse.order!(ARGV) {} - optparse.parse!(args) - - raise optparse.banner if email.nil? || password.nil? - raise "Password must be at least 8 characters." if password.length < 8 - - Administration.create!(email: email, password: password) - Administrateur.create!(email: email, password: password) - Gestionnaire.create!(email: email, password: password) - User.create!(email: email, password: password, confirmed_at: DateTime.now) - puts "Test account #{email} created" -end - task :deploy do domains = %w(37.187.249.111 149.202.72.152 149.202.198.6) domains.each do |domain| diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857..ef9828967 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,15 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). + # -# Examples: +# Create an initial user who can use all roles # -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) + +default_user = "test@exemple.fr" +default_password = "testpassword" + +puts "Create test user '#{default_user}'" +Administration.create!(email: default_user, password: default_password) +Administrateur.create!(email: default_user, password: default_password) +Gestionnaire.create!(email: default_user, password: default_password) +User.create!(email: default_user, password: default_password, confirmed_at: DateTime.now)