Giter Site home page Giter Site logo

forms-admin's Introduction

GOV.UK Forms Admin Tests

GOV.UK Forms is a service for creating forms. GOV.UK Forms Admin is a an application to handle the administration, design and publishing of those forms. It's a Ruby on Rails application built on a PostgreSQL database.

Before you start

To run the project you will need to install:

  • Ruby - we use version 3 of Ruby. Before running the project, double check the .ruby-version file to see the exact version.
  • Node.js - the frontend build requires Node.js. We use Node 18 LTS versions.
  • a running PostgreSQL database

We recommend using a version manager to install and manage these, such as:

Getting started

Installing for the first time

# 1. Clone the git repository and change directory to the new folder
git clone [email protected]:alphagov/forms-admin.git
cd forms-admin

# 2. Run the setup script
./bin/setup

Running the app

You can either run the development task:

# Run the foreman dev server. This will also start the frontend dev task
bin/dev

or run the rails server:

# Run a local Rails server
bin/rails server

# When running the server, you can use any of the frontend tasks, e.g.:
npm run dev

Development tools

Running the tests

The app tests are written with rspec-rails and can be run with:

bundle exec rspec

There are also unit tests for JavaScript code (look for files named *.test.js), written with Jest. These can be run with:

npm run test

Linting

We use RuboCop GOV.UK for linting code, to autocorrect issues run:

bundle exec rubocop -A

We also use the i18n-tasks tool to keep our locales files in a consistent order. When the tests run they will check if the locale files are normalised, and fail if they are not. To fix the locale files automatically you can run:

bundle exec i18n-tasks normalize

On GitHub pull requests we also check our dependencies for security issues using [bundler-audit], you can run this locally with:

bundle audit

Running tasks with rake

We have a Rakefile that is setup to follow the GOV.UK conventions for Rails applications.

To lint your changes and run tests with one command you can run

bundle exec rake

Setting up the database

In order to run this project, your database will need to have a user in it. The bin/setup script will normally take care of this for you, but if you need to quickly add some users you can do so by loading the database seed:

bin/rails db:seed

Changing configuration

Secrets vs Settings

Refer to the the config gem to understand the file based settings loading order.

To override file based via Machine based env variables settings

cat config/settings.yml
file
  based
    settings
      env1: 'foo'
export SETTINGS__FILE__BASED__SETTINGS__ENV1="bar"
puts Settings.file.based.setting.env1
bar

Refer to the settings file for all the settings required to run this app

Environment variables

Name Purpose
DATABASE_URL The URL to the postgres instance (without the database at the end)

Feature flags

This repo supports the ability to set up feature flags. To do this, add your feature flag in the settings file under the features property. eg:

features:
  some_feature: true

You can then use the feature service to check whether the feature is enabled or not. Eg. FeatureService.enabled?(:some_feature).

You can also nest features:

features:
  some:
    nested_feature: true

And check with FeatureService.enabled?("some.nested_feature").

Testing with features

Rspec tests can also be tagged with feature_{name}: true. This will turn that feature on just for the duration of that test.

Configuring GOV.UK Notify

We use GOV.UK Notify to send emails from our apps.

If you want to test the Notify functionality locally, you will need to get a test API key from the Notify service. Add it as an environment variable under SETTINGS__GOVUK_NOTIFY__API_KEY or add it to a local config file:

# config/settings.local.yml

# Settings for GOV.UK Notify api & email templates
govuk_notify:
  api_key: <API key from Notify>

Example emails can be seen locally by visiting http://localhost:3000/rails/mailers

Configuring Sentry

We use Sentry to catch exceptions in production apps and alert us.

We currently have a very basic setup for Sentry in this repo for testing, which we will continue to build upon.

In order to use this locally you will need to sign up to Sentry and create a new project. Then add the Sentry DSN to your environment as SETTINGS__SENTRY__DSN, or add it to a local config file:

# config/settings.local.yml

sentry:
  DSN: <DSN from Sentry>

If you want to deliberately raise an exception to test, uncomment out the triggers in the Sentry initializer script. Whenever you run the app errors will be raised and should also come through on Sentry.

Deployment

The forms-admin app is containerised (see Dockerfile) and can be deployed however you would normally deploy a containerised app.

We host our apps using Amazon Web Services, you can read about how deployments happen on our team wiki, if you have access.

Logging

  • HTTP access logs are managed using Lograge and configured within the application config
  • The output format is JSON using the JsonLogFormatter to enable simpler searching and visbility especially in Splunk.
  • DO NOT use log_tags since it breaks the JSON formatting produced by Lograge.

Updating Docker files

To update the version of Alpine Linux and Ruby used in the Dockerfile, use the update_app_versions.sh script in forms-deploy

Support

