Skip to content

Commit

Permalink
fix: More hotfixes for public files #1241 & #1344
Browse files Browse the repository at this point in the history
Added required `RecordBone.refresh` for Fluidpages.
  • Loading branch information
phorward committed Dec 9, 2024
1 parent 3d53e41 commit 652dd60
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This file documents any relevant changes done to ViUR-core since version 3.

## [3.7.0.rc7]
## [3.7.0.rc8]

- chore: Adding file deprecations (#1268)
- chore: Drop python 3.10 support (#1175)
Expand Down Expand Up @@ -55,7 +55,7 @@ This file documents any relevant changes done to ViUR-core since version 3.
- fix: `uploadKey` wrong in `getUploadUrl` (#1301)
- fix: `User.is_active()` without status-bone (#1331)
- fix: Add `__set_name__` in `__setattr__` for bones (#1312)
- fix: add `servingurl` to `FileBone`s default `refKeys` setting (#1344)
- fix: add `serving_url` to `FileBone`s default `refKeys` setting (#1344)
- fix: Add datetime import in email.py (#1225)
- fix: Add default param for `createRelSkelFromKey` (#1304)
- fix: Allow `list` in `SpatialBone` `setBoneValue` (#1335)
Expand Down
2 changes: 1 addition & 1 deletion src/viur/core/bones/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(
"height",
"derived",
"public",
"servingurl",
"serving_url",
),
public: bool = False,
**kwargs
Expand Down
12 changes: 12 additions & 0 deletions src/viur/core/bones/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,15 @@ def structure(self) -> dict:
return super().structure() | {
"format": self.format,
"using": self.using().structure()}

def refresh(self, skel, bone_name):
using_skel = self.using()

for idx, lang, value in self.iter_bone_value(skel, bone_name):
if value is None:
continue

using_skel.unserialize(value)

for key, bone in using_skel.items():
bone.refresh(using_skel, key)
27 changes: 17 additions & 10 deletions src/viur/core/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,19 +1261,26 @@ def mark_for_deletion(self, dlkey: str) -> None:

def inject_serving_url(self, skel: SkeletonInstance) -> None:
"""Inject the serving url for public image files into a FileSkel"""
# try to create a servingurl for images
if not conf.instance.is_dev_server and skel["public"] and skel["mimetype"] \
and skel["mimetype"].startswith("image/") and not skel["serving_url"]:
if (
skel["public"]
and skel["mimetype"]
and skel["mimetype"].startswith("image/")
and not skel["serving_url"]
):
bucket = File.get_bucket(skel["dlkey"])
filename = f"/gs/{bucket.name}/{skel['dlkey']}/source/{skel['name']}"

# Trying this on local development server will raise a
# `google.appengine.runtime.apiproxy_errors.RPCFailedError`
if conf.instance.is_dev_server:
logging.warning(f"Can't inject serving_url for {filename!r} on local development server")
return

try:
bucket = File.get_bucket(skel["dlkey"])
skel["serving_url"] = images.get_serving_url(
None,
secure_url=True,
filename=f"/gs/{bucket.name}/{skel['dlkey']}/source/{skel['name']}",
)
skel["serving_url"] = images.get_serving_url(None, secure_url=True, filename=filename)

except Exception as e:
logging.warning("Error while creating serving url")
logging.warning(f"Failed to create serving_url for {filename!r} with exception {e!r}")
logging.exception(e)


Expand Down
2 changes: 1 addition & 1 deletion src/viur/core/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This will mark it as a pre-release as well on PyPI.
# See CONTRIBUTING.md for further information.

__version__ = "3.7.0.rc7"
__version__ = "3.7.0.rc8"

assert __version__.count(".") >= 2 and "".join(__version__.split(".", 3)[:3]).isdigit(), \
"Semantic __version__ expected!"

0 comments on commit 652dd60

Please sign in to comment.