Skip to content

Commit

Permalink
Merge pull request #47 from co-cddo/add-admin-interfaces
Browse files Browse the repository at this point in the history
Add admin interfaces
  • Loading branch information
jimnarey authored Mar 10, 2024
2 parents 1241b90 + 12ed882 commit edc2f55
Show file tree
Hide file tree
Showing 13 changed files with 472 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ repos:
rev: v1.4.0
hooks:
- id: detect-secrets
exclude: (^\.github/workflows/)|package\.lock\.json|(^tests/fixtures/)|request_a_govuk_domain/static
exclude: (^\.github/workflows/)|package\.lock\.json|(^tests/fixtures/)|request_a_govuk_domain/static|seed/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ makemigrations:

migrate-devserver:
docker exec -it domains-register-a-govuk-domain-web-1 ./manage.py migrate

clear-db:
docker compose down && docker container prune -f && docker volume rm domains-register-a-govuk-domain_postgres-data
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,73 @@ make collectstatic; make up

The command `make collectstatic` is to collect the static files and `make up` is to run the application on docker.

`make collectstatic` is a one-time command to collect the static files. It is not required to run this command every
time, unless there are changes in the static files.
`make collectstatic` is a one-time command to collect the static files. It is not required to run this command every time, unless there are changes in the static files.

So after the first time, the command to run the application on local docker is:
```bash
make up
```

Alternatively, you can use `make up-devserver` to use the Django development server in place of gunicorn.

When the application is run, any migrations are applied to the database. Seed data for the `reviewer` user group (see below) is also applied.

When running the application for the first time, or after deleting the docker volume containing the database, it's typical for docker to throw the following error:

```
service "init" didn't completed successfully: exit 1
make: *** [Makefile:5: up-devserver] Error 1
```

Just run either `make up` or `make up-devserver` again.

## Usage instructions

The application will be accessible via http://localhost:8000/name
The user-facing application is accessible via http://localhost:8000

Note: The application is in initial stages and the forms are at prototype/R&D stage. The pages on the application and logic within them are not yet representative of application.

Note: The application is in initial stages and the forms are at prototype/R&D stage. The pages on the application and
logic within them are not yet representative of application.
The team can view and assess registration applications via the Django admin site. Each time the app is started, it will create a superuser and a 'reviewer' (staff) user if these do not already exist. The credentials are:

- admin, ilovedomains
- reviewer, ilovedomains

## Development instructions

This project uses Poetry for dependency management and packaging. To install Poetry, follow the instructions at
https://python-poetry.org/
This project uses Poetry for dependency management and packaging. To install Poetry, follow the instructions at https://python-poetry.org/

To install dependencies for local development ( e.g. when using IDE to make changes ) , use `poetry install`.


This repository is set up with [pre-commit](https://pre-commit.com/) for style and error checking before every commit.
You should install pre-commit, then run `pre-commit install` from within the project directory.

### Updating fixtures

Seed data is included for users, a single user group ('reviewer') and enough records to populate a single registration application.

If the models are changed it will be necessary to update the seed data. New seed data can be produced with:

```
python manage.py dumpdata request --indent 2
```

If the models change to the extent that the permissions for staff/reviewer users have to be changed (e.g. to provide visibility of a new model in the admin site) the it will be necessary to update the seed data. Log into the admin site as a superuser and change the permissions for the `reviewer` group as required.

Then copy and paste the output of the following command into the `reviewer_group.json` file, replacing the existing content:

```
python manage.py dumpdata auth.group --indent 2
```

If additional groups are added or other fundamental changes made which mean the default superuser/reviewer user records are changed, then paste the output of the following command into the `users.json` file, again replacing the existing content:

```
python manage.py dumpdata auth.user --indent 2
```

### Clearing the database

While we're in the early stages of development it makes sense to delete existing migrations and create them afresh. To enable this, use the `make clear-db` command. Seed data will be re-applied when the application is restarted.

## Make commands

Expand All @@ -62,10 +103,18 @@ Following are some of the make commands:

`make collectstatic` - Collect the static files

`make makemigrations` - Create migrations which will be applied on each application start

`make up` - Run the application on docker

`make up-devserver` - Run the application on docker using the Django development server

`make shell` - Open a bash console within the running application container (you'll get an error if the service isn't running)

`make down` - Stop the application on docker

`make clear-db` - Delete the database volume


## End-to-end testing

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
restart: 'no'
environment:
<<: *common-application-variables
command: [ "sh", "-c", "python manage.py migrate --noinput" ]
command: [ "sh", "-c", "python manage.py migrate --noinput && python manage.py loaddata ./seed/reviewer_group.json ./seed/users.json ./seed/request.json" ]
depends_on:
- postgres

Expand Down
48 changes: 46 additions & 2 deletions request_a_govuk_domain/request/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# from django.contrib import admin
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.admin import GroupAdmin
from django.contrib.auth.models import User
from django.contrib.auth.models import Group

# Register your models here.
from .models import Application, CentralGovernmentAttributes, Review


class DomainRegistrationUserAdmin(UserAdmin):
def has_module_permission(self, request):
if request.user.is_superuser:
return True
return False


class DomainRegistrationGroupAdmin(GroupAdmin):
def has_module_permission(self, request):
if request.user.is_superuser:
return True
return False


class CentralGovernmentAttributesInline(admin.StackedInline):
model = CentralGovernmentAttributes
can_delete = False
verbose_name_plural = "Central Government Attributes"


class ReviewInline(admin.StackedInline):
model = Review
can_delete = False
verbose_name_plural = "Reviews"


class ApplicationAdmin(admin.ModelAdmin):
model = Application
inlines = [CentralGovernmentAttributesInline, ReviewInline]


admin.site.unregister(User)
admin.site.register(User, DomainRegistrationUserAdmin)

admin.site.unregister(Group)
admin.site.register(Group, DomainRegistrationGroupAdmin)

admin.site.register(Application, ApplicationAdmin)
Loading

0 comments on commit edc2f55

Please sign in to comment.