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

Mid Septemer Update #848

Merged
merged 42 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6aeef42
Feat(kontres)/add image to bookable item (#785)
eriskjel Mar 23, 2024
c9b5975
Feat(kontres)/add approved by (#786)
eriskjel Apr 6, 2024
28067fa
Create minutes for Codex (#787)
MadsNyl Apr 8, 2024
9e4ff76
Feat(minute)/viewset (#788)
MadsNyl Apr 8, 2024
0544b2f
Feat(kontres)/add notification (#790)
eriskjel Apr 10, 2024
ae483dd
Memberships with fines activated (#791)
MadsNyl Apr 12, 2024
95ef58c
fixed merge
MadsNyl Apr 13, 2024
bfa2299
Feat(user)/user bio (#758)
haruixu Apr 16, 2024
3f56496
Update CHANGELOG.md
MadsNyl Apr 16, 2024
064da8a
added filter for allowed photos for user (#794)
MadsNyl Apr 17, 2024
81a3c5e
Upped payment time when coming from waiting list (#796)
MadsNyl Apr 17, 2024
a583c45
fixed paymenttime saved to db (#798)
MadsNyl Apr 17, 2024
0f24085
fixed bug (#800)
MadsNyl Apr 17, 2024
8a3cfd4
fixed mergeconflict
MadsNyl Apr 17, 2024
e597268
Disallow users to unregister when payment is done (#802)
MadsNyl May 1, 2024
3b84765
update changelog
MadsNyl May 1, 2024
f21e0ab
Added serializer for category in event (#804)
MadsNyl May 2, 2024
e30f102
fixed merge
MadsNyl May 2, 2024
64d717c
Permission middelware (#806)
MadsNyl Jun 9, 2024
ed57afc
Permission refactor of QR Codes (#807)
MadsNyl Jun 9, 2024
ab3cf15
Permissions for payment orders (#808)
MadsNyl Jun 10, 2024
062193d
chore(iac): updated docs and force https (#810)
martcl Jul 26, 2024
23b310a
feat(iac): add terraform guardrails so index don't nuke our infra (#811)
martcl Jul 26, 2024
fa31096
Automatic registration for new users with Feide (#809)
MadsNyl Jul 30, 2024
bef294d
changelog update
MadsNyl Jul 30, 2024
4db63b5
Merge branch 'dev' of https://github.com/TIHLDE/Lepton into dev
MadsNyl Jul 30, 2024
fcce5e8
Feide env variables Terraform (#814)
MadsNyl Jul 31, 2024
514a26b
added delete endpoint for file (#815)
MadsNyl Aug 4, 2024
d3e8e9a
Update CHANGELOG.md
MadsNyl Aug 4, 2024
a02af01
merge conflict
MadsNyl Aug 4, 2024
c9bf357
format
MadsNyl Aug 4, 2024
1a7dff4
format
MadsNyl Aug 4, 2024
f086ac2
fixed permission for committee leaders for group forms
MadsNyl Aug 18, 2024
ec03558
updated csv for forms (#818)
MadsNyl Aug 18, 2024
0526f02
Permission for group forms and news (#820)
MadsNyl Aug 21, 2024
39f7cd0
merge and changelog
MadsNyl Aug 21, 2024
f40fba0
Update reservation_seralizer.py (#822)
MindChirp Aug 27, 2024
1f03c30
Group ownership of Minutes (#847)
MadsNyl Sep 14, 2024
d7e9b91
Changed endpoint response (#846)
MindChirp Sep 14, 2024
b574fdc
updated changelog.md
MadsNyl Sep 14, 2024
8b83718
Merge branch 'dev' of https://github.com/TIHLDE/Lepton into dev
MadsNyl Sep 14, 2024
bf42e7a
merge
MadsNyl Sep 14, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

## Neste versjon

## Versjon 2024.09.14
- ⚡**Codex**. Det er nå et skille mellom dokumenter opprettet av Drift og Index.

## Versjon 2024.08.21
- ⚡**Nyheter**. Ledere av komiteer kan nå opprette nyheter.
- ⚡**Forms**. Alle ledere av grupper kan nå opprette gruppe spørreskjemaer.
Expand Down
16 changes: 16 additions & 0 deletions app/common/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from enum import Enum

from django.db import models

from enumchoicefield import ChoiceEnum


Expand Down Expand Up @@ -44,6 +46,7 @@ class Groups(ChoiceEnum):
REDAKSJONEN = "Redaksjonen"
FONDET = "Forvaltningsgruppen"
PLASK = "Plask"
DRIFT = "Drift"


class AppModel(ChoiceEnum):
Expand Down Expand Up @@ -106,3 +109,16 @@ class StrikeEnum(ChoiceEnum):
LATE = "LATE"
BAD_BEHAVIOR = "BAD_BEHAVIOR"
EVAL_FORM = "EVAL_FORM"


class CodexGroups(models.TextChoices):
DRIFT = "Drift"
INDEX = "Index"

@classmethod
def all(cls) -> list:
return [cls.DRIFT, cls.INDEX]

@classmethod
def reverse(cls) -> list:
return [cls.INDEX, cls.DRIFT]
18 changes: 18 additions & 0 deletions app/common/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ def check_has_access(groups_with_access, request):
return False


def check_has_full_access(groups_with_access: list[str], request):
"""Check if user has access to all groups"""
set_user_id(request)
user = request.user

if not user:
return False

try:
groups = map(str, groups_with_access)
return user and user.memberships.filter(
group__slug__iregex=r"(" + "|".join(groups) + ")"
).count() == len(groups_with_access)
except Exception as e:
capture_exception(e)
return False


def set_user_id(request):
# If the id and user of the request is already set, return
if (hasattr(request, "id") and request.id) and (
Expand Down
2 changes: 2 additions & 0 deletions app/content/factories/minute_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from app.content.factories.user_factory import UserFactory
from app.content.models.minute import Minute
from app.group.factories.group_factory import GroupFactory


class MinuteFactory(DjangoModelFactory):
Expand All @@ -12,3 +13,4 @@ class Meta:
title = factory.Faker("sentence", nb_words=4)
content = factory.Faker("text")
author = factory.SubFactory(UserFactory)
group = factory.SubFactory(GroupFactory)
27 changes: 27 additions & 0 deletions app/content/migrations/0066_minute_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.5 on 2024-09-12 14:16

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("group", "0018_fine_defense"),
("content", "0065_merge_0060_minute_tag_0064_alter_userbio_description"),
]

operations = [
migrations.AddField(
model_name="minute",
name="group",
field=models.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="meeting_minutes",
to="group.group",
),
),
]
28 changes: 28 additions & 0 deletions app/content/migrations/0067_alter_minute_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.5 on 2024-09-13 06:11

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("group", "0018_fine_defense"),
("content", "0066_minute_group"),
]

operations = [
migrations.AlterField(
model_name="minute",
name="group",
field=models.ForeignKey(
blank=True,
choices=[("Drift", "Drift"), ("Index", "Index")],
default="Index",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="meeting_minutes",
to="group.group",
),
),
]
32 changes: 26 additions & 6 deletions app/content/models/minute.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from django.db import models

from app.common.enums import AdminGroup
from app.common.permissions import BasePermissionModel
from app.common.enums import CodexGroups
from app.common.permissions import BasePermissionModel, check_has_access
from app.content.enums import MinuteTagEnum
from app.content.models.user import User
from app.group.models import Group
from app.util.models import BaseModel


class Minute(BaseModel, BasePermissionModel):
write_access = (AdminGroup.INDEX,)
read_access = (AdminGroup.INDEX,)
write_access = CodexGroups.all()
read_access = CodexGroups.all()

title = models.CharField(max_length=200)
content = models.TextField(default="", blank=True)
Expand All @@ -24,6 +25,22 @@ class Minute(BaseModel, BasePermissionModel):
on_delete=models.SET_NULL,
related_name="meeting_minutes",
)
group = models.ForeignKey(
Group,
blank=True,
null=True,
default=CodexGroups.INDEX,
choices=CodexGroups.choices,
on_delete=models.SET_NULL,
related_name="meeting_minutes",
)

@classmethod
def has_create_permission(cls, request):
data = request.data
if "group" in data:
return check_has_access([data["group"]], request)
return False

@classmethod
def has_update_permission(cls, request):
Expand All @@ -41,10 +58,13 @@ def has_object_read_permission(self, request):
return self.has_read_permission(request)

def has_object_update_permission(self, request):
return self.has_write_permission(request)
data = request.data
if "group" in data:
return check_has_access([data["group"]], request)
return False

def has_object_destroy_permission(self, request):
return self.has_write_permission(request)
return check_has_access([self.group.slug], request)

def has_object_retrieve_permission(self, request):
return self.has_read_permission(request)
Expand Down
20 changes: 16 additions & 4 deletions app/content/serializers/minute.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers

from app.content.models import Minute, User
from app.group.serializers import SimpleGroupSerializer


class SimpleUserSerializer(serializers.ModelSerializer):
Expand All @@ -12,7 +13,7 @@ class Meta:
class MinuteCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Minute
fields = ("title", "content", "tag")
fields = ("title", "content", "tag", "group")

def create(self, validated_data):
author = self.context["request"].user
Expand All @@ -22,24 +23,35 @@ def create(self, validated_data):

class MinuteSerializer(serializers.ModelSerializer):
author = SimpleUserSerializer(read_only=True)
group = SimpleGroupSerializer(read_only=True)

class Meta:
model = Minute
fields = ("id", "title", "content", "author", "created_at", "updated_at", "tag")
fields = (
"id",
"title",
"content",
"author",
"created_at",
"updated_at",
"tag",
"group",
)


class MinuteUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = Minute
fields = ("id", "title", "content", "tag")
fields = ("id", "title", "content", "tag", "group")

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


class MinuteListSerializer(serializers.ModelSerializer):
author = SimpleUserSerializer(read_only=True)
group = SimpleGroupSerializer(read_only=True)

class Meta:
model = Minute
fields = ("id", "title", "author", "created_at", "updated_at", "tag")
fields = ("id", "title", "author", "created_at", "updated_at", "tag", "group")
18 changes: 17 additions & 1 deletion app/content/views/minute.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, status
from rest_framework.exceptions import NotFound
from rest_framework.response import Response

from app.common.enums import CodexGroups
from app.common.pagination import BasePagination
from app.common.permissions import BasicViewPermission
from app.common.permissions import (
BasicViewPermission,
check_has_access,
check_has_full_access,
)
from app.common.viewsets import BaseViewSet
from app.content.filters import MinuteFilter
from app.content.models import Minute
Expand All @@ -30,6 +36,16 @@ class MinuteViewSet(BaseViewSet):
"author__user_id",
]

def get_queryset(self):
if check_has_full_access(CodexGroups.all(), self.request):
return self.queryset
elif check_has_access([CodexGroups.DRIFT], self.request):
return self.queryset.filter(group=CodexGroups.DRIFT)
elif check_has_access([CodexGroups.INDEX], self.request):
return self.queryset.filter(group=CodexGroups.INDEX)

raise NotFound()

def get_serializer_class(self):
if hasattr(self, "action") and self.action == "list":
return MinuteListSerializer
Expand Down
2 changes: 1 addition & 1 deletion app/kontres/views/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ def update(self, request, *args, **kwargs):
def destroy(self, request, *args, **kwargs):
super().destroy(self, request, *args, **kwargs)
return Response(
{"detail": "Reservasjonen ble slettet."}, status=status.HTTP_204_NO_CONTENT
{"detail": "Reservasjonen ble slettet."}, status=status.HTTP_200_OK
)
Loading
Loading