Skip to content

Commit 9a19163

Browse files
TmpechoEmilJohns1
andauthored
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]>
1 parent 0c1de71 commit 9a19163

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+279
-249
lines changed

app/common/enums.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ class Groups(models.TextChoices):
7777

7878
@classmethod
7979
def all(cls):
80-
return (cls.TIHLDE, cls.JUBKOM, cls.REDAKSJONEN, cls.FONDET, cls.PLASK, cls.DRIFT)
80+
return (
81+
cls.TIHLDE,
82+
cls.JUBKOM,
83+
cls.REDAKSJONEN,
84+
cls.FONDET,
85+
cls.PLASK,
86+
cls.DRIFT,
87+
)
8188

8289

8390
# This can't be removed because it is used in the migrations. It is not used in the code.
@@ -110,6 +117,10 @@ class NativeGroupType(models.TextChoices):
110117
def public_groups(cls):
111118
return [cls.BOARD, cls.SUBGROUP, cls.COMMITTEE, cls.INTERESTGROUP]
112119

120+
@classmethod
121+
def non_public_groups(cls):
122+
return [cls.TIHLDE, cls.STUDYYEAR, cls.STUDY, cls.OTHER]
123+
113124

114125
class EnvironmentOptions(Enum):
115126
LOCAL = "LOCAL"
@@ -173,7 +184,13 @@ class NativeStrikeEnum(models.TextChoices):
173184

174185
@classmethod
175186
def all(cls):
176-
return [cls.PAST_DEADLINE, cls.NO_SHOW, cls.LATE, cls.BAD_BEHAVIOR, cls.EVAL_FORM]
187+
return [
188+
cls.PAST_DEADLINE,
189+
cls.NO_SHOW,
190+
cls.LATE,
191+
cls.BAD_BEHAVIOR,
192+
cls.EVAL_FORM,
193+
]
177194

178195

179196
class CodexGroups(models.TextChoices):

app/content/factories/cheatsheet_factory.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import factory
44
from factory.django import DjangoModelFactory
55

6-
from app.common.enums import (
7-
NativeCheatsheetType as CheatsheetType,
8-
NativeUserClass as UserClass,
9-
NativeUserStudy as UserStudy
10-
)
6+
from app.common.enums import NativeCheatsheetType as CheatsheetType
7+
from app.common.enums import NativeUserClass as UserClass
8+
from app.common.enums import NativeUserStudy as UserStudy
119
from app.content.models import Cheatsheet
1210

1311

app/content/filters/user.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from django_filters.rest_framework import BooleanFilter, CharFilter, FilterSet
22

3-
from app.common.enums import (
4-
Groups,
5-
NativeGroupType as GroupType
6-
)
3+
from app.common.enums import Groups
4+
from app.common.enums import NativeGroupType as GroupType
75
from app.content.models import User
86
from app.content.models.strike import Strike
97

app/content/models/cheatsheet.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
from django.db import models
44

5-
from app.common.enums import (
6-
AdminGroup,
7-
NativeCheatsheetType as CheatsheetType,
8-
Groups,
9-
NativeUserClass as UserClass,
10-
NativeUserStudy as UserStudy,
11-
)
5+
from app.common.enums import AdminGroup, Groups
6+
from app.common.enums import NativeCheatsheetType as CheatsheetType
7+
from app.common.enums import NativeUserClass as UserClass
8+
from app.common.enums import NativeUserStudy as UserStudy
129
from app.common.permissions import BasePermissionModel
1310
from app.util.models import BaseModel
1411

