Skip to content

Commit ccde93c

Browse files
akelchphorwardArneGudermannsveneberth
authored
feat: FileBone(public=True) for public files (#1241)
This PR adds public files. Public files are stored in an extra bucket that follows this name: public-dot-{__PROJECT_ID} The bucket must be created with ACL rights. With getUploadUrl, the parameter public is used to decide whether it is a public file or not. FileBone(public=True) can only refer to a public file Public files again can deliver a servingurl, and this PR adds facilities to route these trought the ViUR system. --------- Co-authored-by: Andreas H. Kelch <> Co-authored-by: Jan Max Meyer <[email protected]> Co-authored-by: agudermann <[email protected]> Co-authored-by: Sven Eberth <[email protected]>
1 parent f52ce30 commit ccde93c

File tree

3 files changed

+315
-37
lines changed

3 files changed

+315
-37
lines changed

src/viur/core/bones/file.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class FileBone(TreeLeafBone):
128128

129129
kind = "file"
130130
"""The kind of this bone is 'file'"""
131+
131132
type = "relational.tree.leaf.file"
132133
"""The type of this bone is 'relational.tree.leaf.file'."""
133134

@@ -137,7 +138,16 @@ def __init__(
137138
derive: None | dict[str, t.Any] = None,
138139
maxFileSize: None | int = None,
139140
validMimeTypes: None | list[str] = None,
140-
refKeys: t.Optional[t.Iterable[str]] = ("name", "mimetype", "size", "width", "height", "derived"),
141+
refKeys: t.Optional[t.Iterable[str]] = (
142+
"name",
143+
"mimetype",
144+
"size",
145+
"width",
146+
"height",
147+
"derived",
148+
"public",
149+
),
150+
public: bool = False,
141151
**kwargs
142152
):
143153
r"""
@@ -170,6 +180,7 @@ def __init__(
170180

171181
self.refKeys.add("dlkey")
172182
self.derive = derive
183+
self.public = public
173184
self.validMimeTypes = validMimeTypes
174185
self.maxFileSize = maxFileSize
175186

@@ -191,6 +202,10 @@ def isInvalid(self, value):
191202
if self.maxFileSize:
192203
if value["dest"]["size"] > self.maxFileSize:
193204
return "File too large."
205+
206+
if value["dest"]["public"] != self.public:
207+
return f"Only files marked public={self.public!r} are allowed."
208+
194209
return None
195210

196211
def postSavedHandler(self, skel, boneName, key):
@@ -298,5 +313,6 @@ def recreateFileEntryIfNeeded(val):
298313

299314
def structure(self) -> dict:
300315
return super().structure() | {
301-
"valid_mime_types": self.validMimeTypes
316+
"valid_mime_types": self.validMimeTypes,
317+
"public": self.public,
302318
}

0 commit comments

Comments
 (0)