Skip to content

Commit

Permalink
Early August Update (#816)
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

---------

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]>
  • Loading branch information
6 people authored Aug 4, 2024
1 parent 6f118fc commit 8a9cc2b
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 42 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:

- name: Checkout Code Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v2
Expand All @@ -35,7 +35,7 @@ jobs:
steps:

- name: Checkout Code Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up .env file
run: |
Expand All @@ -44,35 +44,35 @@ jobs:
echo "VIPPS_MERCHANT_SERIAL_NUMBER=${{ secrets.VIPPS_MERCHANT_SERIAL_NUMBER }}" >> .env
- name: Build the Stack
run: docker-compose build
run: docker compose build

- name: Run the Stack
run: docker-compose up -d
run: docker compose up -d

- name: Make DB Migrations
run: docker-compose run --rm web python manage.py migrate
run: docker compose run --rm web python manage.py migrate

- name: Run Django Tests
run: docker-compose run --rm web pytest --cov=app
run: docker compose run --rm web pytest --cov=app

- name: Tear down the Stack
run: docker-compose down
run: docker compose down

check-migrations:
runs-on: ubuntu-latest
steps:

- name: Checkout Code Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Build the Stack
run: docker-compose build
run: docker compose build

- name: Run the Stack
run: docker-compose up -d
run: docker compose up -d

- name: Check for unstaged migrations
run: docker-compose run --rm web python manage.py makemigrations --check --no-input
run: docker compose run --rm web python manage.py makemigrations --check --no-input

- name: Tear down the Stack
run: docker-compose down
run: docker compose down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ celerybeat-schedule

.terraform
*.tfvars
.terraform.lock.hcl
2 changes: 2 additions & 0 deletions .terraform.lock.hcl

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

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

## Versjon 2024.07.30
-**Feide**. Man kan nå registrere bruker automatisk med Feide.
-**Fillagring**. Man kan nå slette en fil fra Azure basert på container navn og fil navn.

## Versjon 2024.05.01
-**Arrangement**. Et arrangement vil nå få kategori sendt som navn på kategori istedenfor kun id.
Expand Down
2 changes: 1 addition & 1 deletion app/common/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def getContainerNameFromBlob(self):
return (
"".join(e for e in self.blob.content_type if e.isalnum())
if self.blob.content_type
else None
else "default"
)

def checkBlobSize(self):
Expand Down
20 changes: 9 additions & 11 deletions app/content/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

from dry_rest_permissions.generics import DRYGlobalPermissionsField

from app.communication.notifier import Notify
from app.communication.enums import UserNotificationSettingType
from app.common.enums import GroupType, Groups
from app.common.enums import Groups, GroupType
from app.common.serializers import BaseModelSerializer
from app.communication.enums import UserNotificationSettingType
from app.communication.notifier import Notify
from app.content.exceptions import FeideUserExistsError
from app.content.models import User
from app.content.serializers.user_bio import UserBioSerializer
from app.group.models import Group, Membership
from app.content.util.feide_utils import (
generate_random_password,
get_feide_tokens,
get_feide_user_groups,
parse_feide_groups,
generate_random_password,
get_study_year,
get_feide_user_info_from_jwt,
get_study_year,
parse_feide_groups,
)
from app.content.exceptions import FeideUserExistsError
from app.group.models import Group, Membership


class DefaultUserSerializer(BaseModelSerializer):
Expand Down Expand Up @@ -168,9 +168,7 @@ def add_user_to_study(self, user, slug):
study = Group.objects.filter(type=GroupType.STUDY, slug=slug).first()
study_year = get_study_year(slug)
class_ = Group.objects.get_or_create(
name=study_year,
type=GroupType.STUDYYEAR,
slug=study_year
name=study_year, type=GroupType.STUDYYEAR, slug=study_year
)

if not study or not class_:
Expand Down
4 changes: 3 additions & 1 deletion app/content/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
UserCalendarEvents,
UserViewSet,
accept_form,
upload,
delete,
register_with_feide,
upload,
)

router = routers.DefaultRouter()
Expand Down Expand Up @@ -52,6 +53,7 @@
re_path(r"", include(router.urls)),
path("accept-form/", accept_form),
path("upload/", upload),
path("delete-file/<str:container_name>/<str:blob_name>/", delete),
path("feide/", register_with_feide),
re_path(r"users/(?P<user_id>[^/.]+)/events.ics", UserCalendarEvents()),
]
27 changes: 13 additions & 14 deletions app/content/util/feide_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import jwt
import requests
import secrets
import string
from datetime import datetime

import jwt
import requests
from requests.auth import HTTPBasicAuth
from datetime import datetime

