@ -15,7 +15,9 @@ class FileSerializer(ModelSerializer):
|
||||
"pk",
|
||||
"name",
|
||||
"content",
|
||||
"location",
|
||||
"private",
|
||||
"url",
|
||||
)
|
||||
|
||||
|
||||
@ -24,4 +26,7 @@ class FileViewSet(UsedByMixin, ModelViewSet):
|
||||
serializer_class = FileSerializer
|
||||
filterset_fields = ("private",)
|
||||
ordering = ("name",)
|
||||
search_fields = ("name",)
|
||||
search_fields = (
|
||||
"name",
|
||||
"location",
|
||||
)
|
||||
|
@ -0,0 +1,32 @@
|
||||
# Generated by Django 5.1.11 on 2025-06-13 15:29
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("authentik_core", "0049_file_rename_meta_icon_application_meta_old_icon"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="file",
|
||||
name="location",
|
||||
field=models.TextField(null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="file",
|
||||
name="content",
|
||||
field=models.BinaryField(null=True),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="file",
|
||||
constraint=models.CheckConstraint(
|
||||
condition=models.Q(
|
||||
("content__isnull", False), ("location__isnull", False), _connector="OR"
|
||||
),
|
||||
name="one_of_content_location_is_defined",
|
||||
),
|
||||
),
|
||||
]
|
@ -29,6 +29,7 @@ from authentik.blueprints.models import ManagedModel
|
||||
from authentik.core.expression.exceptions import PropertyMappingExpressionException
|
||||
from authentik.core.types import UILoginButton, UserSettingSerializer
|
||||
from authentik.lib.avatars import get_avatar
|
||||
from authentik.lib.config import CONFIG
|
||||
from authentik.lib.expression.exceptions import ControlFlowException
|
||||
from authentik.lib.generators import generate_id
|
||||
from authentik.lib.merge import MERGE_LIST_UNIQUE
|
||||
@ -1107,12 +1108,19 @@ class File(SerializerModel):
|
||||
id = models.UUIDField(primary_key=True, editable=False, default=uuid4)
|
||||
|
||||
name = models.TextField()
|
||||
content = models.BinaryField()
|
||||
content = models.BinaryField(null=True)
|
||||
location = models.TextField(null=True)
|
||||
public = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("File")
|
||||
verbose_name = _("Files")
|
||||
constraints = (
|
||||
models.CheckConstraint(
|
||||
condition=Q(content__isnull=False) | Q(location__isnull=False),
|
||||
name="one_of_content_location_is_defined",
|
||||
),
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
@ -1122,3 +1130,14 @@ class File(SerializerModel):
|
||||
from authentik.core.api.files import FileSerializer
|
||||
|
||||
return FileSerializer
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
if self.content:
|
||||
return (
|
||||
CONFIG.get("web.path", "/")[:-1]
|
||||
+ f"/files/{'public' if self.public else 'private'}/{self.pk}"
|
||||
)
|
||||
elif self.location.startswith("/"):
|
||||
return CONFIG.get("web.path", "/")[:-1] + self.location
|
||||
return self.location
|
||||
|
Reference in New Issue
Block a user