Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply redesign #7

Merged
merged 14 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VW_DEBUG=False
VW_SECRET_KEY=django-insecure-dev-key
VW_ALLOWED_HOSTS=localhost,127.0.0.1,::1
VW_DB=sqlite://./db.sqlite
VW_OPENID_CLIENT_ID=dev-client
VW_OPENID_CLIENT_SECRET=public-secret
VW_OPENID_SCOPE=openid profile
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM docker.io/tiangolo/uvicorn-gunicorn:python3.10-slim
# add system dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update &&\
apt-get install -y --no-install-recommends git &&\
apt-get install -y --no-install-recommends git nodejs npm &&\
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip3 install --no-cache pipenv psycopg2-binary
WORKDIR /app
Expand All @@ -18,7 +18,7 @@ COPY docker/prestart.sh /app/
RUN ln -sf /app/vinywaji/asgi.py /app/main.py

# setup recommended container config
RUN mkdir /app/data
RUN mkdir -p /app/data
ENV VW_DATABASE_URL=sqlite:///app/data/db.sqlite

# add additional metadata
Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ environs = { version = "~=9.5", extras = ["django"] }
opentelemetry-api = "~=1.22.0"
opentelemetry-sdk = "~=1.22.0"
opentelemetry-exporter-prometheus = "*"
django-tailwind = "*"
django-templates-macros = "*"

[dev-packages]
pre-commit = "*"
Expand All @@ -22,6 +24,7 @@ black = "*"
ipython = "*"
pytest = "*"
pytest-django = "*"
django-browser-reload = "*"

