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

Small Mid April Update #795

Merged
merged 10 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .envs/.local
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ DATABASE_HOST=db
DATABASE_NAME=nettside-dev
DATABASE_PASSWORD=password
DATABASE_PORT=3306
DATABASE_USER=root
DATABASE_USER=root
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.04.16
- ✨ **Brukerbio**. Bruker kan nå opprette bio.

## Versjon 2023.04.08
- ✨ **Codex** Index brukere kan nå opprette dokumenter og møtereferater i Codex.

Expand Down
3 changes: 3 additions & 0 deletions app/communication/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ class UserNotificationSettingType(models.TextChoices):
FINE = "FINE", "Grupper - bot"
GROUP_MEMBERSHIP = "GROUP_MEMBERSHIP", "Grupper - medlemsskap"
OTHER = "OTHER", "Andre"
RESERVATION_NEW = "RESERVATION NEW", "Ny reservasjon"
RESERVATION_APPROVED = "RESERVATION APPROVED", "Godkjent reservasjon"
RESERVATION_CANCELLED = "RESERVATION CANCELLED", "Avslått reservasjon"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.5 on 2024-04-10 16:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("communication", "0009_alter_usernotificationsetting_notification_type"),
]

operations = [
migrations.AlterField(
model_name="usernotificationsetting",
name="notification_type",
field=models.CharField(
choices=[
("REGISTRATION", "Påmeldingsoppdateringer"),
("UNREGISTRATION", "Avmeldingsoppdateringer"),
("STRIKE", "Prikkoppdateringer"),
("EVENT_SIGN_UP_START", "Arrangementer - påmeldingsstart"),
("EVENT_SIGN_OFF_DEADLINE", "Arrangementer - avmeldingsfrist"),
("EVENT_EVALUATION", "Arrangementer - evaluering"),
("EVENT_INFO", "Arrangementer - info fra arrangør"),
("FINE", "Grupper - bot"),
("GROUP_MEMBERSHIP", "Grupper - medlemsskap"),
("OTHER", "Andre"),
("RESERVATION NEW", "Ny reservasjon"),
("RESERVATION APPROVED", "Godkjent reservasjon"),
("RESERVATION CANCELLED", "Avslått reservasjon"),
],
max_length=30,
),
),
]
1 change: 1 addition & 0 deletions app/content/factories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
from app.content.factories.toddel_factory import ToddelFactory
from app.content.factories.priority_pool_factory import PriorityPoolFactory
from app.content.factories.qr_code_factory import QRCodeFactory
from app.content.factories.user_bio_factory import UserBioFactory
from app.content.factories.logentry_factory import LogEntryFactory
from app.content.factories.minute_factory import MinuteFactory
12 changes: 12 additions & 0 deletions app/content/factories/user_bio_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import factory
from factory.django import DjangoModelFactory

from app.content.factories.user_factory import UserFactory
from app.content.models.user_bio import UserBio


class UserBioFactory(DjangoModelFactory):
class Meta:
model = UserBio

user = factory.SubFactory(UserFactory)
7 changes: 7 additions & 0 deletions app/content/filters/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class UserFilter(FilterSet):
)
in_group = CharFilter(method="filter_is_in_group", label="Only list users in group")

has_allowed_photo = BooleanFilter(
method="filter_has_allowed_photo", label="Has allowed photo"
)