Raise a Github issue if you need support.

How to contribute

We welcome contributions - please read CONTRIBUTING.md and the alphagov Code of Conduct before contributing.

License

We use the MIT License.

forms-admin's People

Contributors

0atman avatar alice-carr avatar aliuk2012 avatar c-harry avatar cadmiumcat avatar chao-xian avatar danielburnley avatar danworth avatar davidbiddle avatar deberny avatar dependabot[bot] avatar hannahkc avatar james-sheppard-gov-uk avatar jamie-o-wilkinson avatar lfdebrux avatar rkotyank avatar samjamcul avatar thomasiles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

chao-xian

forms-admin's Issues

Align form builder home screen with the prototype

Trello card: https://trello.com/c/2mA8sYr5/262-create-form-builder-home-screen

Prototype screen: https://forms-prototypes.london.cloudapps.digital/form-designer/form-home

To do:

  • Update form home screen create button to match the prototype
  • Update form list display to match the prototype
    • Note: In Dev we can keep the link to the runner for now as a link underneath the form name or something similar
  • Edit links take you to the form overview screen (depends on #43 )
  • Create request and frontend specs for this

Add friendly Error pages

This should include:
404 for page not found
500 for unexpected errors
Service unavailable (in case we need to take the service down temporarily)

Display questions on form overview screen

  • When I follow a link from the home screen it opens the form overview screen for that form
  • This screen displays the form name, a create question button
  • includes a link to allow user to edit the form name
  • include a link to allow the user to edit each question that's been added

Create page for adding a question to a form

We should be able to add a question page to the form. The page itself could be made ahead of the API work, however the page itself will not be able to be persisted until that work has been completed

  • form builder can add the question text
  • form builder can add the optional short name
  • form builder can optionally add hint text
  • form builder can select the sort of answer it is from list:
    • single line of text
    • address
    • date
    • email address
    • National Insurance number
    • phone number
  • user can save this page
  • saves the question type as appropriate in the saved from structure

Related issues
alphagov/forms-api#25

Localise existing views

We recently added localisation to the repo (#56) and from this point on we will be localising any new views or components we create. However, there are existing views which still have hard-coded English text in them.

We should complete this issue before we start adding support for other languages.

This affects:
forms/

  • edit.html.erb
  • new.html.erb
  • not_found.html.erb
  • show.html.erb

home/

  • index.html.erb

layouts/

  • application.html.erb

Create initial form overview screen

Both #41 and #42 require a form overview screen to link to, we can create a simple one to begin with that contains an edit link to our existing edit page (editing the title/submission email)

As this will be iterated and changed in the future, we don't need to worry about making this too designed and can just be a simple link to the edit details page that exists already

To do

  • Create form overview screen
  • Form overview screen contains link to existing edit screen for "Edit form"

Configure frontend build

This should include anything we're likely to need in both forms-admin and forms-runner, but not anything more specific. We already have a default Rollup build but this may also need a but of configuring.

This should include:

  • babel for transpiling
  • a browserslist configuration (start with a sensible default, we will adjust this later once we have a better idea of our user stats)
  • jest for unit testing
  • cypress for end-to-end testing
  • style and js linting
  • autoprefixer
  • dart-sass instead of ruby-sass
  • install govuk-frontend
  • style and js formatting

Fix asset rendering bug

Currently the govuk-frontend assets (most noticeably the GDS Transport font) aren't being compiled by the asset build. This means that the fonts and assets will load correctly on a local machine, but return 404s on the dev server.

Add CONTRIBUTING.md

We're unlikely to get any contributions from members of the public at this early stage, but it's probably a good idea to have a CONTRIBUTING.md in place early. At a minimum this should include a link to the Code of Conduct.

We may want to adapt one of the existing versions, e.g. the govuk-frontend CONTRIBUTING.md

Add sentry

We want to use sentry for exception tracking, we will need to set up a sentry account and ensure the service can send exceptions correctly

Add Cypress tests to CI pipeline

We should run the Cypress tests on every PR to to catch any issues early. Ideally we should add this to our existing CI workflow.

Align create form journey with with prototype

Tasks

  • Use a Start button for the create a form button on the homepage, instead of a normal button
  • Make the label for the respective form name and email pages use h1 elements
  • Separate the email address question from the form name question, and don't include it in the create a form journey
  • Make the form name and email pages 2/3 width
  • Set the submission email to an empty string when the form is created

Trello cards:

https://trello.com/c/DzXscuZj/426-landing-page-forms-as-a-start-button
https://trello.com/c/0PVwvL3k/427-create-a-form-journey-update

Add CODEOWNERS file

From the GDS Way:

Consider protecting the .github/workflows folder by using a CODEOWNERS file and requiring review from CODEOWNERS for merges into protected branches.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.