@@ -19,10 +16,16 @@ class Cheatsheet(BaseModel, BasePermissionModel):
1916
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
2017
title = models.CharField(max_length=200)
2118
creator = models.CharField(max_length=200)
22-
grade = models.CharField(max_length=50, choices=UserClass.choices, default=UserClass.FIRST)
23-
study = models.CharField(max_length=50, choices=UserStudy.choices, default=UserStudy.DATAING)
19+
grade = models.CharField(
20+
max_length=50, choices=UserClass.choices, default=UserClass.FIRST
21+
)
22+
study = models.CharField(
23+
max_length=50, choices=UserStudy.choices, default=UserStudy.DATAING
24+
)
2425
course = models.CharField(max_length=200)
25-
type = models.CharField(max_length=50, choices=CheatsheetType.choices, default=CheatsheetType.LINK)
26+
type = models.CharField(
27+
max_length=50, choices=CheatsheetType.choices, default=CheatsheetType.LINK
28+
)
2629
official = models.BooleanField(default=False)
2730
url = models.URLField(max_length=600)
2831

app/content/models/news.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
from django.contrib.contenttypes.fields import GenericRelation
33
from django.db import models
44

5-
from app.common.enums import (
6-
AdminGroup,
7-
Groups
8-
)
5+
from app.common.enums import AdminGroup, Groups
96
from app.common.permissions import BasePermissionModel, check_has_access
107
from app.emoji.models.reaction import Reaction
118
from app.util.models import BaseModel, OptionalImage

app/content/models/toddel.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from django.db import models
22

3-
from app.common.enums import (
4-
AdminGroup,
5-
Groups
6-
)
3+
from app.common.enums import AdminGroup, Groups
74
from app.common.permissions import BasePermissionModel
85
from app.util.models import BaseModel
96
from app.util.utils import datetime_format

app/content/models/user.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
from django.dispatch import receiver
1414
from rest_framework.authtoken.models import Token
1515

16-
from app.common.enums import (
17-
AdminGroup,
18-
Groups,
19-
NativeGroupType as GroupType,
20-
NativeMembershipType as MembershipType
21-
)
16+
from app.common.enums import AdminGroup, Groups
17+
from app.common.enums import NativeGroupType as GroupType
18+
from app.common.enums import NativeMembershipType as MembershipType
2219
from app.common.permissions import check_has_access
2320
from app.util.models import BaseModel, OptionalImage
2421
from app.util.utils import disable_for_loaddata, now
@@ -176,8 +173,8 @@ def has_unanswered_evaluations_for(self, event):
176173
return self.get_unanswered_evaluations().filter(event=event).exists()
177174

178175
def get_unanswered_evaluations(self):
179-
from app.forms.models.forms import EventForm
180176
from app.forms.enums import NativeEventFormType as EventFormType
177+
from app.forms.models.forms import EventForm
181178

182179
date_30_days_ago = now() - timedelta(days=30)
183180
registrations = self.registrations.filter(has_attended=True)

app/content/serializers/event.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class EventSerializer(serializers.ModelSerializer):
2525
evaluation = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
2626
survey = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
2727
organizer = SimpleGroupSerializer(read_only=True)
28-
permissions = DRYPermissionsField(actions=["write", "read"], object_only=True, read_only=True)
28+
permissions = DRYPermissionsField(
29+
actions=["write", "read"], object_only=True, read_only=True
30+
)
2931
paid_information = serializers.SerializerMethodField(
3032
required=False, allow_null=True
3133
)

app/content/serializers/user.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
from dry_rest_permissions.generics import DRYGlobalPermissionsField
66

7-
from app.common.enums import (
8-
Groups,
9-
NativeGroupType as GroupType
10-
)
7+
from app.common.enums import Groups
8+
from app.common.enums import NativeGroupType as GroupType
119
from app.common.serializers import BaseModelSerializer
1210
from app.communication.enums import UserNotificationSettingType
1311
from app.communication.notifier import Notify