class Meta:
model: User
fields = [
Expand Down Expand Up @@ -52,3 +56,6 @@ def filter_has_active_strikes(self, queryset, name, value):
if value is False:
return queryset.exclude(strikes__in=Strike.objects.active()).distinct()
return queryset.filter(strikes__in=Strike.objects.active()).distinct()

def filter_has_allowed_photo(self, queryset, name, value):
return queryset.filter(allows_photo_by_default=value)
43 changes: 43 additions & 0 deletions app/content/migrations/0059_userbio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.5 on 2024-01-29 17:51

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


class Migration(migrations.Migration):

dependencies = [
("content", "0058_merge_20231217_2155"),
]

operations = [
migrations.CreateModel(
name="UserBio",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("description", models.CharField(max_length=50)),
("gitHub_link", models.URLField(blank=True, max_length=300, null=True)),
(
"linkedIn_link",
models.URLField(blank=True, max_length=300, null=True),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="bio",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
18 changes: 18 additions & 0 deletions app/content/migrations/0060_alter_userbio_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-02-01 10:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("content", "0059_userbio"),
]

operations = [
migrations.AlterField(
model_name="userbio",
name="description",
field=models.CharField(blank=True, max_length=50, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.5 on 2024-02-19 16:09

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
("content", "0060_alter_userbio_description"),
]

operations = [
migrations.AddField(
model_name="userbio",
name="created_at",
field=models.DateTimeField(
auto_now_add=True, default=django.utils.timezone.now
),
preserve_default=False,
),
migrations.AddField(
model_name="userbio",
name="updated_at",
field=models.DateTimeField(auto_now=True),
),
]
25 changes: 25 additions & 0 deletions app/content/migrations/0062_alter_userbio_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.5 on 2024-02-21 13:35

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


class Migration(migrations.Migration):

dependencies = [
("content", "0061_userbio_created_at_userbio_updated_at"),
]

operations = [
migrations.AlterField(
model_name="userbio",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="bio",
to=settings.AUTH_USER_MODEL,
unique=True,
),
),
]
24 changes: 24 additions & 0 deletions app/content/migrations/0063_alter_userbio_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.5 on 2024-02-21 13:39

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


class Migration(migrations.Migration):

dependencies = [
("content", "0062_alter_userbio_user"),
]

operations = [
migrations.AlterField(
model_name="userbio",
name="user",
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="bio",
to=settings.AUTH_USER_MODEL,
),
),
]
18 changes: 18 additions & 0 deletions app/content/migrations/0064_alter_userbio_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-02-26 15:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("content", "0063_alter_userbio_user"),
]

operations = [
migrations.AlterField(
model_name="userbio",
name="description",
field=models.CharField(blank=True, max_length=500, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 4.2.5 on 2024-04-16 06:58

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("content", "0060_minute_tag"),
("content", "0064_alter_userbio_description"),
]

operations = []
45 changes: 45 additions & 0 deletions app/content/models/user_bio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.db import models

from app.common.enums import Groups
from app.common.permissions import BasePermissionModel, check_has_access
from app.content.models.user import User
from app.util.models import BaseModel


class UserBio(BaseModel, BasePermissionModel):
read_access = (Groups.TIHLDE,)
write_access = (Groups.TIHLDE,)

description = models.CharField(max_length=500, blank=True, null=True)

gitHub_link = models.URLField(max_length=300, blank=True, null=True)

linkedIn_link = models.URLField(max_length=300, blank=True, null=True)

user = models.OneToOneField(
User, on_delete=models.CASCADE, unique=True, related_name="bio"
)

def __str__(self):
bio_str = f"{self.user}"
if self.description:
bio_str += f" - {self.description}"
if self.gitHub_link:
bio_str += f" - {self.gitHub_link}"
if self.linkedIn_link:
bio_str += f" - {self.linkedIn_link}"
return bio_str

@classmethod
def has_update_permission(cls, request):
return check_has_access(cls.write_access, request)

@classmethod
def has_destroy_permission(cls, request):
return check_has_access(cls.write_access, request)

def has_object_update_permission(self, request):
return self.user == request.user

def has_object_destroy_permission(self, request):
return self.user == request.user
3 changes: 3 additions & 0 deletions app/content/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from app.common.enums import GroupType
from app.common.serializers import BaseModelSerializer
from app.content.models import User
from app.content.serializers.user_bio import UserBioSerializer
from app.group.models import Group, Membership


Expand Down Expand Up @@ -50,6 +51,7 @@ def get_studyyear(self, obj):
class UserSerializer(DefaultUserSerializer):
unread_notifications = serializers.SerializerMethodField()
unanswered_evaluations_count = serializers.SerializerMethodField()
bio = UserBioSerializer(read_only=True, required=False)

class Meta:
model = User
Expand All @@ -63,6 +65,7 @@ class Meta:
"slack_user_id",
"allows_photo_by_default",
"accepts_event_rules",
"bio",
)
read_only_fields = ("user_id",)

Expand Down
23 changes: 23 additions & 0 deletions app/content/serializers/user_bio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from app.common.serializers import BaseModelSerializer
from app.content.models.user_bio import UserBio


class UserBioSerializer(BaseModelSerializer):
class Meta:
model = UserBio
fields = ["id", "description", "gitHub_link", "linkedIn_link"]


class UserBioCreateSerializer(BaseModelSerializer):
class Meta:
model = UserBio
fields = ["description", "gitHub_link", "linkedIn_link"]

def create(self, validated_data):
return super().create(validated_data)


class UserBioUpdateSerializer(BaseModelSerializer):
class Meta:
model = UserBio
fields = ["description", "gitHub_link", "linkedIn_link"]
2 changes: 2 additions & 0 deletions app/content/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ShortLinkViewSet,
StrikeViewSet,
ToddelViewSet,
UserBioViewset,
UserCalendarEvents,
UserViewSet,
accept_form,
Expand All @@ -30,6 +31,7 @@
router.register("short-links", ShortLinkViewSet, basename="short-link")
router.register("qr-codes", QRCodeViewSet, basename="qr-code")
router.register("users", UserViewSet, basename="user")
router.register("user-bios", UserBioViewset, basename="user-bio")
router.register(
r"events/(?P<event_id>\d+)/registrations",
RegistrationViewSet,
Expand Down
1 change: 1 addition & 0 deletions app/content/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
from app.content.views.strike import StrikeViewSet
from app.content.views.toddel import ToddelViewSet
from app.content.views.qr_code import QRCodeViewSet
from app.content.views.user_bio import UserBioViewset
from app.content.views.logentry import LogEntryViewSet
from app.content.views.minute import MinuteViewSet
Loading
Loading