Skip to content

Latest commit

 

History

History
121 lines (83 loc) · 3.96 KB

README.md

File metadata and controls

121 lines (83 loc) · 3.96 KB

Tell us who you employ

A Rails app and OAuth consumer, backed by a PostgreSQL database.

It allows users to review and update details of who they employ, for compliance reasons.

For Buckinghamshire Council's family information team.

It uses Outpost as an identity provider, but could be adapted to use any OAuth 2.0 provider.

Running it locally

Using docker compose:

Docker compose also includes an Outpost (production) instance as well. Since it is using the production environment you will need to setup ngrok or uncomment the https-portal service in the docker-compose.yml file. It is recommended to setup a static domain on your ngrok account, so that when you create your oAuth app you don't need to update the url everytime you load the application!

cp -rp sample.env .env
docker compose up -d

# if using Outpost setup https in front of it
ngrok http --domain=STATICDOMAIN 3000

# outpost setup
docker compose exec outpost bin/herokuish procfile exec bin/rails SEED_ADMIN_USER=true db:seed
docker compose exec outpost bin/herokuish procfile exec bin/rails SEED_DEFAULT_DATA=true db:seed
docker compose exec outpost bin/herokuish procfile exec bin/rails SEED_DUMMY_DATA=true db:seed
# or
docker compose exec outpost bin/herokuish procfile exec bin/rails SEED_ADMIN_USER=true SEED_DEFAULT_DATA=true SEED_DUMMY_DATA=true db:seed

# add the staffing portal as an oAuth application
docker compose exec outpost bin/herokuish procfile exec bin/rails c
app = Doorkeeper::Application.create!(name: "tell-us-who-you-employ", scopes: 'public', redirect_uri: "https://localhost:3004/auth/outpost/callback")
app.uid #OAUTH_CLIENT_ID
app.secret #OAUTH_SECRET
# On dev you will need to update the url to http in the database manually to get around doorkeepers validation

# add the values in .env file and run up -d again
docker compose up -d

# Seed the staff portal database with fake data
docker compose exec app bin/rails db:seed

Staffing portal will be on: localhost:3004 and outpost will be on your ngrok url (or another outpost instance).

NB outposturl/oauth/applications gives you access to the gui for managing applications, you will need superadmin priviledges to access it.

docker compose exec outpost bin/herokuish procfile exec bin/rails c
user = User.find_by(email: '[email protected]')
user.superadmin = true
user.save

On your local machine:


cp -rp sample.env .env
uncomment DATABASE_URL line
yarn
bundle install
rails db:setup
rails s
rails db:seed

Config

You need to set the following environment variables for it to work:


OAUTH_SERVER
OAUTH_CLIENT_ID
OAUTH_SECRET

Locally, you can use a .env file in the project root.

If you're using it with Outpost, you can get these from /oauth/applications while logged in as an administrator.

The redirect URI ends in .../auth/outpost/callback.

Running it on the web

Suitable for Heroku and other 12-factor compliant hosting.

Tests

docker compose exec app bash -c "DISABLE_SPRING=1 NODE_ENV=development RAILS_ENV=test bundle exec rspec"
docker compose exec app bash -c "DISABLE_SPRING=1 NODE_ENV=development RAILS_ENV=test bundle exec rspec ./spec/models/service_spec.rb"

Services

If the service names become badly out of sync we can manually update them all.

--in tell us db
--get all the needed service_ids
select distinct service_id from employees
--in outpost db
--get the information we need
select id, name, created_at, updated_at from services where id in (9, 7, 12)
require 'csv'

CSV.foreach('staging_employee_services_data.csv', headers: true) do |service_data|
  puts "Service.upsert({ id: #{service_data['id']}, name: \"#{service_data['name']}\", created_at: \"#{service_data['created_at']}\", updated_at: \"#{service_data['updated_at']}\" })"
end