Skip to content

Commit

Permalink
Merge branch 'develop' into ruff-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Fogapod committed Feb 10, 2024
2 parents 81265c5 + c0ba926 commit ce2b30f
Show file tree
Hide file tree
Showing 37 changed files with 1,567 additions and 316 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
# because pre-commit uses external mypy
- name: install mypy
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install --only main,typecheck
# https://github.com/typeddjango/django-stubs/issues/458
- name: create .env file
run: cp example.env .env
- uses: pre-commit/[email protected]

unit_test:
Expand All @@ -35,7 +44,9 @@ jobs:
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install
poetry install --only main
- name: create .env file
run: cp example.env .env
- name: Run tests
env:
SECRET_KEY: secret
Expand Down
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.2.1
hooks:
- id: ruff-format
- id: ruff
Expand All @@ -23,7 +23,12 @@ repos:
exclude: >-
^.*.md$
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.8.0
# hooks:
# - id: mypy
# local mypy because of stub dependencies
- repo: local
hooks:
- id: typecheck
name: Typecheck
entry: mypy .
types: [python]
language: system
pass_filenames: false
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENV PYTHONUNBUFFERED=yes \

WORKDIR /src

COPY poetry.lock pyproject.toml .
COPY poetry.lock pyproject.toml ./

RUN : \
# psycopg runtime dep
Expand All @@ -36,12 +36,15 @@ COPY src .
RUN : \
&& mkdir /home/website \
&& mkdir /home/website/statics \
&& mkdir /home/website/media
&& mkdir /home/website/media \
&& mkdir /home/website/logs

# removes \r from script and makes it executable.
# both of these are caused by windows users touching file and not configuring git properly
RUN : \
&& sed -i 's/\r//g' entrypoint.sh \
&& chmod +x entrypoint.sh

RUN crontab -l | { cat; echo "* * * * * python /src/manage.py send_queued_mail >> /home/website/logs/send_mail.log 2>&1"; } | crontab -

ENTRYPOINT ["./entrypoint.sh"]
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ The all-in-one backend application for [Unitystation](https://github.com/unityst

## Development guide

### Settings file
### Environment setup

Copy `example.env` to `.env` and customize it.
Copy `example.env` to `.env` and customize it. You can then start development by either using docker or running the project locally.

### Setting up python
### Setting up python to run the project locally

You will need python 3.11+

Expand Down Expand Up @@ -60,6 +60,13 @@ Install dev dependencies
poetry install
```

#### Start the server

from the src folder run
```sh
python manage.py runserver
```

#### pre-commit

pre-commit is a git hook which runs every time you make a commit to catch linting and formatting errors early.
Expand All @@ -78,14 +85,15 @@ Docker (with help of compose) lets you launch entire project including database

2- Launch project by running `docker compose -f dev-compose.yml up --build`.

3- Test out the webui by accessing http://localhost:8000/

### Navigating web UI
### Try it out

Assuming you've managed to get a page running on http://localhost:8000/, we can now start doing things such as registering a test account.
After everything is done, you can access the web UI at http://localhost:8000/. Here you will see the automatic documentation for the API and you can test out the API end points.

Some other useful links:
- http://localhost:8000/admin -> View all accounts and edit existing ones.
- http://localhost:8000/accounts/register -> Create an account (if you already don't have one)
- http://localhost:8000/accounts/verify-account -> Test account verfication manually.
- http://localhost:8000/accounts/register -> Create an account.
- http://localhost:8000/accounts/login-credentials -> Test loging in with a username and password.
- http://localhost:8000/accounts/login-token -> Test loging in with a token (see admin page if you lost the token after login with credentials).

To find more api end points or add new ones, check out `urls.py` under the respective folder of what feature you want mess around with.
You can also use [Bruno](https://www.usebruno.com/) (a Postman alternative) to test out the API.
The Bruno project is included in the repository and you can find it in the 'api-collection' folder in the root of the repository.
11 changes: 11 additions & 0 deletions api-collection/Auth/Mail confirmation/ConfirmAccount.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: ConfirmAccount
type: http
seq: 1
}

post {
url: {{baseUrl}}/accounts/confirm-account/<token you get via email here>
body: none
auth: none
}
17 changes: 17 additions & 0 deletions api-collection/Auth/Mail confirmation/Resend mail confirmation.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: Resend mail confirmation
type: http
seq: 2
}

post {
url: {{baseUrl}}/accounts/resend-account-confirmation
body: json
auth: none
}

body:json {
{
"email": "[email protected]"
}
}
17 changes: 17 additions & 0 deletions api-collection/Auth/ResetPassword/confirm the reset.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: confirm the reset
type: http
seq: 2
}

post {
url: {{baseUrl}}/accounts/reset-password/<token here>
body: json
auth: none
}

body:json {
{
"password": "admin"
}
}
17 changes: 17 additions & 0 deletions api-collection/Auth/ResetPassword/request a reset.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: request a reset
type: http
seq: 1
}

post {
url: {{baseUrl}}/accounts/reset-password/
body: json
auth: none
}

body:json {
{
"email": "[email protected]"
}
}
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ services:
expose:
- 8000
command: gunicorn central_command.wsgi:application --bind 0.0.0.0:8000
volumes:
- static-volume:/home/website/statics
- media-volume:/home/website/media
volumes:
- static-volume:/home/website/statics
- media-volume:/home/website/media

volumes:
db-data:
Expand Down
5 changes: 5 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ DB_ENGINE=django.db.backends.postgresql
DB_NAME=postgres
DB_HOST=db
DB_PORT=5432

# Links to stuff
WEBSITE_URL = http://localhost:8000
PASS_RESET_URL_SUFFIX = reset-password/
ACCOUNT_CONFIRMATION_URL_SUFFIX = confirm-email/
Loading

0 comments on commit ce2b30f

Please sign in to comment.