Files
2026-09-18 13:55:25 +07:00

35 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
"""Post-install / upgrade hooks for nextzen_document."""
def post_init_hook(env):
"""Migrate legacy nxz.document.share tokens onto file access fields."""
Share = env["nxz.document.share"].sudo()
File = env["nxz.document.file"].sudo()
shares = Share.search([])
for share in shares:
doc = share.file_id
if not doc:
continue
vals = {}
if not doc.access_token and share.access_token:
vals["access_token"] = share.access_token
if doc.access_via_link == "none":
vals["access_via_link"] = "view"
if vals:
# Bypass uniqueness race by writing one-by-one
try:
doc.write(vals)
except Exception:
if "access_token" in vals and not doc.access_token:
doc.write(
{
"access_via_link": vals.get(
"access_via_link", doc.access_via_link
)
}
)
# Ensure every existing file has a token for Copy Link
for doc in File.search([("access_token", "=", False)]):
doc._ensure_access_token()