-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* created endpoint for listing and destroying orders * Infrastructure as Code using terraform (#684) * feat: initial terraform * chore: add basic documentation * chore: more documentation * Added IaC setup for Lepton * added checov github action * chekov allow softfail * chore: database name * hack to allow azure container apps managed certificates * small changes * tweeking values * chore: revert changes to makefile * chore: make format * chore: bump build actions (#755) * Feat(payment)/orders (#757) * added filtersearch * added filter * added filter and listing * Add status field to the ordering filter and fix retrieve method in OrderViewSet * Refactor order filters and views * Add is_index_user function to check if user is in Index * Refactor order factory and serializers, add update endpoint for orders * Add admin group user permission to order views and tests * added permission checks for order model and removed from order viewset (#760) * added permission checks for order model and removed from order viewset * format * fixed string representation for orders (#764) * removed bug that deleted paid event if event is updated. added more i… (#765) * removed bug that deleted paid event if event is updated. added more info to paid_event in adminpanel * format * Update CHANGELOG.md (#766) * Feat(kontres)/initial setup (#720) * Initial setup * Update settings.py * created draft for reservation class and state enum * config for kontres * created endpoint for creating new reservation * created serializer for create_reservation * added create_reservation to url path * added admin.py to implement admin panel logic * added __Str__ for admin panel * added seperate class for a bookable item * made "Kontoret" default value of a reservation for now and added migration * removed unnecessary code * added endpoint to edit a reservation, lacking request validation * added endpoint to fetch all reservations * updated urls.py with the newest endpoints * code cleanup * created model test for reservation class * added bookable item object to reservation serializer * created test for creating reservations * added clean and self to reservation class * added bookable item serializer * added som error handling to fetch_all_reservations.py * created endpoint to fetch reseervation by id * modifies urls.py to accomodate changes in endpoints regarding queries and arguments * removed the default value for bookable item in reservation * every new reservation will now automatically be pending * fetch_reservation.py now uses url argument instead of query parameter * fixed bug in reservation_seralizer.py regarding bookableitem id * fixed and added more tests in test_create_reservation.py * created pytests for editing a reservation * created pytests for fetching all reservations * created pytests for fetching a reservation by 1 * made toString method in reservation model cleaner * combined files to make one common reservation endpoint * adjusted tests to accommodate to endpoint url * transitioned to uuid for reservation and bookable item class * fixed tests to accommodate uuid * created endpoint to fetch all bookable items * modified urls.py to accommodate uuid and new endpoint * removed old and seperate endpoint files * added uuid to admin panel * added error handling in reservation view * initial commit * all new reservations will be pending * added test for bookable items * deleted old endpoint and url model * fixed code for pr * fixed kontres conventions * formatting * added queryset to reservation model * fixed imports * rename * re-migrated * formatting * moved tests to correct place, and refactored to use factories and conftest.py * added reservation and bookable item factories to conftest.py * created factories * fixed migration issues * fixed packaging location * removed comments * added read and write access specifications to reservation and bookable item model * added endpoint guards * fixed tests * formatting * fixed tests * refactored permission system * refactored reservation model with correct permission system * fixed viewset to accomodate new permission system * removed unnecessary test * fixed old tests to accomodate new permission system, as well as added new ones * added extensive validation logic to prevent overlapping reservations etc * formatting for pr * removed relative import * linting * removed necessary code * rewrote reservation queryset * made reservation factory use enums for state * removed necessary state validation * fixed tests * formatting * linting * Added new field to reservation model * Trigger Build * Trigger Build * format and closed INSTALLED_APPS list * closed urls list * fixed description model bug as result of git issues * added class methods to bookable_item model * reformated permission logic * removed uneccessary code * translated error messages to norwegian * reformated tests to fit new viewset and permission logic * linting * changed from write to update permission and added status code on reponse on update view * creating a reservation will now use userId from request, and ignore any other attempt * users are now unable to modify reservation after it has been confirmed. also fixed permission logic in update method * added tests to make sure users cannot change their reservation after is has been confirmed * linting --------- Co-authored-by: Frikk Balder <[email protected]> Co-authored-by: ConradOsvik <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Mads Nylund <[email protected]> * LogEntry viewset and fix (#768) added viewset and serializer for logentry. Also remove date_hierachy in admin register for LogEntry * Feat(kontres)/add group to create reservation (#769) * fixed delete object permission * added group field to reservation model * added context to serializer * added group validation logic to serializer * created tests for group logic on reservation model * fixed seralizer complexity by splitting into methods * fixed time issue on tests * linting * fixed bug where bookable item was not properly inserted as payload in 2 tests * removed unnecessary assertion against database * fixed destroy logic in viewset and model * Feat(kontres)/return full objects in response (#770) * reservation response will now include the full objects for author, bookable_item and group * reservation response will now include the full objects for author, bookable_item and group * git aids * fixed some more git aids * fixed logic in serializer method for validating time (#771) * fixed logic in serializer method for validating time * skip unfinished test - waiting for updated viewset logic * Update pull_request_template.md (#774) * Fix(event)/fix priority waiting number (#775) * fix(kontres)/added basic viewset to bookable item (#773) * Removed SQL logging settings (#776) removed logging settings * fixed bug of payment countdown for registrations from waitlist to queue (#778) * Update CHANGELOG.md (#779) * Feat(kontres)/add endpoint for my reservations (#777) * added endpoint to fetch /me/reservations * added tests for /me/reservations endpoint * removed logging statement * admin can now fetch all reservations by user * created tests for admin fetching reservations by user --------- Co-authored-by: Martin Clementz <[email protected]> Co-authored-by: Erik Skjellevik <[email protected]> Co-authored-by: Frikk Balder <[email protected]> Co-authored-by: ConradOsvik <[email protected]>
- Loading branch information
1 parent
ec473c2
commit 8347ca8
Showing
44 changed files
with
2,136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib.admin.models import LogEntry | ||
from django.utils import timezone | ||
|
||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from app.content.factories.user_factory import UserFactory | ||
|
||
|
||
class LogEntryFactory(DjangoModelFactory): | ||
class Meta: | ||
model = LogEntry | ||
|
||
action_time = timezone.now() | ||
user = factory.SubFactory(UserFactory) | ||
content_type = None | ||
object_id = 1 | ||
object_repr = "Test" | ||
action_flag = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from rest_framework import serializers | ||
|
||
from app.common.serializers import BaseModelSerializer | ||
|
||
|
||
class ContentTypeSerializer(BaseModelSerializer): | ||
app_label_name = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = ContentType | ||
fields = ("app_label_name",) | ||
|
||
def get_app_label_name(self, obj): | ||
return obj.app_labeled_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.contrib.admin.models import LogEntry | ||
from rest_framework import serializers | ||
|
||
from app.common.serializers import BaseModelSerializer | ||
from app.content.serializers.content_type import ContentTypeSerializer | ||
from app.content.serializers.user import SimpleUserSerializer | ||
|
||
|
||
class LogEntryListSerializer(BaseModelSerializer): | ||
user = SimpleUserSerializer(many=False) | ||
content_type = ContentTypeSerializer(many=False) | ||
action_flag = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = LogEntry | ||
fields = ( | ||
"action_time", | ||
"user", | ||
"content_type", | ||
"object_id", | ||
"object_repr", | ||
"action_flag", | ||
) | ||
|
||
def get_action_flag(self, obj): | ||
if obj.is_addition(): | ||
return "ADDITION" | ||
if obj.is_change(): | ||
return "CHANGE" | ||
if obj.is_deletion(): | ||
return "DELETION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.contrib.admin.models import LogEntry | ||
from rest_framework.response import Response | ||
|
||
from app.common.mixins import ActionMixin | ||
from app.common.pagination import BasePagination | ||
from app.common.permissions import AdminGroup, check_has_access | ||
from app.common.viewsets import BaseViewSet | ||
from app.content.serializers.logentry import LogEntryListSerializer | ||
|
||
|
||
class LogEntryViewSet(BaseViewSet, ActionMixin): | ||
serializer_class = LogEntryListSerializer | ||
pagination_class = BasePagination | ||
queryset = LogEntry.objects.all() | ||
|
||
def list(self, request, *args, **kwargs): | ||
if check_has_access(AdminGroup.admin(), request): | ||
return super().list(request, *args, **kwargs) | ||
|
||
return Response({"detail": "Du har ikke tilgang til å se loggen."}, status=403) | ||
|
||
def retrieve(self, request, *args, **kwargs): | ||
if check_has_access(AdminGroup.admin(), request): | ||
return super().retrieve(request, *args, **kwargs) | ||
|
||
return Response({"detail": "Du har ikke tilgang til å se loggen."}, status=403) | ||
|
||
def create(self, request, *args, **kwargs): | ||
return Response({"detail": "Du har ikke tilgang til å logge."}, status=403) | ||
|
||
def update(self, request, *args, **kwargs): | ||
return Response( | ||
{"detail": "Du har ikke tilgang til å oppdatere loggen."}, status=403 | ||
) | ||
|
||
def destroy(self, request, *args, **kwargs): | ||
return Response( | ||
{"detail": "Du har ikke tilgang til å slette loggen."}, status=403 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
|
||
from app.kontres.models.bookable_item import BookableItem | ||
from app.kontres.models.reservation import Reservation | ||
|
||
|
||
class ReservationAdmin(admin.ModelAdmin): | ||
readonly_fields = ("id",) | ||
|
||
|
||
class BookableItemAdmin(admin.ModelAdmin): | ||
readonly_fields = ("id",) | ||
|
||
|
||
admin.site.register(Reservation, ReservationAdmin) | ||
admin.site.register(BookableItem, BookableItemAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class KontResConfig(AppConfig): | ||
name = "app.kontres" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.db import models | ||
|
||
|
||
class ReservationStateEnum(models.TextChoices): | ||
PENDING = "PENDING" | ||
CONFIRMED = "CONFIRMED" | ||
CANCELLED = "CANCELLED" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from app.kontres.factories.bookable_item_factory import BookableItemFactory | ||
from app.kontres.factories.reservation_factory import ReservationFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from factory import Faker, Sequence | ||
from factory.django import DjangoModelFactory | ||
|
||
from app.kontres.models.bookable_item import BookableItem | ||
|
||
|
||
class BookableItemFactory(DjangoModelFactory): | ||
class Meta: | ||
model = BookableItem | ||
|
||
name = Sequence(lambda n: f"Item_{n}") | ||
description = Faker("text") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.utils import timezone | ||
|
||
from factory import Faker, SubFactory | ||
from factory.django import DjangoModelFactory | ||
|
||
from app.content.factories import UserFactory | ||
from app.kontres.enums import ReservationStateEnum | ||
from app.kontres.factories.bookable_item_factory import BookableItemFactory | ||
from app.kontres.models.reservation import Reservation | ||
|
||
|
||
class ReservationFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Reservation | ||
|
||
author = SubFactory(UserFactory) | ||
bookable_item = SubFactory(BookableItemFactory) | ||
start_time = timezone.now() + timezone.timedelta(hours=1) | ||
end_time = timezone.now() + timezone.timedelta(hours=2) | ||
state = ReservationStateEnum.PENDING | ||
description = Faker("text") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 4.0.8 on 2023-10-25 13:10 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BookableItem', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=20)), | ||
('description', models.TextField(blank=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Reservation', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('start_time', models.DateTimeField()), | ||
('end_time', models.DateTimeField()), | ||
('state', models.CharField(choices=[('PENDING', 'Pending'), ('CONFIRMED', 'Confirmed'), ('CANCELLED', 'Cancelled')], default='PENDING', max_length=15)), | ||
('description', models.TextField(blank=True)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reservations', to=settings.AUTH_USER_MODEL)), | ||
('bookable_item', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='reservations', to='kontres.bookableitem')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Oops, something went wrong.