-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix(registration)/allow-registration-for-grou…
…p-members
- Loading branch information
Showing
44 changed files
with
925 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.contrib import admin | ||
|
||
from app.files import models | ||
|
||
admin.site.register(models.UserGallery) | ||
admin.site.register(models.File) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class FilesConfig(AppConfig): | ||
name = "app.files" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from rest_framework import status | ||
from rest_framework.exceptions import APIException, ValidationError | ||
|
||
from app.constants import MAX_GALLERY_SIZE | ||
|
||
|
||
class APINoGalleryFoundForUser(APIException): | ||
status_code = status.HTTP_400_BAD_REQUEST | ||
default_detail = "Ingen galleri ble funnet for brukeren." | ||
|
||
|
||
class NoGalleryFoundForUser(ValidationError): | ||
default_detail = "Ingen galleri ble funnet for brukeren." | ||
|
||
|
||
class APIGalleryIsFull(APIException): | ||
status_code = status.HTTP_400_BAD_REQUEST | ||
default_detail = f"Galleriet er fullt med {MAX_GALLERY_SIZE} filer." | ||
|
||
|
||
class GalleryIsFull(ValidationError): | ||
default_detail = f"Galleriet er fullt med {MAX_GALLERY_SIZE} filer." |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Generated by Django 4.2.16 on 2024-10-07 16:45 | ||
|
||
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), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UserGallery", | ||
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)), | ||
( | ||
"author", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="user_galleries", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="File", | ||
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=80)), | ||
("url", models.URLField()), | ||
("description", models.TextField(blank=True)), | ||
( | ||
"gallery", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="files", | ||
to="files.usergallery", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 5.1.1 on 2024-10-31 15:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("files", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="file", | ||
name="url", | ||
), | ||
migrations.AddField( | ||
model_name="file", | ||
name="file", | ||
field=models.URLField(blank=True, max_length=600, null=True), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from app.files.exceptions import ( | ||
APIGalleryIsFull, | ||
APINoGalleryFoundForUser, | ||
GalleryIsFull, | ||
NoGalleryFoundForUser, | ||
) | ||
from app.util.mixins import APIErrorsMixin | ||
|
||
|
||
class FileErrorMixin(APIErrorsMixin): | ||
@property | ||
def expected_exceptions(self): | ||
return { | ||
**super().expected_exceptions, | ||
NoGalleryFoundForUser: APINoGalleryFoundForUser, | ||
GalleryIsFull: APIGalleryIsFull, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from app.files.models.user_gallery import UserGallery | ||
from app.files.models.file import File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from django.db import models | ||
from django.db.models import PROTECT | ||
|
||
from app.common.enums import AdminGroup, Groups | ||
from app.common.permissions import BasePermissionModel, check_has_access | ||
from app.files.models.user_gallery import UserGallery | ||
from app.util.models import BaseModel, OptionalFile | ||
|
||
|
||
class File(BaseModel, BasePermissionModel, OptionalFile): | ||
read_access = AdminGroup.admin() | ||
write_access = AdminGroup.admin() | ||
|
||
title = models.CharField(max_length=80) | ||
|
||
description = models.TextField(blank=True) | ||
gallery = models.ForeignKey( | ||
UserGallery, on_delete=PROTECT, related_name="files", blank=False | ||
) | ||
|
||
class Meta: | ||
pass | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
@classmethod | ||
def has_read_permission(cls, request): | ||
return super().has_read_permission(request) | ||
|
||
@classmethod | ||
def has_write_permission(cls, request): | ||
return check_has_access(Groups.TIHLDE, request) | ||
|
||
@classmethod | ||
def has_retrieve_permission(cls, request): | ||
return cls.has_read_permission(request) | ||
|
||
@classmethod | ||
def has_create_permission(cls, request): | ||
return check_has_access(cls.write_access, request) | ||
|
||
@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(Groups.TIHLDE, 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 self.gallery.author == request.user | ||
|
||
def has_object_destroy_permission(self, request): | ||
return self.gallery.author == request.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from django.db import models | ||
from django.db.models import PROTECT | ||
|
||
from app.common.enums import AdminGroup | ||
from app.common.permissions import BasePermissionModel | ||
from app.content.models.user import User | ||
from app.util.models import BaseModel | ||
|
||
|
||
class UserGallery(BaseModel, BasePermissionModel): | ||
read_access = AdminGroup.admin() | ||
write_access = AdminGroup.admin() | ||
|
||
author = models.OneToOneField( | ||
User, on_delete=PROTECT, related_name="user_galleries" | ||
) | ||
|
||
class Meta: | ||
pass | ||
|
||
def __str__(self): | ||
return f"Gallery by {self.author.first_name} {self.author.last_name}" | ||
|
||
@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 self.author == request.user | ||
|
||
def has_object_destroy_permission(self, request): | ||
return self.author == request.user | ||
|
||
@classmethod | ||
def get_all_files(cls, user): | ||
return cls.objects.get(author=user).files.all() | ||
|
||
@classmethod | ||
def has_gallery(cls, user): | ||
return cls.objects.filter(author=user).exists() | ||
|
||
@classmethod | ||
def create_gallery(cls, user): | ||
return cls.objects.create(author=user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from app.files.serializers.user_gallery import UserGallerySerializer | ||
from app.files.serializers.file import ( | ||
FileSerializer, | ||
CreateFileSerializer, | ||
DeleteFileSerializer, | ||
) |
Oops, something went wrong.