Skip to content

Commit

Permalink
feat: update core for next.js migration (#4)
Browse files Browse the repository at this point in the history
* update jwt tokens for next auth

* update user statistics schema for heatmap

* update resources app

* fix return code for delete endpoints

* return all loa requests in admin

* add query param to audit log

* separate event positions by level

* remove default profile generation

* add requested fields to support request

* store event scores in database

* add staff flag to statistics endpoint

* ruff linting + formatting

* updated event editing responses

* enable console emails for development

* update return code for presets

* gcap endorsements

* feat: quarterly controlling hours

* feat: sync visiting roster

* fix: wrong function call

* ruff fmt

* update to django 5.0

* updated statistics aggregation

* scheduled session count

* replace all emails with vatusa links

* changes for new loa management pages

* remove obsolete envs

* remove old workflow

* ruff workflow

* set up postgresql config

* fix lint errors

* went through fixing small things i found

* more fixes

* fix signal registration
  • Loading branch information
MikeRomaa authored Mar 8, 2024
1 parent 461e53b commit 9e066fa
Show file tree
Hide file tree
Showing 140 changed files with 2,066 additions and 1,433 deletions.
47 changes: 25 additions & 22 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
DEV_ENV =
ALLOWED_HOSTS =
SECRET_KEY =
SENTRY_DSN =
DEV_ENV=
ALLOWED_HOSTS=
SECRET_KEY=
SENTRY_DSN=

STATIC_ROOT =
MEDIA_ROOT =
STATIC_ROOT=
MEDIA_ROOT=

VATSIM_CONNECT_CLIENT_ID =
VATSIM_CONNECT_CLIENT_SECRET =
VATSIM_CONNECT_REDIRECT_URI =
DB_HOST=
DB_PORT=
DB_NAME=
DB_USER=
DB_PASSWORD=

VATUSA_API_TOKEN =
AVWX_API_TOKEN =
EMAIL_HOST=
EMAIL_PORT=
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
EMAIL_USE_TLS=
EMAIL_ADDRESS=

FACILITY_NAME =
FACILITY_IATA =
MAVP_FACILTIY_IATA =
POSITION_PREFIXES =
VATSIM_CONNECT_CLIENT_ID=
VATSIM_CONNECT_CLIENT_SECRET=
VATSIM_CONNECT_REDIRECT_URI=

EMAIL_HOST =
EMAIL_PORT =
EMAIL_HOST_USER =
EMAIL_HOST_PASSWORD =
EMAIL_USE_TLS =
EMAIL_ADDRESS =
VATUSA_API_TOKEN=
AVWX_API_TOKEN=

EVENTS_WEBHOOK_URL =
POSITION_PREFIXES=

EVENTS_WEBHOOK_URL=
27 changes: 0 additions & 27 deletions .github/workflows/deploy-prod.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Ruff
on:
push:
branches:
- main
pull_request:
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
9 changes: 6 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/ruff.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/runConfigurations/Start.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 28 additions & 28 deletions .idea/zhu-core.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.10-alpine

WORKDIR /app

COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt
14 changes: 10 additions & 4 deletions apps/administration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from auditlog.models import LogEntry
from django.core.exceptions import FieldDoesNotExist
from rest_framework import serializers

from ..users.serializers import BasicUserSerializer
from apps.users.serializers import BasicUserSerializer


class LogEntrySerializer(serializers.ModelSerializer):
Expand All @@ -11,7 +12,7 @@ class LogEntrySerializer(serializers.ModelSerializer):

class Meta:
model = LogEntry
fields = ['id', 'action', 'actor', 'changes', 'content_type', 'object_id', 'object_repr', 'timestamp']
fields = ["id", "action", "actor", "changes", "content_type", "object_id", "object_repr", "timestamp"]

def get_changes(self, obj):
"""
Expand All @@ -23,8 +24,13 @@ def get_changes(self, obj):
model = obj.content_type.model_class()

for field in changes:
field_class = model._meta.get_field(field)
if getattr(field_class, 'choices', None):
try:
field_class = model._meta.get_field(field)
except FieldDoesNotExist:
# This can happen if a field gets deleted. We'll just ignore it.
continue

if getattr(field_class, "choices", None):
choices = {str(key): value for key, value in field_class.choices}
for i in range(2):
changes[field][i] = choices.get(changes.get(field)[i])
Expand Down
4 changes: 2 additions & 2 deletions apps/administration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from . import views

urlpatterns = [
path('notifications/', views.NotificationView.as_view()),
path('audit/', views.AuditLogView.as_view()),
path("notifications/", views.NotificationView.as_view()),
path("audit/", views.AuditLogView.as_view()),
]
43 changes: 32 additions & 11 deletions apps/administration/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from datetime import date

from auditlog.models import LogEntry
from django.db.models import Case, CharField, Q, Value, When
from django.db.models.functions import Concat
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.events.models import SupportRequest
from apps.feedback.models import Feedback
from apps.loa.models import LOA
from apps.visit.models import VisitingApplication
from zhu_core.permissions import IsStaff

from .serializers import LogEntrySerializer
from ..events.models import SupportRequest
from ..feedback.models import Feedback
from ..loa.models import LOA
from ..visit.models import VisitingApplication


class NotificationView(APIView):
Expand All @@ -20,16 +24,18 @@ def get(self, request):
"""
Returns notification counts for admin panel categories.
"""
return Response({
'visiting_applications': VisitingApplication.objects.count(),
'pending_feedback': Feedback.objects.filter(approved=False).count(),
'support_requests': SupportRequest.objects.count(),
'loa_requests': LOA.objects.filter(end__gt=date.today(), approved=False).count(),
})
return Response(
{
"visiting_applications": VisitingApplication.objects.count(),
"pending_feedback": Feedback.objects.filter(approved=False).count(),
"support_requests": SupportRequest.objects.count(),
"loa_requests": LOA.objects.filter(approved=False, end__gte=date.today()).count(),
}
)


class AuditLogPagination(PageNumberPagination):
page_size_query_param = 'page_size'
page_size_query_param = "page_size"
page_size = 100


Expand All @@ -39,4 +45,19 @@ class AuditLogView(ListAPIView):
serializer_class = LogEntrySerializer

def get_queryset(self):
if query := self.request.GET.get("query"):
return LogEntry.objects.annotate(
user=Case(
When(
actor__isnull=False,
then=Concat(
"actor__first_name",
"actor__last_name",
"actor__cid",
output_field=CharField(),
),
),
default=Value("System"),
)
).filter(Q(object_repr__icontains=query) | Q(changes__icontains=query) | Q(user__icontains=query))
return LogEntry.objects.all()
2 changes: 1 addition & 1 deletion apps/announcements/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

@admin.register(Announcement)
class AnnouncementAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'posted')
list_display = ("title", "author", "posted")
6 changes: 3 additions & 3 deletions apps/announcements/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from auditlog.registry import auditlog
from django.db import models

from ..users.models import User
from apps.users.models import User


class Announcement(models.Model):
class Meta:
verbose_name = 'Announcement'
verbose_name = "Announcement"

title = models.CharField(max_length=128)
body = models.TextField()
author = models.ForeignKey(User, models.SET_NULL, null=True, blank=True, related_name='announcements')
author = models.ForeignKey(User, models.SET_NULL, null=True, blank=True, related_name="announcements")
posted = models.DateTimeField(auto_now_add=True)

def __str__(self):
Expand Down
12 changes: 5 additions & 7 deletions apps/announcements/serializers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from rest_framework import serializers

from apps.users.models import User
from apps.users.serializers import BasicUserSerializer

from .models import Announcement
from ..users.models import User
from ..users.serializers import BasicUserSerializer


class BaseAnnouncementSerializer(serializers.ModelSerializer):
author = serializers.PrimaryKeyRelatedField(
queryset=User.objects.all(),
default=serializers.CurrentUserDefault()
)
author = serializers.PrimaryKeyRelatedField(queryset=User.objects.all(), default=serializers.CurrentUserDefault())

class Meta:
model = Announcement
fields = '__all__'
fields = "__all__"


class AnnouncementSerializer(BaseAnnouncementSerializer):
Expand Down
6 changes: 3 additions & 3 deletions apps/announcements/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import views

urlpatterns = [
path('', views.AnnouncementListView.as_view()),
path('<int:announcement_id>/', views.AnnouncementInstanceView.as_view()),
path('recent/', views.RecentAnnouncementListView.as_view()),
path("", views.AnnouncementListView.as_view()),
path("<int:announcement_id>/", views.AnnouncementInstanceView.as_view()),
path("recent/", views.RecentAnnouncementListView.as_view()),
]
Loading

0 comments on commit 9e066fa

Please sign in to comment.