app/content/views/user.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
from app.badge.models import Badge, UserBadge
1010
from app.badge.serializers import BadgeSerializer, UserBadgeSerializer
11-
from app.common.enums import (
12-
Groups,
13-
NativeGroupType as GroupType
14-
)
11+
from app.common.enums import Groups
12+
from app.common.enums import NativeGroupType as GroupType
1513
from app.common.mixins import ActionMixin
1614
from app.common.pagination import BasePagination
1715
from app.common.permissions import (

app/forms/enums.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from enumchoicefield import ChoiceEnum
21
from django.db import models
32

3+
from enumchoicefield import ChoiceEnum
4+
45

56
# This must be here because of the migrations files
67
class EventFormType(ChoiceEnum):

app/forms/models/forms.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
from ordered_model.models import OrderedModel
66
from polymorphic.models import PolymorphicModel
77

8-
from app.common.enums import (
9-
AdminGroup,
10-
Groups
11-
)
8+
from app.common.enums import AdminGroup, Groups
129
from app.common.permissions import BasePermissionModel, check_has_access
1310
from app.content.models.event import Event
1411
from app.content.models.user import User
15-
from app.forms.enums import (
16-
NativeFormFieldType as FormFieldType,
17-
NativeEventFormType as EventFormType
18-
)
12+
from app.forms.enums import NativeEventFormType as EventFormType
13+
from app.forms.enums import NativeFormFieldType as FormFieldType
1914
from app.forms.exceptions import (
2015
DuplicateSubmission,
2116
FormNotOpenForSubmission,
@@ -118,7 +113,9 @@ def has_object_read_permission(self, request):
118113
class EventForm(Form):
119114

120115
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="forms")
121-
type = models.CharField(max_length=40, choices=EventFormType.choices, default=EventFormType.SURVEY)
116+
type = models.CharField(
117+
max_length=40, choices=EventFormType.choices, default=EventFormType.SURVEY
118+
)
122119

123120
class Meta:
124121
unique_together = ("event", "type")
@@ -218,7 +215,9 @@ class Field(OrderedModel):
218215
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
219216
title = models.CharField(max_length=400)
220217
form = models.ForeignKey(Form, on_delete=models.CASCADE, related_name="fields")
221-
type = models.CharField(max_length=40, choices=FormFieldType.choices, default=FormFieldType.TEXT_ANSWER)
218+
type = models.CharField(
219+
max_length=40, choices=FormFieldType.choices, default=FormFieldType.TEXT_ANSWER
220+
)
222221
required = models.BooleanField(default=False)
223222
order_with_respect_to = "form"
224223

app/group/exceptions.py

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ class APIUserIsNotInGroupException(APIException):
99

1010
class UserIsNotInGroup(ValidationError):
1111
pass
12+
13+
14+
class APIGroupTypeNotInPublicGroupsException(APIException):
15+
status_code = status.HTTP_400_BAD_REQUEST
16+
default_detail = "Ikke gylde gruppetype"
17+
18+
19+
class GroupTypeNotInPublicGroups(ValueError):
20+
pass

app/group/filters/group.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ class Meta:
1414
model: Group
1515
fields = ["type", "overview"]
1616

17-
def filter_type(self, queryset, name, value):
17+
def filter_type(self, queryset, _, value):
1818
"""Django Rest does not know hot to convert incoming string values into EnumChoiceField values and we must do this manually."""
1919
mapped = list(GroupType[v] for v in value)
2020
return queryset.filter(type__in=mapped)
2121

22-
def filter_overview(self, queryset, name, value):
22+
def filter_overview(self, queryset, _):
2323
if is_admin_user(self.request):
2424
return queryset
2525
return queryset.filter(type__in=GroupType.public_groups())

app/group/mixins.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from app.group.exceptions import APIUserIsNotInGroupException, UserIsNotInGroup
1+
from app.group.exceptions import (
2+
APIGroupTypeNotInPublicGroupsException,
3+
APIUserIsNotInGroupException,
4+
GroupTypeNotInPublicGroups,
5+
UserIsNotInGroup,
6+
)
27
from app.util.mixins import APIErrorsMixin
38

49

@@ -9,3 +14,12 @@ def expected_exceptions(self):
914
**super().expected_exceptions,
1015
UserIsNotInGroup: APIUserIsNotInGroupException,
1116
}
17+
18+
19+
class APIGroupErrorsMixin(APIErrorsMixin):
20+
@property
21+
def expected_exceptions(self):
22+
return {
23+
**super().expected_exceptions,
24+
GroupTypeNotInPublicGroups: APIGroupTypeNotInPublicGroupsException,
25+
}

