Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/pip/dev/sentry-sdk-2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl authored Oct 11, 2024
2 parents bba5a65 + 1a49b08 commit 6db5e9d
Show file tree
Hide file tree
Showing 37 changed files with 662 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
---

## Neste versjon

-**Tilbakemelding-funksjon**. Man kan nå opprette tilbakemeldinger for bugs og idé.
## Versjon 2024.09.25

-**Codex arrangementer**. Det kan nå opprettes arrangementer på Codex, som medlemmer av Codex kan melde seg på.
Expand Down
1 change: 1 addition & 0 deletions app/content/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Meta:
"user_id",
"first_name",
"last_name",
"image",
)


Expand Down
18 changes: 18 additions & 0 deletions app/forms/migrations/0014_form_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-10-01 06:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("forms", "0013_alter_field_type"),
]

operations = [
migrations.AddField(
model_name="form",
name="description",
field=models.TextField(blank=True, default=""),
),
]
1 change: 1 addition & 0 deletions app/forms/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Form(PolymorphicModel, BasePermissionModel):
write_access = (*AdminGroup.admin(), AdminGroup.NOK)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=400)
description = models.TextField(blank=True, default="")
template = models.BooleanField(default=False)

viewer_has_answered = None
Expand Down
1 change: 1 addition & 0 deletions app/forms/serializers/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Meta:
fields = (
"id",
"title",
"description",
"fields",
"template",
"resource_type",
Expand Down
Empty file added app/index/__init__.py
Empty file.
Empty file added app/index/admin/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions app/index/admin/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin

from app.index import models

admin.site.register(models.Bug)
5 changes: 5 additions & 0 deletions app/index/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class IndexConfig(AppConfig):
name = "app.index"
8 changes: 8 additions & 0 deletions app/index/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models


class Status(models.TextChoices):
OPEN = "OPEN", "Åpen"
CLOSED = "CLOSED", "Lukket"
IN_PROGRESS = "IN_PROGRESS", "Under arbeid"
REJECTED = "REJECTED", "Avvist"
Empty file added app/index/exceptions.py
Empty file.
2 changes: 2 additions & 0 deletions app/index/factories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from app.index.factories.bug_factory import BugFactory
from app.index.factories.idea_factory import IdeaFactory
13 changes: 13 additions & 0 deletions app/index/factories/bug_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import factory
from factory.django import DjangoModelFactory

from app.content.factories import UserFactory
from app.index.models.bug import Bug


class BugFactory(DjangoModelFactory):
class Meta:
model = Bug

title = factory.Sequence(lambda n: f"Bug{n}")
author = factory.SubFactory(UserFactory)
13 changes: 13 additions & 0 deletions app/index/factories/idea_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import factory
from factory.django import DjangoModelFactory

from app.content.factories import UserFactory
from app.index.models.idea import Idea


class IdeaFactory(DjangoModelFactory):
class Meta:
model = Idea

title = factory.Sequence(lambda n: f"Idea{n}")
author = factory.SubFactory(UserFactory)
Empty file added app/index/filters/__init__.py
Empty file.
112 changes: 112 additions & 0 deletions app/index/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Generated by Django 4.2.5 on 2024-09-26 14:54

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


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name="Feedback",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("title", models.CharField(max_length=100)),
("description", models.TextField(blank=True, default="")),
(
"status",
models.CharField(
default="OPEN",
max_length=20,
verbose_name=[
("OPEN", "Åpen"),
("CLOSED", "Lukket"),
("IN_PROGRESS", "Under arbeid"),
("REJECTED", "Avvist"),
],
),
),
(
"author",
models.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
),
),
(
"polymorphic_ctype",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="polymorphic_%(app_label)s.%(class)s_set+",
to="contenttypes.contenttype",
),
),
],
options={
"ordering": ("created_at",),
},
),
migrations.CreateModel(
name="Bug",
fields=[
(
"feedback_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="index.feedback",
),
),
],
options={
"abstract": False,
},
bases=("index.feedback",),
),
migrations.CreateModel(
name="Idea",
fields=[
(
"feedback_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="index.feedback",
),
),
],
options={
"abstract": False,
},
bases=("index.feedback",),
),
]
Empty file.
Empty file added app/index/mixins.py
Empty file.
3 changes: 3 additions & 0 deletions app/index/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from app.index.models.bug import Bug
from app.index.models.feedback import Feedback
from app.index.models.idea import Idea
5 changes: 5 additions & 0 deletions app/index/models/bug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app.index.models.feedback import Feedback


class Bug(Feedback):
pass
76 changes: 76 additions & 0 deletions app/index/models/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from django.db import models

from polymorphic.models import PolymorphicModel

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


class Feedback(BaseModel, BasePermissionModel, PolymorphicModel):

read_access = (Groups.TIHLDE,)
write_access = (Groups.TIHLDE,)

title = models.CharField(max_length=100)
description = models.TextField(default="", blank=True)

author = models.ForeignKey(
User, blank=True, null=True, default=None, on_delete=models.SET_NULL
)
status = models.CharField(Status.choices, default=Status.OPEN, max_length=20)

def __str__(self):
return f"{self.title} - {self.status}"

class Meta:
ordering = ("created_at",)

@classmethod
def has_read_permission(cls, request):
return super().has_read_permission(request)

@classmethod
def has_write_permission(cls, request):
return super().has_write_permission(request)

@classmethod
def has_retrieve_permission(cls, request):
return cls.has_read_permission(request)

@classmethod
def has_create_permission(cls, request):
return cls.has_write_permission(request)

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

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

@classmethod
def has_list_permission(cls, request):
return cls.has_read_permission(request)

def has_object_read_permission(self, request):
return self.has_read_permission(request)

def has_object_write_permission(self, request):
return self.has_write_permission(request)

def has_object_retrieve_permission(self, request):
return self.has_object_read_permission(request)

def has_object_update_permission(self, request):
return (
check_has_access([AdminGroup.INDEX], request) or self.author == request.user
)

def has_object_destroy_permission(self, request):
return (
check_has_access([AdminGroup.INDEX], request) or self.author == request.user
)
5 changes: 5 additions & 0 deletions app/index/models/idea.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from app.index.models.feedback import Feedback


class Idea(Feedback):
pass
3 changes: 3 additions & 0 deletions app/index/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from app.index.serializers.bug import BugListSerializer
from app.index.serializers.idea import IdeaListSerializer
from app.index.serializers.feedback import FeedbackListPolymorphicSerializer
17 changes: 17 additions & 0 deletions app/index/serializers/bug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from app.common.serializers import BaseModelSerializer
from app.content.serializers.user import SimpleUserSerializer
from app.index.models.bug import Bug


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

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

0 comments on commit 6db5e9d

Please sign in to comment.