[requires]
python_version = "3"
680 changes: 351 additions & 329 deletions Pipfile.lock

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,32 @@ To start it:
pipenv shell
./src/manage.py check --deploy
./src/manage.py migrate
./src/manage.py tailwind build
./src/manage.py runserver
```

## Development

While development, you need to run `./src/manage.py tailwind start` to update the tailwind styles automatically.

## Configuration

The application is configured at runtime via the following environment variables:

| Name | Default | Description | Notes |
|-------------------------|------------------------|-------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| VW_DB | *required* | Url that specifies the complete database connection. [Documentation](https://pypi.org/project/dj-database-url/) | In container based deployments this preconfigured to point to `/app/data/db.sqlite` |
| VW_SECRET_KEY | *required* | Django secret key. **Keep this secret!** | |
| VW_ALLOWED_HOSTS | *required* | List of hostnames which may be used when accessing the application. | |
| VW_SERVED_OVER_HTTPS | `false` | Whether the application is served over HTTPS. If enabled, automatic redirects and additional security measures are activated. | |
| VW_HSTS_SECONDS | `63072000` | If larger than 0 and `BL_SERVED_OVER_HTTPS` is true, HSTS is enabled with this configured value. | |
| VW_TRUST_REVERSE_PROXY | `false` | If true, headers set by a reverse proxy (i.e. `X-Forwarded-Proto`) are trusted. | |
| VW_OPENID_PROVIDER_NAME | `Mafiasi` | A human readable name identifying the authentication provider. | |
| VW_OPENID_ISSUER | *mafiasi-identity* | The url of the openid issue | |
| VW_OPENID_CLIENT_ID | *required* | Mafiasi-Identity client ID. Used for authentication | |
| VW_OPENID_CLIENT_SECRET | *required* | Mafiasi-Identity client secret. Used for authentication | |
| VW_ALLOWED_METRICS_NETS | `127.0.0.0/8`, `::/64` | List of IP networks which are allowed to access the /metrics endpoint | |
| VW_ORG_NAME | `Bit-Bots Drinks` | Application Title related to the organisation that hosts it | |
| VW_DEFAULT_AMOUNT | `1.5` | A float describing how much a drink costs per default | |
| VW_MAFIASI_COLORS | `false` | Whether a color scheme specific to Mafiasi should be used | |
| Name | Default | Description | Notes |
|-------------------------|------------------------|-------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| VW_DEBUG | `false` | Whether Debug Mode should be enabled. | When `true`, dependencies have to be installed with `pipenv install -d --ignore-pipfile` |
| VW_DB | *required* | Url that specifies the complete database connection. [Documentation](https://pypi.org/project/dj-database-url/) | In container based deployments this preconfigured to point to `/app/data/db.sqlite` |
| VW_SECRET_KEY | *required* | Django secret key. **Keep this secret!** | |
| VW_ALLOWED_HOSTS | *required* | List of hostnames which may be used when accessing the application. | |
| VW_SERVED_OVER_HTTPS | `false` | Whether the application is served over HTTPS. If enabled, automatic redirects and additional security measures are activated. | |
| VW_HSTS_SECONDS | `63072000` | If larger than 0 and `BL_SERVED_OVER_HTTPS` is true, HSTS is enabled with this configured value. | |
| VW_TRUST_REVERSE_PROXY | `false` | If true, headers set by a reverse proxy (i.e. `X-Forwarded-Proto`) are trusted. | |
| VW_OPENID_PROVIDER_NAME | `Mafiasi` | A human readable name identifying the authentication provider. | |
| VW_OPENID_ISSUER | *mafiasi-identity* | The url of the openid issue | |
| VW_OPENID_CLIENT_ID | *required* | Mafiasi-Identity client ID. Used for authentication | |
| VW_OPENID_CLIENT_SECRET | *required* | Mafiasi-Identity client secret. Used for authentication | |
| VW_ALLOWED_METRICS_NETS | `127.0.0.0/8`, `::/64` | List of IP networks which are allowed to access the /metrics endpoint | |
| VW_ORG_NAME | `Bit-Bots Drinks` | Application Title related to the organisation that hosts it | |
| VW_DEFAULT_AMOUNT | `1.5` | A float describing how much a drink costs per default | |
| VW_MAFIASI_COLORS | `false` | Whether a color scheme specific to Mafiasi should be used | |
1 change: 1 addition & 0 deletions docker/prestart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ set -e
./manage.py check --deploy
./manage.py collectstatic --no-input
./manage.py migrate
./manage.py tailwind build
2 changes: 0 additions & 2 deletions src/vinywaji/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def me(self, request):
]
)
)


class TransactionViewSet(
viewsets.mixins.CreateModelMixin,
viewsets.mixins.RetrieveModelMixin,
Expand Down
12 changes: 3 additions & 9 deletions src/vinywaji/core/management/commands/load_old_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def handle(self, *args, **options):

# re-add users
for user_data in (
i
for i in fixture_json
if i["model"] == "django_auth_mafiasi.mafiasiauthmodeluser"
i for i in fixture_json if i["model"] == "django_auth_mafiasi.mafiasiauthmodeluser"
):
logger.info(
"adding user %s with openid sub %s",
Expand All @@ -43,12 +41,8 @@ def handle(self, *args, **options):
)

# re-add transactions
for transact_data in (
i for i in fixture_json if i["model"] == "vinywaji_core.transaction"
):
user = openid_models.OpenidUser.objects.get(
sub=transact_data["fields"]["user"]
).user
for transact_data in (i for i in fixture_json if i["model"] == "vinywaji_core.transaction"):
user = openid_models.OpenidUser.objects.get(sub=transact_data["fields"]["user"]).user
parsed_datetime = timezone.datetime.strptime(
transact_data["fields"]["time"], "%Y-%m-%dT%H:%M:%S.%fZ"
)
Expand Down
32 changes: 8 additions & 24 deletions src/vinywaji/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class Migration(migrations.Migration):
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
models.DateTimeField(blank=True, null=True, verbose_name="last login"),
),
(
"is_superuser",
Expand All @@ -48,35 +46,25 @@ class Migration(migrations.Migration):
(
"username",
models.CharField(
error_messages={
"unique": "A user with that username already exists."
},
error_messages={"unique": "A user with that username already exists."},
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
max_length=150,
unique=True,
validators=[
django.contrib.auth.validators.UnicodeUsernameValidator()
],
validators=[django.contrib.auth.validators.UnicodeUsernameValidator()],
verbose_name="username",
),
),
(
"first_name",
models.CharField(
blank=True, max_length=150, verbose_name="first name"
),
models.CharField(blank=True, max_length=150, verbose_name="first name"),
),
(
"last_name",
models.CharField(
blank=True, max_length=150, verbose_name="last name"
),
models.CharField(blank=True, max_length=150, verbose_name="last name"),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
models.EmailField(blank=True, max_length=254, verbose_name="email address"),
),
(
"is_staff",
Expand All @@ -96,9 +84,7 @@ class Migration(migrations.Migration):
),
(
"date_joined",
models.DateTimeField(
default=django.utils.timezone.now, verbose_name="date joined"
),
models.DateTimeField(default=django.utils.timezone.now, verbose_name="date joined"),
),
(
"groups",
Expand Down Expand Up @@ -160,9 +146,7 @@ class Migration(migrations.Migration):
),
(
"time",
models.DateTimeField(
auto_now_add=True, help_text="When this transaction occurred"
),
models.DateTimeField(auto_now_add=True, help_text="When this transaction occurred"),
),
(
"user",
Expand Down
3 changes: 2 additions & 1 deletion src/vinywaji/core/migrations/0002_webhookconfig.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 5.0.6 on 2024-07-09 14:52

import django.db.models.deletion
import vinywaji.core.models
from django.conf import settings
from django.db import migrations, models

import vinywaji.core.models


class Migration(migrations.Migration):

Expand Down
20 changes: 6 additions & 14 deletions src/vinywaji/core/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
import secrets
import uuid

from django.contrib.auth.models import AbstractUser
from django.db import models
Expand All @@ -18,16 +18,12 @@ class User(AbstractUser):
@property
def current_balance(self) -> int:
"""How much money the user currently has in their account"""
aggregate = self.transactions.aggregate(
transaction_sum=models.Sum("amount", default=0)
)
aggregate = self.transactions.aggregate(transaction_sum=models.Sum("amount", default=0))
return aggregate["transaction_sum"]


class Transaction(models.Model):
id = models.UUIDField(
primary_key=True, default=uuid_default, help_text="The ID of this transaction"
)
id = models.UUIDField(primary_key=True, default=uuid_default, help_text="The ID of this transaction")
user = models.ForeignKey(
to="User",
on_delete=models.CASCADE,
Expand All @@ -44,9 +40,7 @@ class Transaction(models.Model):
help_text="How much money was involved in this transaction in euro-cent. "
"Negative amounts represent purchases while positive amounts represent deposits."
)
time = models.DateTimeField(
auto_now_add=True, help_text="When this transaction occurred"
)
time = models.DateTimeField(auto_now_add=True, help_text="When this transaction occurred")

def __str__(self):
if self.description != "":
Expand All @@ -62,9 +56,7 @@ class WebhookConfig(models.Model):
This model stores the configuration of what each webhook exactly does.
"""

id = models.UUIDField(
primary_key=True, default=uuid_default, help_text="The ID of this webhook"
)
id = models.UUIDField(primary_key=True, default=uuid_default, help_text="The ID of this webhook")
description = models.CharField(
max_length=128,
help_text="A free-form description which the user can give this webhook",
Expand Down Expand Up @@ -110,4 +102,4 @@ def trigger(self) -> Transaction:
user=self.user,
description=self.transaction_description,
amount=self.amount,
)
)
4 changes: 4 additions & 0 deletions src/vinywaji/gui/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ class GuiConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "vinywaji.gui"
label = "vinywaji_gui"


class ThemeConfig(AppConfig):
name = "vinywaji.gui"
39 changes: 0 additions & 39 deletions src/vinywaji/gui/static/base.css

This file was deleted.

Loading
Loading