app/group/models/group.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
from django.db import models
22
from django.utils.text import slugify
33

4-
from app.common.enums import AdminGroup, NativeGroupType as GroupType
5-
from app.common.permissions import BasePermissionModel, set_user_id
4+
from app.common.enums import AdminGroup
5+
from app.common.enums import NativeGroupType as GroupType
6+
from app.common.permissions import (
7+
BasePermissionModel,
8+
check_has_access,
9+
set_user_id,
10+
)
611
from app.communication.enums import UserNotificationSettingType
712
from app.content.models.user import User
813
from app.util.models import BaseModel, OptionalImage
914

1015

1116
class Group(OptionalImage, BaseModel, BasePermissionModel):
12-
17+
read_access = []
1318
write_access = AdminGroup.admin()
1419

1520
name = models.CharField(max_length=50)
1621
slug = models.SlugField(max_length=50, primary_key=True)
1722
description = models.TextField(max_length=1000, null=True, blank=True)
1823
contact_email = models.EmailField(max_length=200, null=True, blank=True)
1924
fine_info = models.TextField(default="", blank=True)
20-
type = models.CharField(max_length=50, choices=GroupType.choices, default=GroupType.OTHER)
25+
type = models.CharField(
26+
max_length=50, choices=GroupType.choices, default=GroupType.OTHER
27+
)
2128
fines_activated = models.BooleanField(default=False)
2229
members = models.ManyToManyField(
2330
User,
@@ -131,6 +138,10 @@ def has_write_permission(cls, request):
131138
except (Membership.DoesNotExist, KeyError, AssertionError):
132139
return super().has_write_permission(request)
133140

141+
@classmethod
142+
def has_create_permission(cls, request):
143+
return check_has_access(cls.write_access, request)
144+
134145
def has_object_write_permission(self, request):
135146
from app.group.models import Membership
136147

app/group/models/membership.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from django.db import models
22
from django.db.transaction import atomic
33

4-
from app.common.enums import (
5-
AdminGroup,
6-
NativeGroupType as GroupType,
7-
NativeMembershipType as MembershipType
8-
)
4+
from app.common.enums import AdminGroup
5+
from app.common.enums import NativeGroupType as GroupType
6+
from app.common.enums import NativeMembershipType as MembershipType
97
from app.common.permissions import BasePermissionModel
108
from app.content.models.user import User
119
from app.group.models.group import Group
@@ -24,7 +22,9 @@ class MembershipHistory(BaseModel):
2422
group = models.ForeignKey(
2523
Group, on_delete=models.CASCADE, related_name="membership_histories"
2624
)
27-
membership_type = models.CharField(max_length=50, choices=MembershipType.choices, default=MembershipType.MEMBER)
25+
membership_type = models.CharField(
26+
max_length=50, choices=MembershipType.choices, default=MembershipType.MEMBER
27+
)
2828
start_date = models.DateTimeField()
2929
end_date = models.DateTimeField()
3030

@@ -71,7 +71,9 @@ class Membership(BaseModel, BasePermissionModel):
7171
group = models.ForeignKey(
7272
Group, on_delete=models.CASCADE, related_name="memberships"
7373
)
74-
membership_type = models.CharField(max_length=50, choices=MembershipType.choices, default=MembershipType.MEMBER)
74+
membership_type = models.CharField(
75+
max_length=50, choices=MembershipType.choices, default=MembershipType.MEMBER
76+
)
7577
expiration_date = models.DateField(null=True, blank=True)
7678

7779
class Meta:

0 commit comments

Comments
 (0)