from app.content.exceptions import (
FeideGetTokenError,
FeideGetUserGroupsError,
FeideParseGroupsError,
FeideTokenNotFoundError,
FeideUsedUserCode,
FeideUserGroupsNotFoundError,
FeideUserInfoNotFoundError,
FeideUsernameNotFoundError,
)
from app.settings import (
FEIDE_CLIENT_ID,
FEIDE_CLIENT_SECRET,
Expand All @@ -14,17 +24,6 @@
FEIDE_USER_GROUPS_INFO_URL,
)

from app.content.exceptions import (
FeideTokenNotFoundError,
FeideGetTokenError,
FeideUserInfoNotFoundError,
FeideUsernameNotFoundError,
FeideUserGroupsNotFoundError,
FeideParseGroupsError,
FeideGetUserGroupsError,
FeideUsedUserCode,
)


def get_feide_tokens(code: str) -> tuple[str, str]:
"""Get access and JWT tokens for signed in Feide user"""
Expand Down
2 changes: 1 addition & 1 deletion app/content/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
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
7 changes: 5 additions & 2 deletions app/content/views/feide.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from rest_framework.decorators import api_view
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

from app.content.serializers import FeideUserCreateSerializer, DefaultUserSerializer
from app.content.exceptions import FeideError
from app.content.serializers import (
DefaultUserSerializer,
FeideUserCreateSerializer,
)


@api_view(["POST"])
Expand Down
22 changes: 22 additions & 0 deletions app/content/views/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,25 @@ def upload(request):
{"detail": str(value_error)},
status=status.HTTP_400_BAD_REQUEST,
)


@api_view(["DELETE"])
@permission_classes([IsMember])
def delete(request, container_name, blob_name):
"""Method for deleting files from Azure Blob Storage, only allowed for members"""
try:
handler = AzureFileHandler()
handler.blobName = blob_name
handler.containerName = container_name

handler.deleteBlob()
return Response(
{"detail": "Filen ble slettet"},
status=status.HTTP_200_OK,
)

except ValueError as value_error:
return Response(
{"detail": str(value_error)},
status=status.HTTP_400_BAD_REQUEST,
)
40 changes: 40 additions & 0 deletions infrastructure/containers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ resource "azurerm_container_app" "lepton-api" {
name = "VIPPS_ORDER_URL"
value = var.vipps_order_url
}
env {
name = "FEIDE_CLIENT_ID"
value = var.feide_client_id
}
env {
name = "FEIDE_CLIENT_SECRET"
value = var.feide_client_secret
}
env {
name = "FEIDE_TOKEN_URL"
value = var.feide_token_url
}
env {
name = "FEIDE_USER_GROUPS_INFO_URL"
value = var.feide_user_groups_info_url
}
env {
name = "FEIDE_REDIRECT_URL"
value = var.feide_redirect_url
}
env {
name = var.enviroment == "pro" ? "PROD" : "DEV"
value = "true"
Expand Down Expand Up @@ -337,6 +357,26 @@ resource "azurerm_container_app" "celery" {
name = "VIPPS_ORDER_URL"
value = var.vipps_order_url
}
env {
name = "FEIDE_CLIENT_ID"
value = var.feide_client_id
}
env {
name = "FEIDE_CLIENT_SECRET"
value = var.feide_client_secret
}
env {
name = "FEIDE_TOKEN_URL"
value = var.feide_token_url
}
env {
name = "FEIDE_USER_GROUPS_INFO_URL"
value = var.feide_user_groups_info_url
}
env {
name = "FEIDE_REDIRECT_URL"
value = var.feide_redirect_url
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions infrastructure/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ variable "lepton_api_max_replicas" {
default = 1
}

variable "feide_client_id" {
type = string
sensitive = true
}

variable "feide_client_secret" {
type = string
sensitive = true
}

variable "feide_token_url" {
type = string
default = "https://auth.dataporten.no/oauth/token"
}

variable "feide_user_groups_info_url" {
type = string
default = "https://groups-api.dataporten.no/groups/me/groups"
}

variable "feide_redirect_url" {
type = string
}

variable "enviroment" {
type = string
description = "value is either dev or pro"
Expand Down
6 changes: 6 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ module "infrastructure" {

lepton_api_min_replicas = var.lepton_api_min_replicas
lepton_api_max_replicas = var.lepton_api_max_replicas

feide_client_id = var.feide_client_id
feide_client_secret = var.feide_client_secret
feide_token_url = var.feide_token_url
feide_user_groups_info_url = var.feide_user_groups_info_url
feide_redirect_url = var.feide_redirect_url
}

0 comments on commit 8a9cc2b

Please sign in to comment.