Skip to content

Commit

Permalink
Late December Update (#935)
Browse files Browse the repository at this point in the history
* Feat(kontres)/add image to bookable item (#785)

* added optional image to bookable item model

* added update method in serializer to handle new images

* linting

* remove update method for images

* Feat(kontres)/add approved by (#786)

* added approved by field

* endpoint will now set approved by

* serializer will return full user object in approved_by_detail

* created test for approved by

* migration

* remove unnecessary code

* removed write-only field in approved-by context

* Create minutes for Codex (#787)

* init

* format

* Feat(minute)/viewset (#788)

* added richer reponse on post and put

* added to admin panel

* added filter for minute

* Feat(kontres)/add notification (#790)

* created methods for sending notification to admin and user

* endpoint will now send notification if needed

* add migrations for new notification types

* Memberships with fines activated (#791)

init

* Feat(user)/user bio (#758)

* Created model, serializer and view for user-bio

* Created user bio model and made migrations

* Created user bio serializer + viewsets + added new endpoint

* Tested create method + added bio serializer to user serializer

* Format

* Created update method and started testing

* Debugging test failures in user retrieve

* fixed model error

* Created user_bio_factory + started testing put method

* Created fixture for UserBio

* Created custom excpetion for duplicate user bio

* Added permissions and inherited from BaseModel

* Modularized serializer for bio

* Use correct serializers in viewset + added destroy method

* Finished testing bio viewset integration + format

* Changed environent file to .env to avoid pushing up keys

* Fix: Flipped assertion statement in test, since user bio should not be deleted

* skiped buggy test from kontres

* added mark to pytest.skip

* Moved keys to .env file and reverted docker variables

* Skip buggy kontres test

* format

* Added str method to user_bio

* Removed unused imports

* format

* Changed user relation to a OneToOne-field (same affect as ForeignKey(unique=True) + removed check for duplicate bio in serializer

* Migrations + changed assertion status code in duplicate bio test (could try catch in serializer to produce 400 status code)

* format

* format

* Changed limit for description 50 -> 500 + migrations

* Migrate

* added id to serializer

* merged leaf nodes in migrations

* format

---------

Co-authored-by: Ester2109 <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>
Co-authored-by: Tam Le <[email protected]>

* Update CHANGELOG.md

* added filter for allowed photos for user (#794)

added filter for allowed photos

* Upped payment time when coming from waiting list (#796)

* fixed paymenttime saved to db (#798)

* fixed bug (#800)

* Disallow users to unregister when payment is done (#802)

added 400 status code for deleting paid registration

* update changelog

* Added serializer for category in  event (#804)

added serializer for category in  event

* Permission middelware (#806)

* added a check for existing user and id on request

* format

* Permission refactor of QR Codes (#807)

* added permissions to qr code and refactored viewset

* format

* removed unused imports

* Permissions for payment orders (#808)

* added read permissions

* added permissions for payment order and tests

* format

* chore(iac): updated docs and force https (#810)

chore: updated docs and force https

* feat(iac): add terraform guardrails so index don't nuke our infra (#811)

feat: add guardrails so index don't fup

* Automatic registration for new users with Feide (#809)

* started on feide registration endpoint

* made endpoint for creating user with Feide

* added test for parse group

* finished

* format

* removes three years if in digtrans

* changelog update

* Feide env variables Terraform (#814)

added feid env variables

* added delete endpoint for file (#815)

* added delete endpoint for file

* Trigger Build

* changed workflow to checkout v4

* changed from docker-compose to docker compose

* Update CHANGELOG.md

* format

* format

* fixed permission for committee leaders for group forms

* updated csv for forms (#818)

* Permission for group forms and news (#820)

added permission for committees to create news, and all leaders of groups to create group forms

* Update reservation_seralizer.py (#822)

* Update reservation_seralizer.py

* Fixed linting

* Put a band aid on it *smack*

* Removed blank line..

* ????

* Group ownership of Minutes (#847)

* Refactor MinuteFactory to include group field, and added validation for checkin group access

* added validation for POST request

* Changed endpoint response (#846)

* Changed endpoint response

* Fixed test

* Update test_reservation_integration.py

---------

Co-authored-by: Mads Nylund <[email protected]>

* updated changelog.md

* finished events now appear in the correct order (newest first) (#849)

* finished events now appear in the correct order (newest first)

* added description of change in changelog

* fixed formatting

* updated method to use Django ORM instead of using python methods

* Implement Swagger (#858)

* started on removing choiceenums

* refactored cheatsheet and membership

* refacotered strike enum

* refactored Groups enum

* removed AppModel choiceenum

* added swagger

* Swagger GitHub Action (#860)

* added github action for checking if Swagger is up

* new action

* try another

* tried implementing check for container

* added curl to docker image

* added check if swagger is up

* test if swagger does not get status code 200

* added ?format=openai to trigger error

* checking that the request is working

* updated CHANGELOG.md

* Add new app (#862)

* added script for adding new app to Lepton

* added command to Makefile

* Upgrade all dependencies to latest (#857)

* Add endpoint to create new group as admin

Signed-off-by: Tmpecho <[email protected]>

* Upgrade all dependencies to latest

Signed-off-by: Tmpecho <[email protected]>

* remove bad exception handling in serializers/group.py

* fix inheritance ordering in views/group.py

* refactored group integration test, added non_public_groups to enums

* fix linting

* reformat files

* remove unused import in groups/views/group.py

* Upgrade dependency "black"

Signed-off-by: Tmpecho <[email protected]>

* Upgrade dependency "sentry-sdk"

Signed-off-by: Tmpecho <[email protected]>

* Upgrade dependency "azure-storage-blob" and remove outdated comment in requirements.txt

Signed-off-by: Tmpecho <[email protected]>

* Upgrade all non-django dependencies

Signed-off-by: Tmpecho <[email protected]>

* Upgrade dependency "Django"

Signed-off-by: Tmpecho <[email protected]>

* Upgrade dependencies and remove ignored version from docker-compose.yml

Signed-off-by: Tmpecho <[email protected]>

---------

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: 1Cezzo <[email protected]>

* Allow HS members to create a new group (#864)

* Add endpoint to create new group as admin

Signed-off-by: Tmpecho <[email protected]>

* remove bad exception handling in serializers/group.py

* fix inheritance ordering in views/group.py

* refactored group integration test, added non_public_groups to enums

* fix linting

* reformat files

* remove unused import in groups/views/group.py

---------

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: 1Cezzo <[email protected]>

* App Script Fix (#875)

added serializers dir to script

* Event registration payment orders (#876)

* added list of payment orders for registrations

* update CHANGELOG.md

* chore(deps): update python-dotenv requirement from ~=0.21.1 to ~=1.0.1 (#871)

Updates the requirements on [python-dotenv](https://github.com/theskumar/python-dotenv) to permit the latest version.
- [Release notes](https://github.com/theskumar/python-dotenv/releases)
- [Changelog](https://github.com/theskumar/python-dotenv/blob/main/CHANGELOG.md)
- [Commits](theskumar/python-dotenv@v0.21.1...v1.0.1)

---
updated-dependencies:
- dependency-name: python-dotenv
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Chore(deps): Bump sentry-sdk from 1.14.0 to 2.8.0 (#866)

Bumps [sentry-sdk](https://github.com/getsentry/sentry-python) from 1.14.0 to 2.8.0.
- [Release notes](https://github.com/getsentry/sentry-python/releases)
- [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md)
- [Commits](getsentry/sentry-python@1.14.0...2.8.0)

---
updated-dependencies:
- dependency-name: sentry-sdk
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Codex Course (#852)

* added models for course and registration, and viewset for course and tests

* added validation for date checking for courses

* added viewset for registration for codex courses

* removed unused fields from course model

* removed unused imports

* added API error mixins as mother clas

* fixed error mixin

* refactored to event model

* fixed wrong import

* fixed tests

* format

* skipped broken tests, must be refactored

* updated CHANGELOG.md

* format

* fixed filtering of groups and made tests

* fixed list endpoint for cheatsheets

* trigger

* format

* Endpoint for sending email (#883)

* fix formatting

* created tests for send_email endpoint

* Fix code scanning alert no. 45: Information exposure through an exception

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* fixed errors in send_email and in tests

* lint

* added tests for empty lists and for sending mail to multiple users

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* chore(deps): bump black from 24.3.0 to 24.8.0 (#869)

Bumps [black](https://github.com/psf/black) from 24.3.0 to 24.8.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](psf/black@24.3.0...24.8.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* chore(deps): Bump azure-storage-blob from 12.13.1 to 12.23.1 (#885)

Bumps [azure-storage-blob](https://github.com/Azure/azure-sdk-for-python) from 12.13.1 to 12.23.1.
- [Release notes](https://github.com/Azure/azure-sdk-for-python/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-python/blob/main/doc/esrp_release.md)
- [Commits](Azure/azure-sdk-for-python@azure-storage-blob_12.13.1...azure-storage-blob_12.23.1)

---
updated-dependencies:
- dependency-name: azure-storage-blob
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Added admin.py to root in new app, and added app dir to tests (#892)

added admin.py to root in new app, and added app dir to tests

* Description to forms (#894)

added description to form

* Bug report system (#865)

* Created New App named Index

* created model

* Refactor: Change admin file

* admin

* added serializer and viewsets for list

* fixed typing error for permission_classes

* Started on the create serializer for feedback

* Made tests for create feedback

* Implemented update serializer for feedback

* made destroy method and testing create method as member

* Made destroy method and tests

* Fixed linting

* Fixed linting

---------

Co-authored-by: Tam Le <[email protected]>
Co-authored-by: Josefine Arntsen <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* Renaming of index app to feedback (#901)

renamed index app to feedback

* chore(deps): bump django from 4.2.16 to 5.1.1 (#889)

Bumps [django](https://github.com/django/django) from 4.2.16 to 5.1.1.
- [Commits](django/django@4.2.16...5.1.1)

---
updated-dependencies:
- dependency-name: django
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Event registration race condition (#902)

* started on fixing race condition

* fixed race condition

* upadted CHANGELOG.md

* Feat(registration)/filter participants (#895)

* filtering by year and study

* linting fix

* added allergy filter

* added filter by allergies and participants with allergy count to event.

* Lint fix

* Add new fixture for admin user

* Start testing filtering + finished allergy filter test

* Added integration test for participants filtering

* lint fix

* removed unused import

* Update changelog

* merge with dev and more filters

* Fixed has_paid filter and added filter combination test

* ran linting script

---------

Co-authored-by: Harry Linrui XU <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* Feat(registration)/filter participants (#915)

* filtering by year and study

* linting fix

* added allergy filter

* added filter by allergies and participants with allergy count to event.

* Lint fix

* Add new fixture for admin user

* Start testing filtering + finished allergy filter test

* Added integration test for participants filtering

* lint fix

* removed unused import

* Update changelog

* merge with dev and more filters

* Fixed has_paid filter and added filter combination test

* ran linting script

* fixed has allergy count bug, and has_paid bug

* post linting

---------

Co-authored-by: Harry Linrui XU <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* Fix issue where full error is exposed to external users (#914)

Signed-off-by: Tmpecho <[email protected]>

* chore(deps): Bump sentry-sdk from 2.8.0 to 2.14.0 (#893)

Bumps [sentry-sdk](https://github.com/getsentry/sentry-python) from 2.8.0 to 2.14.0.
- [Release notes](https://github.com/getsentry/sentry-python/releases)
- [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md)
- [Commits](getsentry/sentry-python@2.8.0...2.14.0)

---
updated-dependencies:
- dependency-name: sentry-sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Refactor/minor code cleanup (#884)

* Prefix unused variable names with underscore, remove redundant parenthesis, split long lines into several, rename functions to snake_case,

Signed-off-by: Tmpecho <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Tmpecho <[email protected]>

* Make constant uppercase

Signed-off-by: Tmpecho <[email protected]>

* Empty-Commit

---------

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* Add default detail to custom exceptions (#916)

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* chore(deps): bump uvicorn from 0.30.6 to 0.32.0 (#908)

Bumps [uvicorn](https://github.com/encode/uvicorn) from 0.30.6 to 0.32.0.
- [Release notes](https://github.com/encode/uvicorn/releases)
- [Changelog](https://github.com/encode/uvicorn/blob/master/CHANGELOG.md)
- [Commits](encode/uvicorn@0.30.6...0.32.0)

---
updated-dependencies:
- dependency-name: uvicorn
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* chore(deps): Bump pre-commit from 3.8.0 to 4.0.1 (#899)

Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 3.8.0 to 4.0.1.
- [Release notes](https://github.com/pre-commit/pre-commit/releases)
- [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md)
- [Commits](pre-commit/pre-commit@v3.8.0...v4.0.1)

---
updated-dependencies:
- dependency-name: pre-commit
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mads Nylund <[email protected]>

* Feat(registration)/filter participants (#917)


Fixed bugs introduced in an earlier pr

---------

Co-authored-by: Harry Linrui XU <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>
Co-authored-by: haruixu <[email protected]>

* Upload files (#906)

* Create files app to manage user uploaded files

Signed-off-by: Tmpecho <[email protected]>

* created serializers for file and gallery

* Move file upload endpoint from content/ to files/, create file and gallery views, add file and gallery model methods

Signed-off-by: Tmpecho <[email protected]>

* updating progress, needed to rename 'Gallery' to 'UserGallery' as a Gallery model already exists

* finished mvp for file project

* updating progress

* mvp for file uploading/deletion

* forgot changelog, oopsie

* fixed error in permissions from allowing non-admins to delete files, fixed 'security threat'

* Minor fixes to file serializer

Signed-off-by: Tmpecho <[email protected]>

* Fix whitespace

Signed-off-by: Tmpecho <[email protected]>

* Add custom exeption with mixins for files class

Signed-off-by: Tmpecho <[email protected]>

* Update custom file exceptions, set max gallery size as global constant, throw custom exceptions

Signed-off-by: Tmpecho <[email protected]>

* create test for creating file when not having a gallery, format

* removed duplicate method

* small refactoring and removed 'url' from file model, changed it to 'OptionalFile'

* fix lint

---------

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: Tmpecho <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>
Co-authored-by: Johannes Aamot-Skeidsvoll <[email protected]>

* Refactor/ Fixed sorting in albums (#910)

* Created factory for album

* Fixed the order method in albums

* Fixed linting

* run migrations

---------

Co-authored-by: Mads Nylund <[email protected]>

* made it possible for members and leader of the organizing group to add members to event (#921)

Co-authored-by: Mads Nylund <[email protected]>

* Fix feeedback serializer on list (#927)

added description to serializer for feedback list

* added description to serializer for bug and idea

* Move file upload and deletion to content from files (#928)

Signed-off-by: Tmpecho <[email protected]>
Co-authored-by: Mads Nylund <[email protected]>

* Feedback V2 (#926)

* started on V2 of feedback

* Made more tests for retrieveing feedback details

* Started working on the filtering for status and status for feedback

* started on fix for filter

* fixed filtering

* format

* format

* trigger

---------

Co-authored-by: Tam Le <[email protected]>

* removed max limit from group description (#934)

* format

* removed duplicat fixture

---------

Signed-off-by: Tmpecho <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Erik Skjellevik <[email protected]>
Co-authored-by: haruixu <[email protected]>
Co-authored-by: Ester2109 <[email protected]>
Co-authored-by: Tam Le <[email protected]>
Co-authored-by: martcl <[email protected]>
Co-authored-by: Frikk Balder <[email protected]>
Co-authored-by: Emil Johnsen <[email protected]>
Co-authored-by: Johannes Aamot-Skeidsvoll <[email protected]>
Co-authored-by: 1Cezzo <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Josefine Arntsen <[email protected]>
Co-authored-by: Josefine Arntsen <[email protected]>
Co-authored-by: Yazan Zarka <[email protected]>
Co-authored-by: Harry Linrui XU <[email protected]>
Co-authored-by: Emil Johnsen <[email protected]>
Co-authored-by: Tmpecho <[email protected]>
Co-authored-by: LeMiTam <[email protected]>
  • Loading branch information
19 people authored Dec 26, 2024
1 parent 78bed9b commit 9af2aa3
Show file tree
Hide file tree
Showing 68 changed files with 1,449 additions and 106 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

## Neste versjon

## Versjon 2024.12.26
-**Filopplasting**. Det er nå mulig for admin brukere å laste opp- og slette filer.
-**Mail endepunkt**. Det er nå laget et endepunkt for å sende mailer.

## Versjon 2024.11.04
- 🎨**Overordnet**. Endret variabel og funksjonsnavn til å følge konvensjoner og andre små endringer.
-**Filtrering**. Admin kan nå filtere deltakere av et arrangement på studie, studieår, om deltakere har allergier, (om deltakere godtar å bli tatt bilde av, om deltakere har ankommet), i tillegg til søk på fornavn og etternavn.
Expand Down
2 changes: 2 additions & 0 deletions app/common/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ class BaseModelSerializer(serializers.ModelSerializer):
def update(self, instance, validated_data):
if hasattr(instance, "image") and "image" in validated_data:
replace_file(instance.image, validated_data.get("image", None))
if hasattr(instance, "file") and "file" in validated_data:
replace_file(instance.file, validated_data.get("file", None))
return super().update(instance, validated_data)
6 changes: 4 additions & 2 deletions app/communication/models/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ def send(self, connection):
return is_success

def __str__(self):
return (f"\"{self.subject}\", to {self.users.all()[0] if self.users.count() == 1 else f'{self.users.count()} users'}, "
f"{'sent' if self.sent else 'eta'} {self.eta}")
return (
f"\"{self.subject}\", to {self.users.all()[0] if self.users.count() == 1 else f'{self.users.count()} users'}, "
f"{'sent' if self.sent else 'eta'} {self.eta}"
)
2 changes: 2 additions & 0 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
SLACK_BEDPRES_OG_KURS_CHANNEL_ID = "C01DCSJ8X2Q"
SLACK_ARRANGEMENTER_CHANNEL_ID = "C01LFEFJFV3"

MAX_GALLERY_SIZE = 50

# TODO: Create api-urls as constants which then can be used in for example tests and urls.py files
5 changes: 2 additions & 3 deletions app/content/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
UserCalendarEvents,
UserViewSet,
accept_form,
delete,
register_with_feide,
send_email,
upload,
)
from app.files.views.upload import delete, upload

router = routers.DefaultRouter()

Expand Down Expand Up @@ -54,8 +53,8 @@
re_path(r"", include(router.urls)),
path("accept-form/", accept_form),
path("upload/", upload),
path("send-email/", send_email),
path("delete-file/<str:container_name>/<str:blob_name>/", delete),
path("send-email/", send_email),
path("feide/", register_with_feide),
re_path(r"users/(?P<user_id>[^/.]+)/events.ics", UserCalendarEvents()),
]
2 changes: 1 addition & 1 deletion app/content/util/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from app.content.exceptions import RefundFailedError
from app.payment.tasks import check_if_has_paid
from app.payment.util.payment_utils import (
check_access_token,
initiate_payment,
refund_payment,
check_access_token
)


Expand Down
1 change: 0 additions & 1 deletion app/content/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from app.content.views.news import NewsViewSet
from app.content.views.page import PageViewSet
from app.content.views.short_link import ShortLinkViewSet
from app.content.views.upload import upload, delete
from app.content.views.strike import StrikeViewSet
from app.content.views.toddel import ToddelViewSet
from app.content.views.qr_code import QRCodeViewSet
Expand Down
8 changes: 5 additions & 3 deletions app/content/views/accept_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def accept_form(request):
if len(types) == 1 and types[0].lower() == "annonse"
else MAIL_NOK_LEADER
)
title = (f"{body['info']['bedrift']} vil ha {', '.join(types[:-1])}"
f"{' og ' if len(types) > 1 else ''}{', '.join(types[-1:])}, "
f"{', '.join(times[:-1])}{' og ' if len(times) > 1 else ''}{', '.join(times[-1:])}")
title = (
f"{body['info']['bedrift']} vil ha {', '.join(types[:-1])}"
f"{' og ' if len(types) > 1 else ''}{', '.join(types[-1:])}, "
f"{', '.join(times[:-1])}{' og ' if len(times) > 1 else ''}{', '.join(times[-1:])}"
)

is_success = send_html_email(
to_mails=[to_mail],
Expand Down
24 changes: 17 additions & 7 deletions app/content/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from app.common.pagination import BasePagination
from app.common.permissions import (
BasicViewPermission,
check_has_access,
is_admin_group_user,
is_admin_user,
)
Expand Down Expand Up @@ -157,20 +158,29 @@ def _admin_unregister(self, registration):
def add_registration(self, request, *_args, **_kwargs):
"""Add registration to event for admins"""

if not is_admin_group_user(request):
event_id = self.kwargs.get("event_id", None)
user_id = request.data["user"]

event = get_object_or_404(Event, id=event_id)
user = get_object_or_404(User, user_id=user_id)

organizing_group = event.organizer

is_member_or_leader_of_organizing_group = check_has_access(
[organizing_group], request
)

if (
not is_admin_group_user(request)
and not is_member_or_leader_of_organizing_group
):
return Response(
{
"detail": "Du har ikke tillatelse til å opprette en påmelding på dette arrangementet"
},
status=status.HTTP_403_FORBIDDEN,
)

event_id = self.kwargs.get("event_id", None)
user_id = request.data["user"]

event = get_object_or_404(Event, id=event_id)
user = get_object_or_404(User, user_id=user_id)

if not user.accepts_event_rules:
return Response(
{
Expand Down
4 changes: 1 addition & 3 deletions app/content/views/user_bio.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ def update(self, request, *args, **kwargs):

def destroy(self, request, *args, **kwargs):
super().destroy(request, *args, **kwargs)
return Response(
{"detail": "Brukerbio ble slettet"}, status=status.HTTP_200_OK
)
return Response({"detail": "Brukerbio ble slettet"}, status=status.HTTP_200_OK)
2 changes: 1 addition & 1 deletion app/content/views/user_calendar_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __call__(self, request, *args, **kwargs):
return JsonResponse(
{
"detail": "Denne brukeren har skrudd av offentlig deling av påmeldinger til arrangementer. "
"Du kan derfor ikke hente ut brukerens arrangementer som .ics-fil"
"Du kan derfor ikke hente ut brukerens arrangementer som .ics-fil"
},
status=status.HTTP_403_FORBIDDEN,
)
Expand Down
4 changes: 4 additions & 0 deletions app/feedback/factories/bug_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ class Meta:

title = factory.Sequence(lambda n: f"Bug{n}")
author = factory.SubFactory(UserFactory)
description = factory.Faker("text")
url = factory.Faker("url")
platform = factory.Faker("word")
browser = factory.Faker("word")
1 change: 1 addition & 0 deletions app/feedback/factories/idea_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ class Meta:

title = factory.Sequence(lambda n: f"Idea{n}")
author = factory.SubFactory(UserFactory)
description = factory.Faker("text")
46 changes: 46 additions & 0 deletions app/feedback/filters/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from django.db.models import Q
from django_filters import rest_framework as filters
from django_filters.rest_framework import OrderingFilter

from app.feedback.models import Feedback
from app.feedback.models.bug import Bug
from app.feedback.models.idea import Idea


class FeedbackFilter(filters.FilterSet):
feedback_type = filters.CharFilter(
method="filter_feedback_type", label="List of feedback type"
)

status = filters.CharFilter(
method="filter_status",
label="List of feedback status",
)

ordering = OrderingFilter(
fields=(
"created_at",
"updated_at",
)
)

def filter_feedback_type(self, queryset, _name, feedback_type):
if feedback_type == "Idea":
return queryset.filter(Q(instance_of=Idea))
elif feedback_type == "Bug":
return queryset.filter(Q(instance_of=Bug))
else:
return queryset

def filter_status(self, queryset, _name, value):
return queryset.filter(status=value)

class Meta:
model = Feedback
fields = [
"title",
"author",
"status",
"created_at",
"updated_at",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.5 on 2024-10-21 18:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("feedback", "0001_initial"),
]

operations = [
migrations.AlterModelOptions(
name="feedback",
options={"ordering": ("-created_at",)},
),
migrations.AddField(
model_name="bug",
name="Browser",
field=models.CharField(default="", max_length=200),
),
migrations.AddField(
model_name="bug",
name="Platform",
field=models.CharField(default="", max_length=200),
),
migrations.AddField(
model_name="bug",
name="Url",
field=models.URLField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.5 on 2024-10-21 22:18

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("feedback", "0002_alter_feedback_options_bug_browser_bug_platform_and_more"),
]

operations = [
migrations.RenameField(
model_name="bug",
old_name="Browser",
new_name="browser",
),
migrations.RenameField(
model_name="bug",
old_name="Platform",
new_name="platform",
),
migrations.RenameField(
model_name="bug",
old_name="Url",
new_name="url",
),
]
6 changes: 5 additions & 1 deletion app/feedback/models/bug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.db import models

from app.feedback.models.feedback import Feedback


class Bug(Feedback):
pass
url = models.URLField(max_length=200, blank=True, null=True)
browser = models.CharField(max_length=200, default="")
platform = models.CharField(max_length=200, default="")
2 changes: 1 addition & 1 deletion app/feedback/models/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __str__(self):
return f"{self.title} - {self.status}"

class Meta:
ordering = ("created_at",)
ordering = ("-created_at",)

@classmethod
def has_read_permission(cls, request):
Expand Down
12 changes: 10 additions & 2 deletions app/feedback/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
from app.feedback.serializers.bug import BugListSerializer
from app.feedback.serializers.idea import IdeaListSerializer
from app.feedback.serializers.bug import (
BugDetailSerializer,
BugCreateSerializer,
BugUpdateSerializer,
)
from app.feedback.serializers.idea import (
IdeaDetailSerializer,
IdeaCreateSerializer,
IdeaUpdateSerializer,
)
from app.feedback.serializers.feedback import FeedbackListPolymorphicSerializer
49 changes: 48 additions & 1 deletion app/feedback/serializers/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.feedback.models.bug import Bug


class BugListSerializer(BaseModelSerializer):
class BugSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
Expand All @@ -14,4 +14,51 @@ class Meta:
"status",
"created_at",
"author",
"description",
)


class BugCreateSerializer(BaseModelSerializer):
class Meta:
model = Bug
fields = (
"title",
"description",
)

def create(self, validated_data):
user = self.context["request"].user
validated_data["author"] = user

return super().create(validated_data)


class BugUpdateSerializer(BaseModelSerializer):
class Meta:
model = Bug
fields = (
"title",
"description",
"status",
)

def update(self, instance, validated_data):
return super().update(instance, validated_data)


class BugDetailSerializer(BaseModelSerializer):
author = SimpleUserSerializer(read_only=True)

class Meta:
model = Bug
fields = (
"id",
"title",
"description",
"status",
"created_at",
"author",
"url",
"platform",
"browser",
)
Loading

0 comments on commit 9af2aa3

Please sign in to comment.