From 772958f6bb928db435aedcdb072d9bd941ecf404 Mon Sep 17 00:00:00 2001 From: Rebecca O'Neill <rebecca.e.oneill3@gmail.com> Date: Wed, 15 Jan 2025 16:59:52 +0000 Subject: [PATCH] Update seeds.rb file to create global admin and confirmed users --- README.md | 10 ++++++++++ db/seeds.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index c0b0665949..eb1805bae1 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ git submodule update --init --recursive This links the main repo to the [BOPS applicants project](https://github.com/unboxed/bops-applicants/). +If it's your first time setting up the project or you are changing the docker file first run: + +```sh +docker compose build +``` + Then build and launch the images: ```sh @@ -231,3 +237,7 @@ After adding a new Stimulus controller run `./bin/rails stimulus:manifest:update ## Front-end components As much as possible, we follow the GOV.UK Design System. The HTML components can be found here [here](https://design-system.service.gov.uk/get-started). For help with forms we use the [GOV.UK Ruby on Rails Form Builder gem](https://govuk-form-builder.netlify.app). See [here](https://github.com/unboxed/bops/blob/main/app/views/users/_form.html.erb) for a simple example of implementation. + +## Creating users + +The seed file will automatically create and confirm users for each role and subdomain as well as a global admin user. You will need to update the password for this user. \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 89a1a3657c..9b27cf1139 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -26,6 +26,18 @@ end end +User.find_or_create_by!(role: "global_administrator") do |user| + user.role = "global_administrator" + user.password = PasswordGenerator.call + user.otp_required_for_login = false + user.name = "#{Faker::Name.first_name} #{Faker::Name.last_name}" + user.email = "globaladmin@example.com" +end + +User.find_each do |user| + user.confirm unless user.confirmed? +end + fixture["decisions"].each do |attrs| Decision.find_or_create_by!(attrs.slice("code")) do |decision| decision.assign_attributes(attrs)