modora 0.1.0__py3-none-any.whl
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.
- modora/__init__.py +12 -0
- modora/addons/__init__.py +11 -0
- modora/addons/base/__init__.py +6 -0
- modora/addons/base/__manifest__.py +22 -0
- modora/addons/base/controllers/__init__.py +7 -0
- modora/addons/base/controllers/content.py +58 -0
- modora/addons/base/controllers/export.py +51 -0
- modora/addons/base/controllers/main.py +23 -0
- modora/addons/base/controllers/report.py +36 -0
- modora/addons/base/controllers/rest.py +41 -0
- modora/addons/base/controllers/rpc.py +18 -0
- modora/addons/base/controllers/session.py +93 -0
- modora/addons/base/data/base_records.py +44 -0
- modora/addons/base/data/crons.py +22 -0
- modora/addons/base/data/menus.py +44 -0
- modora/addons/base/data/sys.lang.csv +52 -0
- modora/addons/base/data/sys_config.py +19 -0
- modora/addons/base/demo/users.py +18 -0
- modora/addons/base/models/__init__.py +75 -0
- modora/addons/base/models/auth.py +317 -0
- modora/addons/base/models/org_company.py +71 -0
- modora/addons/base/models/sys_access.py +251 -0
- modora/addons/base/models/sys_attachment.py +124 -0
- modora/addons/base/models/sys_bus.py +132 -0
- modora/addons/base/models/sys_config.py +58 -0
- modora/addons/base/models/sys_cron.py +177 -0
- modora/addons/base/models/sys_external_id.py +24 -0
- modora/addons/base/models/sys_import.py +107 -0
- modora/addons/base/models/sys_job.py +250 -0
- modora/addons/base/models/sys_lang.py +75 -0
- modora/addons/base/models/sys_model.py +72 -0
- modora/addons/base/models/sys_module.py +101 -0
- modora/addons/base/models/sys_sequence.py +158 -0
- modora/addons/base/models/sys_session.py +172 -0
- modora/addons/base/models/sys_ui.py +198 -0
- modora/addons/base/models/sys_view.py +138 -0
- modora/addons/base/security/groups.py +29 -0
- modora/addons/base/security/sys.access.csv +38 -0
- modora/addons/base/static/icons/settings.svg +7 -0
- modora/addons/contact/__init__.py +6 -0
- modora/addons/contact/__manifest__.py +17 -0
- modora/addons/contact/data/menus.py +16 -0
- modora/addons/contact/demo/contacts.py +32 -0
- modora/addons/contact/models/__init__.py +4 -0
- modora/addons/contact/models/contact.py +207 -0
- modora/addons/contact/security/sys.access.csv +4 -0
- modora/addons/contact/static/icons/app.svg +7 -0
- modora/addons/locale/__init__.py +23 -0
- modora/addons/locale/__manifest__.py +19 -0
- modora/addons/locale/data/countries.py +47 -0
- modora/addons/locale/data/currencies.py +26 -0
- modora/addons/locale/data/defaults.py +11 -0
- modora/addons/locale/data/menus.py +15 -0
- modora/addons/locale/models/__init__.py +6 -0
- modora/addons/locale/models/country.py +72 -0
- modora/addons/locale/models/currency.py +209 -0
- modora/addons/locale/models/org_company.py +29 -0
- modora/addons/locale/security/sys.access.csv +9 -0
- modora/addons/mail/__init__.py +7 -0
- modora/addons/mail/__manifest__.py +13 -0
- modora/addons/mail/data/menus.py +16 -0
- modora/addons/mail/models/__init__.py +18 -0
- modora/addons/mail/models/activity.py +101 -0
- modora/addons/mail/models/bus.py +36 -0
- modora/addons/mail/models/follower.py +21 -0
- modora/addons/mail/models/message.py +201 -0
- modora/addons/mail/models/template.py +230 -0
- modora/addons/mail/models/thread.py +283 -0
- modora/addons/mail/security/sys.access.csv +8 -0
- modora/addons/mail/transport.py +77 -0
- modora/addons/web/__init__.py +6 -0
- modora/addons/web/__manifest__.py +12 -0
- modora/addons/web/controllers/__init__.py +4 -0
- modora/addons/web/controllers/main.py +157 -0
- modora/addons/web/static/dist/THIRD-PARTY-LICENSES.txt +1356 -0
- modora/addons/web/static/dist/assets/index-0i4GsfAI.css +1 -0
- modora/addons/web/static/dist/assets/index-0i4GsfAI.css.br +0 -0
- modora/addons/web/static/dist/assets/index-0i4GsfAI.css.gz +0 -0
- modora/addons/web/static/dist/assets/index-Bk_B461G.js +1 -0
- modora/addons/web/static/dist/assets/index-CdE-3s5j.js +53 -0
- modora/addons/web/static/dist/assets/index-CdE-3s5j.js.br +0 -0
- modora/addons/web/static/dist/assets/index-CdE-3s5j.js.gz +0 -0
- modora/addons/web/static/dist/assets/index-D0nCnqYz.js +1 -0
- modora/addons/web/static/dist/assets/index-D0nCnqYz.js.br +0 -0
- modora/addons/web/static/dist/assets/index-D0nCnqYz.js.gz +0 -0
- modora/addons/web/static/dist/assets/index-cgBTXj4B.js +1 -0
- modora/addons/web/static/dist/assets/index-cgBTXj4B.js.br +0 -0
- modora/addons/web/static/dist/assets/index-cgBTXj4B.js.gz +0 -0
- modora/addons/web/static/dist/assets/jsx-runtime-u17CrQMm.js +1 -0
- modora/addons/web/static/dist/assets/sdk-DCh0ASeY.js +1 -0
- modora/addons/web/static/dist/assets/sdk-DCh0ASeY.js.br +0 -0
- modora/addons/web/static/dist/assets/sdk-DCh0ASeY.js.gz +0 -0
- modora/addons/web/static/dist/index.html +30 -0
- modora/addons/web/static/dist/modora-web.js +1 -0
- modora/addons/web/static/dist/react-dom.js +1 -0
- modora/addons/web/static/dist/react-jsx-runtime.js +1 -0
- modora/addons/web/static/dist/react.js +1 -0
- modora/addons/web/static/dist/react.js.br +0 -0
- modora/addons/web/static/dist/react.js.gz +0 -0
- modora/bus.py +195 -0
- modora/cli/__init__.py +6 -0
- modora/cli/main.py +809 -0
- modora/cli/shell.py +65 -0
- modora/cli/webclient.py +208 -0
- modora/config.py +206 -0
- modora/data.py +152 -0
- modora/db/__init__.py +7 -0
- modora/db/cursor.py +338 -0
- modora/db/errors.py +149 -0
- modora/db/functions.py +233 -0
- modora/db/listen.py +120 -0
- modora/db/manage.py +221 -0
- modora/exceptions.py +30 -0
- modora/http/__init__.py +43 -0
- modora/http/content.py +220 -0
- modora/http/errors.py +132 -0
- modora/http/request.py +256 -0
- modora/http/responses.py +57 -0
- modora/http/rest.py +377 -0
- modora/http/routing.py +310 -0
- modora/http/rpc.py +106 -0
- modora/http/serve.py +55 -0
- modora/http/server.py +601 -0
- modora/http/websocket.py +169 -0
- modora/jobs.py +400 -0
- modora/modules/__init__.py +45 -0
- modora/modules/archive.py +218 -0
- modora/modules/data_loader.py +384 -0
- modora/modules/discovery.py +277 -0
- modora/modules/loader.py +593 -0
- modora/modules/manifest.py +200 -0
- modora/modules/migrations.py +69 -0
- modora/modules/registries.py +98 -0
- modora/orm/__init__.py +9 -0
- modora/orm/api.py +95 -0
- modora/orm/client.py +391 -0
- modora/orm/commands.py +87 -0
- modora/orm/data_exchange.py +400 -0
- modora/orm/domains.py +617 -0
- modora/orm/environment.py +285 -0
- modora/orm/fields.py +1122 -0
- modora/orm/json_read.py +234 -0
- modora/orm/models.py +1861 -0
- modora/orm/registry.py +555 -0
- modora/orm/schema.py +482 -0
- modora/py.typed +0 -0
- modora/report.py +792 -0
- modora/tests/__init__.py +102 -0
- modora/tests/case.py +137 -0
- modora/tests/fixtures.py +323 -0
- modora/tests/runner.py +135 -0
- modora/tests/smtp.py +139 -0
- modora/tools/__init__.py +6 -0
- modora/tools/_py_speedups.py +48 -0
- modora/tools/expr.py +66 -0
- modora/tools/filestore.py +135 -0
- modora/tools/formatting.py +141 -0
- modora/tools/html.py +131 -0
- modora/tools/i18n.py +373 -0
- modora/tools/json.py +119 -0
- modora/tools/passwords.py +49 -0
- modora/tools/speedups.py +47 -0
- modora/tools/sql.py +32 -0
- modora/tools/tabular.py +140 -0
- modora/ui.py +329 -0
- modora/views/__init__.py +18 -0
- modora/views/definitions.py +234 -0
- modora/views/expressions.py +344 -0
- modora/views/inheritance.py +242 -0
- modora/views/validation.py +274 -0
- modora-0.1.0.dist-info/METADATA +152 -0
- modora-0.1.0.dist-info/RECORD +176 -0
- modora-0.1.0.dist-info/WHEEL +4 -0
- modora-0.1.0.dist-info/entry_points.txt +9 -0
- modora-0.1.0.dist-info/licenses/LICENSE +201 -0
- modora-0.1.0.dist-info/licenses/NOTICE +16 -0
modora/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Modora: an open-source Python framework for modular business applications."""
|
|
3
|
+
|
|
4
|
+
__version__ = "0.1.0"
|
|
5
|
+
|
|
6
|
+
from modora import ui
|
|
7
|
+
from modora.orm import Command, api, fields, models
|
|
8
|
+
from modora.report import namespace as report
|
|
9
|
+
from modora.tools.i18n import _, _lt
|
|
10
|
+
from modora.views import view
|
|
11
|
+
|
|
12
|
+
__all__ = ["Command", "_", "__version__", "_lt", "api", "fields", "models", "report", "ui", "view"]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Namespace of Modora addons: ``modora.addons.<name>``.
|
|
3
|
+
|
|
4
|
+
Addons ship in their own distributions and contribute ``modora/addons/<name>/``; extra
|
|
5
|
+
folders from ``--addons-path`` and the folders holding addons of editable installs are added
|
|
6
|
+
to ``__path__`` by the module loader (PLAN P3.1).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pkgutil import extend_path
|
|
10
|
+
|
|
11
|
+
__path__ = extend_path(__path__, __name__)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
{
|
|
3
|
+
"name": "Base",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"summary": "Framework models: modules, models, users, groups, companies, access rules, "
|
|
6
|
+
"languages, sequences, parameters and attachments",
|
|
7
|
+
"category": "Hidden",
|
|
8
|
+
"author": "Bytesraw",
|
|
9
|
+
"website": "https://bytesraw.com",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"depends": [],
|
|
12
|
+
"data": [
|
|
13
|
+
"security/groups.py",
|
|
14
|
+
"data/sys.lang.csv",
|
|
15
|
+
"data/base_records.py",
|
|
16
|
+
"data/sys_config.py",
|
|
17
|
+
"data/crons.py",
|
|
18
|
+
"security/sys.access.csv",
|
|
19
|
+
"data/menus.py",
|
|
20
|
+
],
|
|
21
|
+
"demo": ["demo/users.py"],
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""HTTP controllers of ``base``: health check, database list, sessions, RPC, REST and file
|
|
3
|
+
content."""
|
|
4
|
+
|
|
5
|
+
from modora.addons.base.controllers import content, export, main, report, rest, rpc, session
|
|
6
|
+
|
|
7
|
+
__all__ = ["content", "export", "main", "report", "rest", "rpc", "session"]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""File content: attachment downloads, binary field downloads and uploads
|
|
3
|
+
(see :mod:`modora.http.content`)."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from starlette.datastructures import UploadFile
|
|
10
|
+
from starlette.responses import Response
|
|
11
|
+
|
|
12
|
+
from modora.http import BadRequest, Controller, request, route
|
|
13
|
+
from modora.http.content import attachment_response, field_response, upload_files
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _flag(value: str | None) -> bool:
|
|
17
|
+
return (value or "").lower() in ("1", "true", "yes")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Content(Controller):
|
|
21
|
+
@route("/web/content/{attachment_id:int}", type="http", auth="user", methods=["GET"])
|
|
22
|
+
def attachment(self, attachment_id: int, download: str | None = None) -> Response:
|
|
23
|
+
"""An attachment's content (``?download=1`` to save it as a file)."""
|
|
24
|
+
return attachment_response(request, attachment_id, _flag(download))
|
|
25
|
+
|
|
26
|
+
@route(
|
|
27
|
+
"/web/content/{model}/{record_id:int}/{field}", type="http", auth="user", methods=["GET"]
|
|
28
|
+
)
|
|
29
|
+
def field(
|
|
30
|
+
self,
|
|
31
|
+
model: str,
|
|
32
|
+
record_id: int,
|
|
33
|
+
field: str,
|
|
34
|
+
filename: str | None = None,
|
|
35
|
+
download: str | None = None,
|
|
36
|
+
) -> Response:
|
|
37
|
+
"""The content of a record's binary field."""
|
|
38
|
+
return field_response(request, model, record_id, field, filename, _flag(download))
|
|
39
|
+
|
|
40
|
+
@route("/web/upload", type="http", auth="user", methods=["POST"])
|
|
41
|
+
def upload(self) -> list[dict[str, Any]]:
|
|
42
|
+
"""Multipart upload: ``file`` fields (one or more), optional ``res_model`` and
|
|
43
|
+
``res_id`` to attach them to a record. Returns the attachments created."""
|
|
44
|
+
form = request.form
|
|
45
|
+
if form is None:
|
|
46
|
+
raise BadRequest("send the files as multipart/form-data")
|
|
47
|
+
files = [v for v in form.getlist("file") if isinstance(v, UploadFile)]
|
|
48
|
+
if not files:
|
|
49
|
+
raise BadRequest("no file uploaded (use the 'file' field)")
|
|
50
|
+
res_model = form.get("res_model")
|
|
51
|
+
raw_id = form.get("res_id")
|
|
52
|
+
try:
|
|
53
|
+
res_id = int(raw_id) if isinstance(raw_id, str) and raw_id else None
|
|
54
|
+
except ValueError:
|
|
55
|
+
raise BadRequest("res_id must be an integer") from None
|
|
56
|
+
return upload_files(
|
|
57
|
+
request, files, res_model if isinstance(res_model, str) else None, res_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""``POST /web/export/<csv|xlsx>``: download records as a file (PLAN P7.7)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
from starlette.responses import Response
|
|
10
|
+
|
|
11
|
+
from modora.http import BadRequest, Controller, request, route
|
|
12
|
+
from modora.tools.tabular import write_csv, write_xlsx
|
|
13
|
+
|
|
14
|
+
MAX_EXPORT = 100_000
|
|
15
|
+
TYPES = {
|
|
16
|
+
"csv": "text/csv; charset=utf-8",
|
|
17
|
+
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Export(Controller):
|
|
22
|
+
@route("/web/export/{format}", type="json", auth="user", methods=["POST"])
|
|
23
|
+
def export(
|
|
24
|
+
self,
|
|
25
|
+
format: str,
|
|
26
|
+
model: str,
|
|
27
|
+
fields: list[str],
|
|
28
|
+
headers: list[str] | None = None,
|
|
29
|
+
ids: list[int] | None = None,
|
|
30
|
+
domain: list[Any] | None = None,
|
|
31
|
+
) -> Response:
|
|
32
|
+
"""The records ``ids`` (or matching ``domain``) of ``model`` with the field paths
|
|
33
|
+
``fields``, as a CSV or XLSX file (``headers``: column titles)."""
|
|
34
|
+
if format not in TYPES:
|
|
35
|
+
raise BadRequest("format must be csv or xlsx")
|
|
36
|
+
if not fields or not all(isinstance(f, str) for f in fields):
|
|
37
|
+
raise BadRequest("fields must be a list of field paths")
|
|
38
|
+
env = request.env
|
|
39
|
+
if model not in env:
|
|
40
|
+
raise BadRequest(f"unknown model {model!r}")
|
|
41
|
+
records = env[model]
|
|
42
|
+
records = records.browse(ids) if ids else records.search(domain or [], limit=MAX_EXPORT)
|
|
43
|
+
rows = records.exists().export_data(fields)
|
|
44
|
+
titles = headers if headers and len(headers) == len(fields) else fields
|
|
45
|
+
content = write_csv(titles, rows) if format == "csv" else write_xlsx(titles, rows)
|
|
46
|
+
name = f"{records._description or model}.{format}"
|
|
47
|
+
return Response(
|
|
48
|
+
content,
|
|
49
|
+
media_type=TYPES[format],
|
|
50
|
+
headers={"Content-Disposition": f"attachment; filename*=UTF-8''{quote(name, safe='')}"},
|
|
51
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Routes that work without a database: health check and database list."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from modora import __version__
|
|
9
|
+
from modora.http import Controller, Forbidden, request, route
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Server(Controller):
|
|
13
|
+
@route("/web/health", type="json", auth="none", methods=["GET"])
|
|
14
|
+
def health(self) -> dict[str, Any]:
|
|
15
|
+
"""``{"status": "ok"}`` while the server answers (for load balancers)."""
|
|
16
|
+
return {"status": "ok", "version": __version__}
|
|
17
|
+
|
|
18
|
+
@route("/web/database/list", type="json", auth="none", methods=["GET", "POST"])
|
|
19
|
+
def database_list(self) -> list[str]:
|
|
20
|
+
"""The databases this host may use (``list_db`` must be enabled)."""
|
|
21
|
+
if not request.server.config.list_db:
|
|
22
|
+
raise Forbidden("Listing databases is disabled")
|
|
23
|
+
return request.server.allowed_databases(request.host)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""``GET /report/<pdf|html>/<report>/<ids>``: print records with a report (ARCHITECTURE §9.2)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from urllib.parse import quote
|
|
7
|
+
|
|
8
|
+
from starlette.responses import Response
|
|
9
|
+
|
|
10
|
+
from modora.http import BadRequest, Controller, request, route
|
|
11
|
+
|
|
12
|
+
#: Report HTML only needs its inline styles and embedded images.
|
|
13
|
+
HTML_POLICY = "default-src 'none'; img-src data:; style-src 'unsafe-inline'"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Reports(Controller):
|
|
17
|
+
@route("/report/{format}/{report}/{ids}", type="http", auth="user", methods=["GET"])
|
|
18
|
+
def report(self, format: str, report: str, ids: str, download: str | None = None) -> Response:
|
|
19
|
+
"""Render ``report`` (an external id) for the comma-separated record ``ids``, as the
|
|
20
|
+
user; ``?download=1`` saves it as a file."""
|
|
21
|
+
try:
|
|
22
|
+
record_ids = [int(part) for part in ids.split(",") if part]
|
|
23
|
+
except ValueError:
|
|
24
|
+
raise BadRequest("ids must be comma-separated record ids") from None
|
|
25
|
+
if not record_ids:
|
|
26
|
+
raise BadRequest("nothing to print")
|
|
27
|
+
action = request.env["sys.action"]._by_report(report)
|
|
28
|
+
content, filename, mimetype = action._render_report(record_ids, format)
|
|
29
|
+
disposition = "attachment" if (download or "").lower() in ("1", "true") else "inline"
|
|
30
|
+
headers = {
|
|
31
|
+
"Content-Disposition": f"{disposition}; filename*=UTF-8''{quote(filename, safe='')}",
|
|
32
|
+
"X-Content-Type-Options": "nosniff",
|
|
33
|
+
}
|
|
34
|
+
if format == "html":
|
|
35
|
+
headers["Content-Security-Policy"] = HTML_POLICY
|
|
36
|
+
return Response(content, media_type=mimetype, headers=headers)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""REST routes under ``/api/v1`` (see :mod:`modora.http.rest`)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from starlette.responses import Response
|
|
9
|
+
|
|
10
|
+
from modora.http import Controller, request, route
|
|
11
|
+
from modora.http import rest as api
|
|
12
|
+
from modora.http.responses import RawJSON
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Rest(Controller):
|
|
16
|
+
@route("/api/v1/openapi.json", type="json", auth="user", methods=["GET"])
|
|
17
|
+
def openapi(self) -> RawJSON:
|
|
18
|
+
return api.openapi_document(request.env)
|
|
19
|
+
|
|
20
|
+
@route("/api/v1/{model}", type="json", auth="user", methods=["GET"])
|
|
21
|
+
def search(self, model: str) -> Any:
|
|
22
|
+
return api.list_records(request.env, model, request.query)
|
|
23
|
+
|
|
24
|
+
@route("/api/v1/{model}", type="json", auth="user", methods=["POST"])
|
|
25
|
+
def create(self, model: str) -> Response:
|
|
26
|
+
rows, ids = api.create_records(request.env, model, request.json)
|
|
27
|
+
headers = {"Location": f"{api.PREFIX}/{model}/{ids[0]}"} if len(ids) == 1 else {}
|
|
28
|
+
return request.make_json_response(rows, status=201, headers=headers)
|
|
29
|
+
|
|
30
|
+
@route("/api/v1/{model}/{record_id:int}", type="json", auth="user", methods=["GET"])
|
|
31
|
+
def read(self, model: str, record_id: int) -> Any:
|
|
32
|
+
return api.read_record(request.env, model, record_id, request.query)
|
|
33
|
+
|
|
34
|
+
@route("/api/v1/{model}/{record_id:int}", type="json", auth="user", methods=["PATCH"])
|
|
35
|
+
def update(self, model: str, record_id: int) -> Any:
|
|
36
|
+
return api.update_record(request.env, model, record_id, request.json)
|
|
37
|
+
|
|
38
|
+
@route("/api/v1/{model}/{record_id:int}", type="json", auth="user", methods=["DELETE"])
|
|
39
|
+
def delete(self, model: str, record_id: int) -> Response:
|
|
40
|
+
api.delete_record(request.env, model, record_id)
|
|
41
|
+
return Response(status_code=204)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""``POST /rpc/<model>/<method>`` (see :mod:`modora.http.rpc`)."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from modora.http import Controller, request, route
|
|
9
|
+
from modora.http.rpc import call_method, parse_call
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Rpc(Controller):
|
|
13
|
+
@route("/rpc/{model}/{method}", type="json", auth="user", methods=["POST"])
|
|
14
|
+
def call(self, model: str, method: str) -> Any:
|
|
15
|
+
payload = parse_call(request.body)
|
|
16
|
+
return call_method(
|
|
17
|
+
request.env, model, method, payload.ids, payload.args, payload.kwargs, payload.context
|
|
18
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Login, logout and session info for browser clients.
|
|
3
|
+
|
|
4
|
+
``POST /web/session/login`` with ``{"login": …, "password": …}`` sets the ``modora_session``
|
|
5
|
+
cookie (and ``modora_db``, so later requests go to the same database) and returns the session
|
|
6
|
+
info, including the ``csrf_token`` that cookie-authenticated requests send back in the
|
|
7
|
+
``X-CSRF-Token`` header.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
import msgspec
|
|
15
|
+
|
|
16
|
+
from modora import __version__
|
|
17
|
+
from modora.addons.base.models.sys_session import SESSION_LIFETIME, csrf_token
|
|
18
|
+
from modora.exceptions import AccessError
|
|
19
|
+
from modora.http import BadRequest, Controller, Unauthorized, request, route
|
|
20
|
+
from modora.http.request import DATABASE_COOKIE, SESSION_COOKIE, Session
|
|
21
|
+
from modora.orm import SUPERUSER_ID, Environment
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class LoginPayload(msgspec.Struct):
|
|
25
|
+
login: str
|
|
26
|
+
password: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def session_info() -> dict[str, Any]:
|
|
30
|
+
"""What the client needs to know about the user and the database."""
|
|
31
|
+
env = request.env
|
|
32
|
+
user = env.user
|
|
33
|
+
companies = user.company_ids
|
|
34
|
+
current = env.company
|
|
35
|
+
return {
|
|
36
|
+
"uid": user.id,
|
|
37
|
+
"name": user.name,
|
|
38
|
+
"login": user.login,
|
|
39
|
+
"email": user.email or None,
|
|
40
|
+
"theme": user.theme or "system",
|
|
41
|
+
"lang": env.context.get("lang"),
|
|
42
|
+
"tz": env.context.get("tz"),
|
|
43
|
+
"db": request.db,
|
|
44
|
+
"is_admin": user.has_group("base.group_admin"),
|
|
45
|
+
"company_id": current.id if current else None,
|
|
46
|
+
"allowed_companies": [{"id": c.id, "name": c.name} for c in companies],
|
|
47
|
+
"csrf_token": request.csrf_token,
|
|
48
|
+
"server_version": __version__,
|
|
49
|
+
"registry_sequence": env.registry.sequence,
|
|
50
|
+
"modules": list(env.registry.modules),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class SessionController(Controller):
|
|
55
|
+
@route("/web/session/login", type="json", auth="public", methods=["POST"], csrf=False)
|
|
56
|
+
def login(self) -> dict[str, Any]:
|
|
57
|
+
try:
|
|
58
|
+
payload = msgspec.json.decode(request.body or b"{}", type=LoginPayload)
|
|
59
|
+
except msgspec.DecodeError as exc:
|
|
60
|
+
raise BadRequest(f"invalid login request: {exc}") from None
|
|
61
|
+
cr = request.cr
|
|
62
|
+
assert cr is not None
|
|
63
|
+
root = Environment(cr, SUPERUSER_ID, {}, su=True)
|
|
64
|
+
try:
|
|
65
|
+
uid = root["auth.user"]._authenticate(payload.login, payload.password)
|
|
66
|
+
except AccessError as exc:
|
|
67
|
+
raise Unauthorized(exc.message) from None
|
|
68
|
+
record, token = root["sys.session"]._open(
|
|
69
|
+
uid, request.remote_addr, request.headers.get("user-agent")
|
|
70
|
+
)
|
|
71
|
+
request.session = Session(record.id, uid, token, csrf_token(token), {})
|
|
72
|
+
user = root["auth.user"].browse(uid)
|
|
73
|
+
request.update_env(
|
|
74
|
+
user=uid,
|
|
75
|
+
context={"lang": user.lang or "en_US", "tz": user.tz or "UTC", "session_id": record.id},
|
|
76
|
+
)
|
|
77
|
+
max_age = int(SESSION_LIFETIME.total_seconds())
|
|
78
|
+
request.set_cookie(SESSION_COOKIE, token, max_age=max_age)
|
|
79
|
+
if request.db:
|
|
80
|
+
request.set_cookie(DATABASE_COOKIE, request.db, max_age=max_age)
|
|
81
|
+
return session_info()
|
|
82
|
+
|
|
83
|
+
@route("/web/session/logout", type="json", auth="user", methods=["POST"])
|
|
84
|
+
def logout(self) -> bool:
|
|
85
|
+
session = request.session
|
|
86
|
+
if session is not None:
|
|
87
|
+
request.env(su=True)["sys.session"].browse(session.id).unlink()
|
|
88
|
+
request.delete_cookie(SESSION_COOKIE)
|
|
89
|
+
return True
|
|
90
|
+
|
|
91
|
+
@route("/web/session/info", type="json", auth="user", methods=["GET", "POST"])
|
|
92
|
+
def info(self) -> dict[str, Any]:
|
|
93
|
+
return session_info()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""The default company, the root, admin and public users, and the active language.
|
|
3
|
+
|
|
4
|
+
Loaded on install only: users rename the company, change the admin user and switch languages.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from modora.data import Command, record, ref
|
|
8
|
+
|
|
9
|
+
NOUPDATE = True
|
|
10
|
+
|
|
11
|
+
RECORDS = [
|
|
12
|
+
record("lang_en_US", "sys.lang", active=True),
|
|
13
|
+
record("main_company", "org.company", name="My Company"),
|
|
14
|
+
# the root user is created by the loader before any data (it owns every record)
|
|
15
|
+
record(
|
|
16
|
+
"user_root",
|
|
17
|
+
"auth.user",
|
|
18
|
+
lang="en_US",
|
|
19
|
+
tz="UTC",
|
|
20
|
+
company_id=ref("main_company"),
|
|
21
|
+
company_ids=[Command.set([ref("main_company")])],
|
|
22
|
+
group_ids=[Command.set([ref("group_admin")])],
|
|
23
|
+
),
|
|
24
|
+
record(
|
|
25
|
+
"user_admin",
|
|
26
|
+
"auth.user",
|
|
27
|
+
name="Administrator",
|
|
28
|
+
login="admin",
|
|
29
|
+
company_id=ref("main_company"),
|
|
30
|
+
company_ids=[Command.set([ref("main_company")])],
|
|
31
|
+
group_ids=[Command.set([ref("group_admin")])],
|
|
32
|
+
),
|
|
33
|
+
# anonymous visitors of public pages act as this (inactive) user
|
|
34
|
+
record(
|
|
35
|
+
"user_public",
|
|
36
|
+
"auth.user",
|
|
37
|
+
name="Public user",
|
|
38
|
+
login="__public__",
|
|
39
|
+
active=False,
|
|
40
|
+
company_id=ref("main_company"),
|
|
41
|
+
company_ids=[Command.set([ref("main_company")])],
|
|
42
|
+
group_ids=[Command.set([ref("group_public")])],
|
|
43
|
+
),
|
|
44
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Scheduled maintenance of the framework tables (run by ``modora jobs`` workers)."""
|
|
3
|
+
|
|
4
|
+
from modora.data import record
|
|
5
|
+
|
|
6
|
+
NOUPDATE = True # administrators may change the schedules
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _cron(xml_id: str, name: str, model: str, method: str, number: int, kind: str):
|
|
10
|
+
return record(xml_id, "sys.cron", name=name, model=model, method=method,
|
|
11
|
+
interval_number=number, interval_type=kind) # fmt: skip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
RECORDS = [
|
|
15
|
+
_cron("cron_bus_gc", "Delete old bus messages", "sys.bus", "_gc", 1, "hours"),
|
|
16
|
+
_cron("cron_session_gc", "Delete expired sessions", "sys.session", "_gc", 1, "days"),
|
|
17
|
+
_cron("cron_job_gc", "Delete finished jobs", "sys.job", "_gc", 1, "days"),
|
|
18
|
+
_cron("cron_attachment_gc", "Delete unreferenced files", "sys.attachment",
|
|
19
|
+
"_gc_file_store", 1, "days"),
|
|
20
|
+
_cron("cron_transient_vacuum", "Delete old wizard records", "sys.model",
|
|
21
|
+
"_vacuum_transients", 1, "hours"),
|
|
22
|
+
] # fmt: skip
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""The Settings app: actions and menus of the base models (administrators only)."""
|
|
3
|
+
|
|
4
|
+
from modora.data import action, menu
|
|
5
|
+
|
|
6
|
+
ADMIN = ["base.group_admin"]
|
|
7
|
+
|
|
8
|
+
RECORDS = [
|
|
9
|
+
action("action_users", "Users", "auth.user", path="users"),
|
|
10
|
+
action("action_groups", "Groups", "auth.group", path="groups"),
|
|
11
|
+
action("action_companies", "Companies", "org.company", path="companies"),
|
|
12
|
+
action("action_modules", "Modules", "sys.module", views=("kanban", "list", "form"),
|
|
13
|
+
context={"search_defaults": ["installed"]}, path="modules"),
|
|
14
|
+
action("action_config", "System parameters", "sys.config", path="system-parameters"),
|
|
15
|
+
action("action_sequences", "Sequences", "sys.sequence", path="sequences"),
|
|
16
|
+
action("action_languages", "Languages", "sys.lang", path="languages"),
|
|
17
|
+
action("action_views", "Views", "sys.view", path="views"),
|
|
18
|
+
action("action_menus", "Menus", "sys.menu", path="menus"),
|
|
19
|
+
action("action_actions", "Actions", "sys.action", path="actions"),
|
|
20
|
+
action("action_jobs", "Jobs", "sys.job", path="jobs"),
|
|
21
|
+
action("action_crons", "Scheduled actions", "sys.cron", path="scheduled-actions"),
|
|
22
|
+
menu("menu_settings", "Settings", sequence=900, groups=ADMIN, icon="base/icons/settings.svg"),
|
|
23
|
+
menu("menu_users_companies", "Users & Companies", parent="menu_settings", sequence=10),
|
|
24
|
+
menu("menu_users", "Users", parent="menu_users_companies", action="action_users", sequence=10),
|
|
25
|
+
menu("menu_groups", "Groups", parent="menu_users_companies", action="action_groups",
|
|
26
|
+
sequence=20),
|
|
27
|
+
menu("menu_companies", "Companies", parent="menu_users_companies",
|
|
28
|
+
action="action_companies", sequence=30),
|
|
29
|
+
menu("menu_modules", "Modules", parent="menu_settings", action="action_modules", sequence=20),
|
|
30
|
+
menu("menu_technical", "Technical", parent="menu_settings", sequence=90),
|
|
31
|
+
menu("menu_config", "System parameters", parent="menu_technical", action="action_config",
|
|
32
|
+
sequence=10),
|
|
33
|
+
menu("menu_sequences", "Sequences", parent="menu_technical", action="action_sequences",
|
|
34
|
+
sequence=20),
|
|
35
|
+
menu("menu_languages", "Languages", parent="menu_technical", action="action_languages",
|
|
36
|
+
sequence=30),
|
|
37
|
+
menu("menu_views", "Views", parent="menu_technical", action="action_views", sequence=40),
|
|
38
|
+
menu("menu_menus", "Menus", parent="menu_technical", action="action_menus", sequence=50),
|
|
39
|
+
menu("menu_actions", "Actions", parent="menu_technical", action="action_actions",
|
|
40
|
+
sequence=60),
|
|
41
|
+
menu("menu_jobs", "Jobs", parent="menu_technical", action="action_jobs", sequence=70),
|
|
42
|
+
menu("menu_crons", "Scheduled actions", parent="menu_technical", action="action_crons",
|
|
43
|
+
sequence=80),
|
|
44
|
+
] # fmt: skip
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
id,code,iso_code,name,native_name,direction,date_format,time_format,decimal_point,thousands_sep,week_start
|
|
2
|
+
lang_ar_SA,ar_SA,ar,Arabic (Saudi Arabia),العربية,rtl,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
3
|
+
lang_ar_EG,ar_EG,ar,Arabic (Egypt),العربية (مصر),rtl,%d/%m/%Y,%H:%M:%S,.,",",6
|
|
4
|
+
lang_bg_BG,bg_BG,bg,Bulgarian,български,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
5
|
+
lang_ca_ES,ca_ES,ca,Catalan,català,ltr,%d/%m/%Y,%H:%M:%S,",",.,1
|
|
6
|
+
lang_cs_CZ,cs_CZ,cs,Czech,čeština,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
7
|
+
lang_da_DK,da_DK,da,Danish,dansk,ltr,%d-%m-%Y,%H:%M:%S,",",.,1
|
|
8
|
+
lang_de_DE,de_DE,de,German,Deutsch,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
9
|
+
lang_de_CH,de_CH,de,German (Switzerland),Deutsch (Schweiz),ltr,%d.%m.%Y,%H:%M:%S,.,',1
|
|
10
|
+
lang_el_GR,el_GR,el,Greek,Ελληνικά,ltr,%d/%m/%Y,%H:%M:%S,",",.,1
|
|
11
|
+
lang_en_US,en_US,en,English (US),English (US),ltr,%m/%d/%Y,%H:%M:%S,.,",",7
|
|
12
|
+
lang_en_GB,en_GB,en,English (UK),English (UK),ltr,%d/%m/%Y,%H:%M:%S,.,",",1
|
|
13
|
+
lang_en_IN,en_IN,en,English (India),English (India),ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
14
|
+
lang_es_ES,es_ES,es,Spanish,español,ltr,%d/%m/%Y,%H:%M:%S,",",.,1
|
|
15
|
+
lang_es_MX,es_MX,es,Spanish (Mexico),español (México),ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
16
|
+
lang_et_EE,et_EE,et,Estonian,eesti,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
17
|
+
lang_fa_IR,fa_IR,fa,Persian,فارسی,rtl,%Y/%m/%d,%H:%M:%S,.,",",6
|
|
18
|
+
lang_fi_FI,fi_FI,fi,Finnish,suomi,ltr,%d.%m.%Y,%H.%M.%S,",", ,1
|
|
19
|
+
lang_fr_FR,fr_FR,fr,French,français,ltr,%d/%m/%Y,%H:%M:%S,",", ,1
|
|
20
|
+
lang_fr_CA,fr_CA,fr,French (Canada),français (Canada),ltr,%Y-%m-%d,%H:%M:%S,",", ,7
|
|
21
|
+
lang_he_IL,he_IL,he,Hebrew,עברית,rtl,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
22
|
+
lang_hi_IN,hi_IN,hi,Hindi,हिन्दी,ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
23
|
+
lang_hr_HR,hr_HR,hr,Croatian,hrvatski,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
24
|
+
lang_hu_HU,hu_HU,hu,Hungarian,magyar,ltr,%Y.%m.%d,%H:%M:%S,",", ,1
|
|
25
|
+
lang_id_ID,id_ID,id,Indonesian,Bahasa Indonesia,ltr,%d/%m/%Y,%H:%M:%S,",",.,7
|
|
26
|
+
lang_it_IT,it_IT,it,Italian,italiano,ltr,%d/%m/%Y,%H:%M:%S,",",.,1
|
|
27
|
+
lang_ja_JP,ja_JP,ja,Japanese,日本語,ltr,%Y/%m/%d,%H:%M:%S,.,",",7
|
|
28
|
+
lang_ko_KR,ko_KR,ko,Korean,한국어,ltr,%Y.%m.%d,%H:%M:%S,.,",",7
|
|
29
|
+
lang_lt_LT,lt_LT,lt,Lithuanian,lietuvių,ltr,%Y-%m-%d,%H:%M:%S,",", ,1
|
|
30
|
+
lang_lv_LV,lv_LV,lv,Latvian,latviešu,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
31
|
+
lang_ml_IN,ml_IN,ml,Malayalam,മലയാളം,ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
32
|
+
lang_ms_MY,ms_MY,ms,Malay,Bahasa Melayu,ltr,%d/%m/%Y,%H:%M:%S,.,",",1
|
|
33
|
+
lang_nb_NO,nb_NO,nb,Norwegian Bokmål,norsk bokmål,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
34
|
+
lang_nl_NL,nl_NL,nl,Dutch,Nederlands,ltr,%d-%m-%Y,%H:%M:%S,",",.,1
|
|
35
|
+
lang_pl_PL,pl_PL,pl,Polish,polski,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
36
|
+
lang_pt_PT,pt_PT,pt,Portuguese,português,ltr,%d/%m/%Y,%H:%M:%S,",", ,1
|
|
37
|
+
lang_pt_BR,pt_BR,pt,Portuguese (Brazil),português (Brasil),ltr,%d/%m/%Y,%H:%M:%S,",",.,7
|
|
38
|
+
lang_ro_RO,ro_RO,ro,Romanian,română,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
39
|
+
lang_ru_RU,ru_RU,ru,Russian,русский,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
40
|
+
lang_sk_SK,sk_SK,sk,Slovak,slovenčina,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
41
|
+
lang_sl_SI,sl_SI,sl,Slovenian,slovenščina,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
42
|
+
lang_sr_RS,sr_RS,sr,Serbian,српски,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
43
|
+
lang_sv_SE,sv_SE,sv,Swedish,svenska,ltr,%Y-%m-%d,%H:%M:%S,",", ,1
|
|
44
|
+
lang_sw_KE,sw_KE,sw,Swahili,Kiswahili,ltr,%d/%m/%Y,%H:%M:%S,.,",",1
|
|
45
|
+
lang_ta_IN,ta_IN,ta,Tamil,தமிழ்,ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
46
|
+
lang_th_TH,th_TH,th,Thai,ไทย,ltr,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
47
|
+
lang_tr_TR,tr_TR,tr,Turkish,Türkçe,ltr,%d.%m.%Y,%H:%M:%S,",",.,1
|
|
48
|
+
lang_uk_UA,uk_UA,uk,Ukrainian,українська,ltr,%d.%m.%Y,%H:%M:%S,",", ,1
|
|
49
|
+
lang_ur_PK,ur_PK,ur,Urdu,اردو,rtl,%d/%m/%Y,%H:%M:%S,.,",",7
|
|
50
|
+
lang_vi_VN,vi_VN,vi,Vietnamese,Tiếng Việt,ltr,%d/%m/%Y,%H:%M:%S,",",.,1
|
|
51
|
+
lang_zh_CN,zh_CN,zh,Chinese (Simplified),简体中文,ltr,%Y-%m-%d,%H:%M:%S,.,",",1
|
|
52
|
+
lang_zh_TW,zh_TW,zh,Chinese (Traditional),繁體中文,ltr,%Y/%m/%d,%H:%M:%S,.,",",7
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""Parameters set when the database is created."""
|
|
3
|
+
|
|
4
|
+
import uuid
|
|
5
|
+
|
|
6
|
+
from modora.data import record
|
|
7
|
+
from modora.orm.fields import Datetime
|
|
8
|
+
|
|
9
|
+
NOUPDATE = True
|
|
10
|
+
|
|
11
|
+
RECORDS = [
|
|
12
|
+
record("config_database_uuid", "sys.config", key="database.uuid", value=str(uuid.uuid4())),
|
|
13
|
+
record(
|
|
14
|
+
"config_database_create_date",
|
|
15
|
+
"sys.config",
|
|
16
|
+
key="database.create_date",
|
|
17
|
+
value=Datetime.now().isoformat(sep=" "),
|
|
18
|
+
),
|
|
19
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
"""A demo user without administration rights (login ``demo``, password ``demo``)."""
|
|
3
|
+
|
|
4
|
+
from modora.data import Command, record, ref
|
|
5
|
+
|
|
6
|
+
RECORDS = [
|
|
7
|
+
record(
|
|
8
|
+
"user_demo",
|
|
9
|
+
"auth.user",
|
|
10
|
+
name="Demo User",
|
|
11
|
+
login="demo",
|
|
12
|
+
email="demo@example.com",
|
|
13
|
+
password="demo",
|
|
14
|
+
company_id=ref("main_company"),
|
|
15
|
+
company_ids=[Command.set([ref("main_company")])],
|
|
16
|
+
group_ids=[Command.set([ref("group_user")])],
|
|
17
|
+
),
|
|
18
|
+
]
|