Repository Public
1#!/usr/bin/env python32# SP Notes Core3# File: Scripts/recorders/misc.py4# Description: Records the fixtures of the dashboard, settings, page lists (recent, pinned, archived, trash, section,5# children), trash purge (step-up) and tags routes.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9from _parity_support import ParityRecorder, new_id1011r = ParityRecorder("misc")12stale = not r.call("GET", "/api/auth/state").json.get("fresh")1314parent = r.page("tableau de bord parity", section="projects", icon="📊")15child = r.page("sous-page parity", parentId=parent["id"], section="projects")16second = r.page("seconde sous-page parity", parentId=parent["id"], section="projects")17doomed = r.page("à la corbeille parity")18r.call("PATCH", "/api/pages/" + parent["id"], {"pinned": True})19r.call("PATCH", "/api/pages/" + child["id"], {"archived": True})20r.call("PUT", "/api/pages/%s/tags" % parent["id"], {"tags": ["parity-fixture", "Thèse Parity"]}, save="page-tags-put")21task = r.call("POST", "/api/tasks", {"id": new_id(), "title": "Fixture · tâche du tableau de bord", "due": "2026-11-20", "priority": "high", "pageId": parent["id"], "status": "doing"}).json2223# Dashboard.24original = r.call("GET", "/api/dashboard", save="dashboard").json["layout"]25widgets = [{"id": "w-recent", "type": "recent_pages", "size": "half"}, {"id": "w-tasks", "type": "tasks_due", "size": "third", "config": {"days": 7}}, {"id": "w-usage", "type": "usage", "size": "wide"}]26r.call("PUT", "/api/dashboard", {"widgets": widgets}, save="dashboard-layout-put")27r.call("GET", "/api/dashboard", save="dashboard-custom")28r.call("PUT", "/api/dashboard", {"widgets": [{"id": "x", "type": "unicorn", "size": "half"}]}, save="dashboard-layout-validation")29r.call("PUT", "/api/dashboard", {}, save="dashboard-layout-empty")30r.call("PUT", "/api/dashboard", {"reset": True}, save="dashboard-layout-reset")31if original.get("custom"):32 r.call("PUT", "/api/dashboard", {"widgets": original["widgets"]}) # put the layout of the scratch account back33r.call("GET", "/api/dashboard/summary", save="dashboard-summary")3435# Settings.36before = r.call("GET", "/api/settings", save="settings").json37r.call("PATCH", "/api/settings", {"preferences": {"parityFixture": {"density": "compact", "theme": "dark"}}}, save="settings-patch")38r.call("PATCH", "/api/settings", {"displayName": "Fixture · Nom", "email": "fixture@example.org"}, save="settings-patch-profile")39r.call("GET", "/api/settings", save="settings-after")40r.call("PATCH", "/api/settings", {"email": "pas un courriel"}, save="settings-validation")41r.call("PATCH", "/api/settings", {"displayName": before["displayName"], "email": before["email"] or "", "preferences": {"parityFixture": None}}, save="settings-restore")42r.call("GET", "/api/settings/audit?limit=12", save="settings-audit")4344# Page lists.45r.call("DELETE", "/api/pages/" + doomed["id"])46r.call("GET", "/api/pages?view=recent&limit=5", save="pages-recent")47r.call("GET", "/api/pages?view=pinned", save="pages-pinned")48r.call("GET", "/api/pages?view=archived", save="pages-archived")49r.call("GET", "/api/pages?view=trash&limit=50", save="pages-trash")50r.call("GET", "/api/pages?view=section:projects&limit=5", save="pages-section")51r.call("GET", "/api/pages?view=children:" + parent["id"], save="pages-children")52r.call("GET", "/api/pages?view=children:nope", save="pages-children-bad-id")53r.call("GET", "/api/trash", save="trash-get-not-allowed")54r.call("POST", "/api/pages/%s?action=restore" % doomed["id"], save="trash-restore")55r.call("DELETE", "/api/pages/" + doomed["id"])5657# Tags.58r.call("GET", "/api/tags", save="tags")59r.call("PATCH", "/api/tags", {"id": new_id(), "name": "x"}, save="tags-patch-not-allowed")60r.call("DELETE", "/api/tags?id=" + new_id(), save="tags-delete-not-allowed")6162# Tasks list with a `doing` task.63r.call("GET", "/api/tasks?done=1", save="tasks")6465# Purge: needs a passkey verification younger than 5 minutes. `olderThanDays=3650` / `days: 365` match nothing on a66# scratch database: these calls delete nothing.67if stale:68 r.call("DELETE", "/api/trash?olderThanDays=3650", save="trash-reauth-required")69 r.call("POST", "/api/trash", {"action": "purge-old", "days": 365}, save="trash-purge-old-reauth-required")70else:71 r.keep("trash-reauth-required")72 r.keep("trash-purge-old-reauth-required")73if r.fresh():74 r.call("DELETE", "/api/trash?olderThanDays=3650", save="trash-empty-older")75 r.call("POST", "/api/trash", {"action": "purge-old", "days": 365}, save="trash-purge-old")76 r.call("POST", "/api/trash", {"action": "purge-everything"}, save="trash-purge-validation")77else:78 for name in ("trash-empty-older", "trash-purge-old", "trash-purge-validation"):79 r.keep(name)8081r.call("DELETE", "/api/tasks/" + task["id"])82r.call("PUT", "/api/pages/%s/tags" % parent["id"], {"tags": []})83r.finish()84