workpeg 0.166.0__tar.gz → 0.167.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {workpeg-0.166.0/src/workpeg.egg-info → workpeg-0.167.0}/PKG-INFO +1 -1
- {workpeg-0.166.0 → workpeg-0.167.0}/pyproject.toml +1 -1
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/app.py +33 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/build.py +22 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/ast_parser.py +54 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/permissions_manifest.py +41 -14
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/scaffold.js +684 -48
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/workpeg-runtime.js +67 -0
- {workpeg-0.166.0 → workpeg-0.167.0/src/workpeg.egg-info}/PKG-INFO +1 -1
- {workpeg-0.166.0 → workpeg-0.167.0}/LICENSE +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/MANIFEST.in +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/README.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/setup.cfg +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/auth.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/build.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/__main__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/canonical.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/envelope.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/builder/stages.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/cdn.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/cli.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/config.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/context.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/create_new.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/doctor.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_base.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_check.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_envelopes.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/function_local.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/listen.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/project.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/project_submit.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/run.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/runtime.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/docker_driver.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/sandbox/driver.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/starter.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/submit.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/target_sdk.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/agents/AGENTS.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/agents/CLAUDE.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/Dockerfile +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/LICENSE +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/README.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/app/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/app/main.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/requirements.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/functions/wheels/README.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/README.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/Dockerfile +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/app/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/app/main.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/requirements.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/function/wheels/README.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/project/workpeg.json +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/app_shell.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/components.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/main.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/customer.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/customers.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/home.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/templates/starter/pages/not_found.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/terminal.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/actions.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/actions_manifest.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/calendar.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/ir.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/js_generator.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/rtc_checks.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/compiler/rtc_tables.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/create.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/dates.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/dev_refused_names.json +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devmode.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devserve.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/devsite.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/fake_cloud.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/minify.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/render_nodes.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/renderers_manifest.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/rtc.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-concurrent-replies.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-prompt-queue.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-question-frame.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai-subagent-frame.md +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/ai.js +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/editor.js +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/OFL.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic-ext.af944491.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-cyrillic.88be6946.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin-ext.370a8962.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-latin.7611b95c.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-italic-vietnamese.8dfcf303.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic-ext.b7a545bb.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-cyrillic.6129fc85.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin-ext.58a6b173.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-latin.9b6f5ff4.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/fonts/geist-normal-vietnamese.f689f638.woff2 +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/icons.css.gz +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/overlay.js +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/pegment.css +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/runtime/rtc.js +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/scaffold.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/scaffold_check.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/search_manifest.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/serve.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/skills_manifest.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/state.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/validators.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/verify.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/watcher.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/__init__.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/base.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/canvas.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/display.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/fields.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/forms.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/futures.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/gestures.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/interactive.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/layout.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/ui/widgets/pickers.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg/utils.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/SOURCES.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/dependency_links.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/entry_points.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/requires.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/src/workpeg.egg-info/top_level.txt +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_agents_guide.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_auth.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_build.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cdn.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cdn_publish.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_changelog.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_changelog_guard.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_cli.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_command_cheatsheet.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_config.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_context.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_create_new.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_dev_functions_wire.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_dev_install_example.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_doctor.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_check.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_envelopes.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_function_listen.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_pegfn_base.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_project_create.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_project_submit.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_release_script.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_run.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_run_cli.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_runtime.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_runtime_invoke_key.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_submit.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_target_sdk.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_utils.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_version.py +0 -0
- {workpeg-0.166.0 → workpeg-0.167.0}/tests/test_watch_pipeline.py +0 -0
|
@@ -910,6 +910,39 @@ class _Workpeg:
|
|
|
910
910
|
"""
|
|
911
911
|
return self._unavailable("first_business")
|
|
912
912
|
|
|
913
|
+
def request_permission(self, name: str) -> Any:
|
|
914
|
+
"""Ask the person, over this Peg, for a permission it declares.
|
|
915
|
+
|
|
916
|
+
``name`` is a permission in ``workpeg.json``'s ``permissions``, a
|
|
917
|
+
fixed one or the one for all of the Peg's tables (``"table": "*"``),
|
|
918
|
+
which covers every table the Peg has, now or later, so no call names
|
|
919
|
+
a table::
|
|
920
|
+
|
|
921
|
+
async def connect(self):
|
|
922
|
+
outcome = await workpeg.request_permission("instant_answers")
|
|
923
|
+
|
|
924
|
+
Resolves to exactly one of ``"allowed"``, ``"denied"``,
|
|
925
|
+
``"dismissed"``, ``"needs_admin"`` or ``"unavailable"``, and never
|
|
926
|
+
rejects, so it needs no ``try``. Workpeg draws the question in a
|
|
927
|
+
window of its own over the Peg; the Peg's page cannot read it or
|
|
928
|
+
press its buttons (docs/permissions.md, "Ask while your Peg runs").
|
|
929
|
+
Compiles to ``Workpeg.wpRequestPermission``; never runs in Python.
|
|
930
|
+
"""
|
|
931
|
+
return self._unavailable("request_permission")
|
|
932
|
+
|
|
933
|
+
def permission_status(self, name: str) -> Any:
|
|
934
|
+
"""What the business decided about a permission this Peg declares,
|
|
935
|
+
without asking anybody.
|
|
936
|
+
|
|
937
|
+
Resolves to ``"allowed"``, ``"denied"``, ``"not_set"`` or
|
|
938
|
+
``"unavailable"``, never rejects, and draws nothing::
|
|
939
|
+
|
|
940
|
+
status = await workpeg.permission_status("instant_answers")
|
|
941
|
+
|
|
942
|
+
Compiles to ``Workpeg.wpPermissionStatus``; never runs in Python.
|
|
943
|
+
"""
|
|
944
|
+
return self._unavailable("permission_status")
|
|
945
|
+
|
|
913
946
|
# ``*_protected`` variants additionally send the session cookie
|
|
914
947
|
# (``credentials: "include"``) — the authenticated request, for endpoints
|
|
915
948
|
# behind a login (the recreation of the React ``fetchProtected`` helper)::
|
|
@@ -782,6 +782,7 @@ def build_ui(
|
|
|
782
782
|
js = minify_js(js)
|
|
783
783
|
|
|
784
784
|
_assert_parses(js, source)
|
|
785
|
+
_check_permission_calls(parser.permission_calls, source)
|
|
785
786
|
|
|
786
787
|
# Explicit argument wins over everything: that is Workpeg's own build
|
|
787
788
|
# server saying which peg it is compiling, and it does not take the
|
|
@@ -1227,6 +1228,27 @@ def _permissions_section(source: Path) -> "list | None":
|
|
|
1227
1228
|
raise ManifestValidationError(f"{config_path}: {refused}") from None
|
|
1228
1229
|
|
|
1229
1230
|
|
|
1231
|
+
def _check_permission_calls(calls: list, source: Path) -> None:
|
|
1232
|
+
"""Each ``workpeg.request_permission`` / ``permission_status`` call with
|
|
1233
|
+
a literal name, checked against the Peg's ``permissions`` (contract
|
|
1234
|
+
D.6), so an author learns at build time that a name is not declared. A
|
|
1235
|
+
name that is not a literal is checked at run time only, by the runtime,
|
|
1236
|
+
scaffold.js and the api. The name in the message passed its pattern in
|
|
1237
|
+
the parser, so echoing it is safe."""
|
|
1238
|
+
if not calls:
|
|
1239
|
+
return
|
|
1240
|
+
from workpeg.ui.search_manifest import ManifestValidationError
|
|
1241
|
+
|
|
1242
|
+
declared = {e["name"] for e in _permissions_section(source) or []}
|
|
1243
|
+
for call in calls:
|
|
1244
|
+
name, method = call["name"], call["method"]
|
|
1245
|
+
if name is None or name in declared:
|
|
1246
|
+
continue
|
|
1247
|
+
raise ManifestValidationError(
|
|
1248
|
+
f'{call["path"]}:{call["line"]}: workpeg.{method}("{name}"): '
|
|
1249
|
+
f'workpeg.json declares no permission named "{name}".')
|
|
1250
|
+
|
|
1251
|
+
|
|
1230
1252
|
def _actions_section(source: Path) -> "list | None":
|
|
1231
1253
|
"""The Peg's ``actions`` manifest section, from ``workpeg.json``.
|
|
1232
1254
|
|
|
@@ -178,6 +178,19 @@ _WORKPEG_SESSION_HELPERS = {
|
|
|
178
178
|
"first_business": (0, 0, "workpeg.first_business()"),
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
# workpeg.request_permission(name) and workpeg.permission_status(name): ask
|
|
182
|
+
# the person, over the peg, for a permission its manifest declares, or read
|
|
183
|
+
# what was decided (docs/permissions.md, contract D.6). Each compiles to one
|
|
184
|
+
# call into the runtime (Workpeg.wpRequestPermission / wpPermissionStatus),
|
|
185
|
+
# which checks the name again and hands it to scaffold.js. A literal name is
|
|
186
|
+
# checked here and against workpeg.json in build.py; the calls are recorded
|
|
187
|
+
# on ``parser.permission_calls`` for that. An all-tables permission
|
|
188
|
+
# ("table": "*") covers every table of the peg, so no call names a table.
|
|
189
|
+
_WORKPEG_PERMISSION_HELPERS = {
|
|
190
|
+
"request_permission": "workpeg.request_permission(name)",
|
|
191
|
+
"permission_status": "workpeg.permission_status(name)",
|
|
192
|
+
}
|
|
193
|
+
|
|
181
194
|
|
|
182
195
|
def _is_str_const(node: "ast.AST | None") -> bool:
|
|
183
196
|
"""True when *node* is a string literal (an ``ast.Constant`` holding a str)
|
|
@@ -1988,6 +2001,10 @@ class ASTParser:
|
|
|
1988
2001
|
|
|
1989
2002
|
def __init__(self) -> None:
|
|
1990
2003
|
self._components: dict[str, "ComponentIR | None"] = {}
|
|
2004
|
+
# Every workpeg.request_permission / permission_status call, for the
|
|
2005
|
+
# build to check its literal name against workpeg.json.
|
|
2006
|
+
# Kept across every module of the build (not reset per file).
|
|
2007
|
+
self.permission_calls: list[dict] = []
|
|
1991
2008
|
# `store.<field>`: a read is only checked once the whole program has
|
|
1992
2009
|
# been seen, since the field may be declared on the Router in another
|
|
1993
2010
|
# file or first assigned on a page parsed later. See `_check_store_reads`.
|
|
@@ -8644,6 +8661,41 @@ class ASTParser:
|
|
|
8644
8661
|
args[index] = self._parse_expr(kw.value, scope)
|
|
8645
8662
|
return args
|
|
8646
8663
|
|
|
8664
|
+
def _parse_workpeg_permission(self, node: ast.Call, scope: frozenset,
|
|
8665
|
+
method: str) -> Any:
|
|
8666
|
+
"""``workpeg.request_permission(name)`` and
|
|
8667
|
+
``workpeg.permission_status(name)``: exactly one positional name and
|
|
8668
|
+
no keyword at all. Both resolve to a word and never reject; the
|
|
8669
|
+
runtime and scaffold.js check the name again, so this is the
|
|
8670
|
+
author's early warning, not the door."""
|
|
8671
|
+
from workpeg.ui.permissions_manifest import PERMISSION_NAME_PATTERN
|
|
8672
|
+
|
|
8673
|
+
if len(node.args) != 1 or isinstance(node.args[0], ast.Starred) \
|
|
8674
|
+
or node.keywords:
|
|
8675
|
+
raise UnsupportedSyntaxError(
|
|
8676
|
+
f"workpeg.{method}(name) takes only the permission's name")
|
|
8677
|
+
|
|
8678
|
+
name_node = node.args[0]
|
|
8679
|
+
name = None
|
|
8680
|
+
if isinstance(name_node, ast.Constant):
|
|
8681
|
+
if not isinstance(name_node.value, str) or not re.fullmatch(
|
|
8682
|
+
PERMISSION_NAME_PATTERN, name_node.value):
|
|
8683
|
+
raise UnsupportedSyntaxError(
|
|
8684
|
+
f"workpeg.{method}() needs a permission name: 1 to 40 "
|
|
8685
|
+
"lower-case letters, digits or underscores, starting "
|
|
8686
|
+
"with a letter")
|
|
8687
|
+
name = name_node.value
|
|
8688
|
+
|
|
8689
|
+
path, line = self._location_of(node)
|
|
8690
|
+
record = {"method": method, "name": name, "path": path, "line": line}
|
|
8691
|
+
if record not in self.permission_calls:
|
|
8692
|
+
self.permission_calls.append(record)
|
|
8693
|
+
|
|
8694
|
+
return {
|
|
8695
|
+
"expr": "workpeg", "method": method, "protected": True,
|
|
8696
|
+
"args": [self._parse_expr(name_node, scope)],
|
|
8697
|
+
}
|
|
8698
|
+
|
|
8647
8699
|
def _parse_workpeg_call(self, node: ast.Call, scope: frozenset) -> Any:
|
|
8648
8700
|
"""Parse ``workpeg.get/post/put/patch/delete`` — namespaced calls to
|
|
8649
8701
|
Workpeg's own platform, the inverse of ``http.*``.
|
|
@@ -8653,6 +8705,8 @@ class ASTParser:
|
|
|
8653
8705
|
platform's API base at runtime.
|
|
8654
8706
|
"""
|
|
8655
8707
|
method = node.func.attr
|
|
8708
|
+
if method in _WORKPEG_PERMISSION_HELPERS:
|
|
8709
|
+
return self._parse_workpeg_permission(node, scope, method)
|
|
8656
8710
|
# Tables & Rows helpers (get_tables, add_row, …) take no URL — the
|
|
8657
8711
|
# business id is read from the page URL at runtime, and the runtime
|
|
8658
8712
|
# builds the endpoint path from the args.
|
|
@@ -9,10 +9,23 @@ business to allow, and why, in one sentence each.
|
|
|
9
9
|
"purpose": "Adds each answer to Responses seconds after someone submits it.",
|
|
10
10
|
"ask": "install",
|
|
11
11
|
"inbound": {"table": "responses"}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "all_tables",
|
|
15
|
+
"kind": "inbound",
|
|
16
|
+
"purpose": "Adds each answer to its form's own table as it is submitted.",
|
|
17
|
+
"ask": "runtime",
|
|
18
|
+
"inbound": {"table": "*"}
|
|
12
19
|
}
|
|
13
20
|
]
|
|
14
21
|
```
|
|
15
22
|
|
|
23
|
+
``"ask": "runtime"`` is never asked at install: the Peg's own code asks
|
|
24
|
+
with ``workpeg.request_permission(name)``. ``"table": "*"`` is an entry for
|
|
25
|
+
ALL of the Peg's own tables in the business, the ones it has now and the ones
|
|
26
|
+
it creates later, under one grant and one key. Any ``ask`` suits it, since it
|
|
27
|
+
never waits for a table. A Peg may declare one, beside its fixed entries.
|
|
28
|
+
|
|
16
29
|
The api validates the same section with the same rules, in the same order,
|
|
17
30
|
with the same words (``app/core/peg_permissions.py``), and never trusts this
|
|
18
31
|
build: the manifest is unsigned. The build refuses what the api would refuse
|
|
@@ -37,7 +50,8 @@ PERMISSION_NAME_PATTERN = r"^[a-z][a-z0-9_]{0,39}\Z"
|
|
|
37
50
|
PERMISSION_ALIAS_PATTERN = r"^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$"
|
|
38
51
|
PURPOSE_URL_PATTERN = r"(?i)(://|www\.|@|[a-z0-9-]+\.[a-z]{2,})"
|
|
39
52
|
REFUSED_CATEGORIES = ("Cc", "Cf", "Co", "Cs", "Zl", "Zp")
|
|
40
|
-
PERMISSION_ASK = ("install", "settings")
|
|
53
|
+
PERMISSION_ASK = ("install", "settings", "runtime")
|
|
54
|
+
PERMISSION_ALL_TABLES = "*"
|
|
41
55
|
|
|
42
56
|
MSG_NOT_A_LIST = '"permissions" must be a list of objects.'
|
|
43
57
|
MSG_TOO_MANY = ('"permissions" lists {count} entries; a peg may declare at '
|
|
@@ -64,12 +78,17 @@ MSG_PURPOSE_CONTROL = ('permissions[{index}].purpose holds an invisible or '
|
|
|
64
78
|
'control character (U+{code}).')
|
|
65
79
|
MSG_PURPOSE_URL = ('permissions[{index}].purpose must not hold a web '
|
|
66
80
|
'address, an email address or a domain name.')
|
|
67
|
-
MSG_BAD_ASK = 'permissions[{index}].ask must be "install"
|
|
81
|
+
MSG_BAD_ASK = ('permissions[{index}].ask must be "install", "settings" or '
|
|
82
|
+
'"runtime".')
|
|
68
83
|
MSG_BAD_INBOUND = ('permissions[{index}].inbound must be '
|
|
69
|
-
'{{"table": "<table alias>"}}.')
|
|
70
|
-
MSG_BAD_ALIAS = ('permissions[{index}].inbound.table must be a table alias
|
|
71
|
-
'1 to 64 letters, digits, dots, dashes or underscores, '
|
|
72
|
-
'starting with a letter or digit
|
|
84
|
+
'{{"table": "<table alias>"}} or {{"table": "*"}}.')
|
|
85
|
+
MSG_BAD_ALIAS = ('permissions[{index}].inbound.table must be a table alias '
|
|
86
|
+
'(1 to 64 letters, digits, dots, dashes or underscores, '
|
|
87
|
+
'starting with a letter or digit) or "*" for all of the '
|
|
88
|
+
'peg\'s own tables.')
|
|
89
|
+
MSG_SAME_ALL_TABLES = ('permissions[{index}] is a second inbound permission '
|
|
90
|
+
'for all of the peg\'s tables; a peg may declare '
|
|
91
|
+
'one.')
|
|
73
92
|
MSG_SAME_TABLE = ('permissions[{index}] asks for inbound on "{table}" again; '
|
|
74
93
|
'a peg may declare one inbound permission per table.')
|
|
75
94
|
|
|
@@ -119,6 +138,7 @@ def validate_permissions(value):
|
|
|
119
138
|
_fail(MSG_TOO_MANY, count=len(value), max=MAX_PERMISSIONS)
|
|
120
139
|
names = set()
|
|
121
140
|
tables = set()
|
|
141
|
+
all_tables = False
|
|
122
142
|
out = []
|
|
123
143
|
for index, entry in enumerate(value):
|
|
124
144
|
if not isinstance(entry, dict):
|
|
@@ -163,14 +183,21 @@ def validate_permissions(value):
|
|
|
163
183
|
if not isinstance(params, dict) or set(params) != {"table"}:
|
|
164
184
|
_fail(MSG_BAD_INBOUND, index=index)
|
|
165
185
|
table = params["table"]
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
if isinstance(table, str) and table == PERMISSION_ALL_TABLES:
|
|
187
|
+
# All of the peg's own tables, now and later, under one grant.
|
|
188
|
+
# It never waits for a table, so any ``ask`` suits it.
|
|
189
|
+
if all_tables:
|
|
190
|
+
_fail(MSG_SAME_ALL_TABLES, index=index)
|
|
191
|
+
all_tables = True
|
|
192
|
+
else:
|
|
193
|
+
# fullmatch, as the api does: the pattern's ``$`` alone would
|
|
194
|
+
# let a trailing newline through.
|
|
195
|
+
if not isinstance(table, str) \
|
|
196
|
+
or not re.fullmatch(PERMISSION_ALIAS_PATTERN, table):
|
|
197
|
+
_fail(MSG_BAD_ALIAS, index=index)
|
|
198
|
+
if table.lower() in tables:
|
|
199
|
+
_fail(MSG_SAME_TABLE, index=index, table=table)
|
|
200
|
+
tables.add(table.lower())
|
|
174
201
|
|
|
175
202
|
out.append({"name": name, "kind": kind, "purpose": purpose,
|
|
176
203
|
"ask": ask, kind: {"table": table}})
|