drscore 1.0.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.
Files changed (109) hide show
  1. drscore-1.0.0/LICENSE +201 -0
  2. drscore-1.0.0/PKG-INFO +328 -0
  3. drscore-1.0.0/README.md +284 -0
  4. drscore-1.0.0/THIRD_PARTY_LICENSES.md +95 -0
  5. drscore-1.0.0/drscore/__init__.py +0 -0
  6. drscore-1.0.0/drscore/__main__.py +5 -0
  7. drscore-1.0.0/drscore/admin/__init__.py +0 -0
  8. drscore-1.0.0/drscore/admin/metadata.py +444 -0
  9. drscore-1.0.0/drscore/admin/service.py +296 -0
  10. drscore-1.0.0/drscore/admin/templates/sqladmin/LICENSE.sqladmin +27 -0
  11. drscore-1.0.0/drscore/admin/templates/sqladmin/flash.html +20 -0
  12. drscore-1.0.0/drscore/admin/templates/sqladmin/layout.html +94 -0
  13. drscore-1.0.0/drscore/admin/translations/vi.po +574 -0
  14. drscore-1.0.0/drscore/admin/web.py +731 -0
  15. drscore-1.0.0/drscore/app.py +135 -0
  16. drscore-1.0.0/drscore/audit.py +76 -0
  17. drscore-1.0.0/drscore/auth/__init__.py +0 -0
  18. drscore-1.0.0/drscore/auth/passwords.py +30 -0
  19. drscore-1.0.0/drscore/auth/service.py +191 -0
  20. drscore-1.0.0/drscore/authz/__init__.py +0 -0
  21. drscore-1.0.0/drscore/authz/permissions.py +152 -0
  22. drscore-1.0.0/drscore/authz/rowfilter.py +93 -0
  23. drscore-1.0.0/drscore/bi/__init__.py +0 -0
  24. drscore-1.0.0/drscore/bi/dataset.py +161 -0
  25. drscore-1.0.0/drscore/bi/superset.py +120 -0
  26. drscore-1.0.0/drscore/cli.py +440 -0
  27. drscore-1.0.0/drscore/cli_reports.py +472 -0
  28. drscore-1.0.0/drscore/datasources/connectors.py +251 -0
  29. drscore-1.0.0/drscore/datasources/secrets.py +55 -0
  30. drscore-1.0.0/drscore/datasources/spec.py +65 -0
  31. drscore-1.0.0/drscore/db/__init__.py +3 -0
  32. drscore-1.0.0/drscore/db/engine.py +152 -0
  33. drscore-1.0.0/drscore/db/migrate.py +120 -0
  34. drscore-1.0.0/drscore/db/models.py +568 -0
  35. drscore-1.0.0/drscore/db/types.py +50 -0
  36. drscore-1.0.0/drscore/demo/seed.py +252 -0
  37. drscore-1.0.0/drscore/errors.py +70 -0
  38. drscore-1.0.0/drscore/examples/app.example.toml +67 -0
  39. drscore-1.0.0/drscore/examples/database.example.toml +31 -0
  40. drscore-1.0.0/drscore/export/writers.py +214 -0
  41. drscore-1.0.0/drscore/logsetup.py +54 -0
  42. drscore-1.0.0/drscore/migrations/__init__.py +0 -0
  43. drscore-1.0.0/drscore/migrations/env.py +21 -0
  44. drscore-1.0.0/drscore/migrations/script.py.mako +25 -0
  45. drscore-1.0.0/drscore/migrations/versions/0001_initial_schema.py +369 -0
  46. drscore-1.0.0/drscore/migrations/versions/0002_snapshot_history.py +58 -0
  47. drscore-1.0.0/drscore/migrations/versions/0003_oracle_datasource.py +26 -0
  48. drscore-1.0.0/drscore/migrations/versions/0004_report_views.py +42 -0
  49. drscore-1.0.0/drscore/migrations/versions/0005_decimal_order_param_active.py +53 -0
  50. drscore-1.0.0/drscore/migrations/versions/0006_datasource_connection.py +46 -0
  51. drscore-1.0.0/drscore/migrations/versions/0007_bi_dataset.py +32 -0
  52. drscore-1.0.0/drscore/migrations/versions/0008_must_change_password.py +30 -0
  53. drscore-1.0.0/drscore/render/design.py +195 -0
  54. drscore-1.0.0/drscore/render/grid.py +84 -0
  55. drscore-1.0.0/drscore/render/html.py +53 -0
  56. drscore-1.0.0/drscore/render/html_filters.py +56 -0
  57. drscore-1.0.0/drscore/reports/cache.py +169 -0
  58. drscore-1.0.0/drscore/reports/executor.py +170 -0
  59. drscore-1.0.0/drscore/reports/normalize.py +110 -0
  60. drscore-1.0.0/drscore/reports/params.py +421 -0
  61. drscore-1.0.0/drscore/reports/service.py +307 -0
  62. drscore-1.0.0/drscore/reports/validate.py +153 -0
  63. drscore-1.0.0/drscore/settings.py +304 -0
  64. drscore-1.0.0/drscore/startup.py +111 -0
  65. drscore-1.0.0/drscore/web/deps.py +81 -0
  66. drscore-1.0.0/drscore/web/i18n/en.json +111 -0
  67. drscore-1.0.0/drscore/web/i18n/vi.json +111 -0
  68. drscore-1.0.0/drscore/web/i18n.py +34 -0
  69. drscore-1.0.0/drscore/web/routes/api.py +88 -0
  70. drscore-1.0.0/drscore/web/routes/auth.py +83 -0
  71. drscore-1.0.0/drscore/web/routes/pages.py +159 -0
  72. drscore-1.0.0/drscore/web/schemas.py +155 -0
  73. drscore-1.0.0/drscore/web/static/css/drs.css +13 -0
  74. drscore-1.0.0/drscore/web/static/js/home.js +21 -0
  75. drscore-1.0.0/drscore/web/static/js/report.js +376 -0
  76. drscore-1.0.0/drscore/web/static/vendor/echarts/LICENSE +222 -0
  77. drscore-1.0.0/drscore/web/static/vendor/echarts/NOTICE +5 -0
  78. drscore-1.0.0/drscore/web/static/vendor/echarts/echarts.min.js +45 -0
  79. drscore-1.0.0/drscore/web/static/vendor/htmx/LICENSE +13 -0
  80. drscore-1.0.0/drscore/web/static/vendor/htmx/htmx.min.js +1 -0
  81. drscore-1.0.0/drscore/web/static/vendor/superset-embedded-sdk/LICENSE +13 -0
  82. drscore-1.0.0/drscore/web/static/vendor/superset-embedded-sdk/embedded-sdk.min.js +2 -0
  83. drscore-1.0.0/drscore/web/static/vendor/tabler/LICENSE +22 -0
  84. drscore-1.0.0/drscore/web/static/vendor/tabler/tabler.min.css +8 -0
  85. drscore-1.0.0/drscore/web/static/vendor/tabler/tabler.min.js +8 -0
  86. drscore-1.0.0/drscore/web/static/vendor/tabler-icons/LICENSE +21 -0
  87. drscore-1.0.0/drscore/web/static/vendor/tabler-icons/fonts/tabler-icons.ttf +0 -0
  88. drscore-1.0.0/drscore/web/static/vendor/tabler-icons/fonts/tabler-icons.woff +0 -0
  89. drscore-1.0.0/drscore/web/static/vendor/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  90. drscore-1.0.0/drscore/web/static/vendor/tabler-icons/tabler-icons.min.css +4 -0
  91. drscore-1.0.0/drscore/web/static/vendor/tabulator/LICENSE +21 -0
  92. drscore-1.0.0/drscore/web/static/vendor/tabulator/tabulator.min.js +3 -0
  93. drscore-1.0.0/drscore/web/static/vendor/tabulator/tabulator_bootstrap5.min.css +2 -0
  94. drscore-1.0.0/drscore/web/templates/_param_options.html +8 -0
  95. drscore-1.0.0/drscore/web/templates/account.html +57 -0
  96. drscore-1.0.0/drscore/web/templates/base.html +124 -0
  97. drscore-1.0.0/drscore/web/templates/error.html +31 -0
  98. drscore-1.0.0/drscore/web/templates/home.html +55 -0
  99. drscore-1.0.0/drscore/web/templates/login.html +56 -0
  100. drscore-1.0.0/drscore/web/templates/report.html +161 -0
  101. drscore-1.0.0/drscore/web/templating.py +53 -0
  102. drscore-1.0.0/drscore/web/views.py +372 -0
  103. drscore-1.0.0/drscore.egg-info/PKG-INFO +328 -0
  104. drscore-1.0.0/drscore.egg-info/SOURCES.txt +107 -0
  105. drscore-1.0.0/drscore.egg-info/dependency_links.txt +1 -0
  106. drscore-1.0.0/drscore.egg-info/requires.txt +25 -0
  107. drscore-1.0.0/drscore.egg-info/top_level.txt +1 -0
  108. drscore-1.0.0/pyproject.toml +57 -0
  109. drscore-1.0.0/setup.cfg +4 -0
drscore-1.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
drscore-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,328 @@
1
+ Metadata-Version: 2.4
2
+ Name: drscore
3
+ Version: 1.0.0
4
+ Summary: DRS - Dynamic Report System: reports written in SQL, shown as grids, HTML designs and BI dashboards
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Source, https://github.com/tanthanhkaka01/drscore
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ License-File: THIRD_PARTY_LICENSES.md
11
+ License-File: drscore/admin/templates/sqladmin/LICENSE.sqladmin
12
+ License-File: drscore/web/static/vendor/echarts/LICENSE
13
+ License-File: drscore/web/static/vendor/htmx/LICENSE
14
+ License-File: drscore/web/static/vendor/superset-embedded-sdk/LICENSE
15
+ License-File: drscore/web/static/vendor/tabler-icons/LICENSE
16
+ License-File: drscore/web/static/vendor/tabler/LICENSE
17
+ License-File: drscore/web/static/vendor/tabulator/LICENSE
18
+ License-File: drscore/web/static/vendor/echarts/NOTICE
19
+ Requires-Dist: fastapi==0.142.2
20
+ Requires-Dist: pydantic==2.13.5
21
+ Requires-Dist: uvicorn==0.54.0
22
+ Requires-Dist: jinja2==3.1.6
23
+ Requires-Dist: python-multipart==0.0.32
24
+ Requires-Dist: sqlalchemy==2.1.3
25
+ Requires-Dist: alembic==1.20.0
26
+ Requires-Dist: psycopg[binary]==3.3.6
27
+ Requires-Dist: pyodbc==5.3.0
28
+ Requires-Dist: pymssql==2.4.3
29
+ Requires-Dist: oracledb==26.0.1
30
+ Requires-Dist: argon2-cffi==25.1.0
31
+ Requires-Dist: cryptography==50.0.2
32
+ Requires-Dist: authlib==1.8.0
33
+ Requires-Dist: httpx==0.28.1
34
+ Requires-Dist: xlsxwriter==3.2.9
35
+ Requires-Dist: sqladmin==0.32.0
36
+ Requires-Dist: wtforms==3.2.2
37
+ Requires-Dist: babel==2.18.0
38
+ Requires-Dist: itsdangerous==2.2.0
39
+ Requires-Dist: greenlet==3.5.6
40
+ Provides-Extra: test
41
+ Requires-Dist: pytest==9.1.1; extra == "test"
42
+ Requires-Dist: openpyxl==3.1.5; extra == "test"
43
+ Dynamic: license-file
44
+
45
+ # DRS - Dynamic Report System
46
+
47
+ A web portal for reports where a report is **data, not code**: rows in the DRS database say which
48
+ source to read, which SQL or procedure to run, which parameters to ask for, how to show the result
49
+ and who may see it.
50
+
51
+ Status: **milestone 8 (admin pages, metadata export / import, audit log)** done, on top of
52
+ milestone 6 (BI with Superset, without row-level security in the guest token) and milestone 5 (design registry, HTML, report views as tabs) - the web portal on Tabler (sign-in, menu
53
+ by report group, report page with parameter form, Tabulator grid, XLSX / CSV / TXT export, account
54
+ page, Vietnamese / English), HTML reports rendered from design files, BI reports in link mode and
55
+ the "no design, no view" rule, on top of the report engine (SQL Server 2008 R2+, Oracle,
56
+ PostgreSQL, SQLite sources; JSON cache with history and lock), permissions and the dual-engine DRS
57
+ database.
58
+
59
+ ## Install
60
+
61
+ ```bash
62
+ pip install drscore
63
+ python -m drscore init # config/, designs/, runtime/ in this folder (or DRS_HOME)
64
+ python -m drscore serve # http://127.0.0.1:8080 - admin / admin, changed at the first sign-in
65
+ ```
66
+
67
+ The database is SQLite under `runtime/` until `config/database.toml` says otherwise. From a copy of
68
+ this repository instead: `pip install .`, then copy `config/*.example.toml` to `config/*.toml`.
69
+ Running on a server, as a service or in containers: `docs/deployment.md`.
70
+
71
+ ## Quick look with the demo
72
+
73
+ ```bash
74
+ python -m drscore db upgrade
75
+ python -m drscore seed-demo # prints the demo passwords once
76
+ python -m drscore serve # http://127.0.0.1:8080, sign in as hr_aaa, hr_all, viewer or admin
77
+ ```
78
+
79
+ Or from the command line:
80
+
81
+ ```bash
82
+ python -m drscore report run --code EMP_LIST --as-user hr_aaa
83
+ python -m drscore grant show --user hr_all
84
+ ```
85
+
86
+ ## The portal
87
+
88
+ | Page | Address |
89
+ | --- | --- |
90
+ | Sign in | `/login` |
91
+ | Home: the user's report groups and reports, with search | `/` |
92
+ | A report: parameters, Run, grid, Refresh (with `can_refresh`), XLSX / CSV / TXT (with `can_export`) | `/reports/{code}` |
93
+ | Own account: change password, language | `/account` |
94
+ | Administration (administrators only): groups, reports, parameters, columns, row filters, datasources, users, attributes, roles, grants, logs - with Test run, Test connection, Unlock | `/admin/` |
95
+
96
+ Exports are made on the server from the snapshot on screen, with the same permission check and row
97
+ filter, and contain all rows the user may see (not only the filtered page).
98
+
99
+ JSON API: `GET /api/me`, `GET /api/menu`, `GET /api/reports/{code}`, `POST /api/reports/{code}/run`,
100
+ `GET /api/reports/{code}/export?format=xlsx|csv|txt&snapshot_id=`, `GET /healthz`. A state-changing
101
+ request carries the session's CSRF token in `X-CSRF-Token`.
102
+
103
+ ## How the report cache works
104
+
105
+ - One table, `drs_report_snapshot`, holds the cached result (JSON) of every report.
106
+ - Each time someone opens a report, its retention (`drs_report.cache_ttl_seconds`) is checked.
107
+ Still valid: the cached result is shown. Expired: the old snapshot is moved to
108
+ `drs_report_snapshot_history` and the data is read again from the source.
109
+ - Reading again happens under a lock per (report, parameters): when several people open the same
110
+ report at once the source runs once and everyone gets the same result.
111
+ - Nothing is deleted: `drs_report_snapshot_history` keeps every old snapshot, for every report.
112
+ `cache purge` moves all expired snapshots there at once (for reports nobody opens); `cache clear
113
+ --report CODE` moves all snapshots of one report.
114
+
115
+ ## Report views: Grid, Layout (HTML), Dashboard (BI)
116
+
117
+ Every report opens with tabs:
118
+
119
+ | Tab | Shown when | What it shows |
120
+ | --- | --- | --- |
121
+ | Grid | the report has a query and `grid_enabled = true` (the default) | the rows, sort / filter / pages, XLSX / CSV / TXT export |
122
+ | Layout | `html_design_uri` is set (or `report_type = 'HTML'`) | the HTML design file, e.g. `file:html/att_summary.html` |
123
+ | Dashboard | `bi_design_uri` is set (or `report_type = 'BI'`) | a BI dashboard: `superset:<embedded uuid>` (embedded, guest token from DRS) or an `http(s)://` link |
124
+
125
+ `report_type` (GRID / HTML / BI, default GRID) is the tab the page opens on. All tabs show the same
126
+ data (one run, one snapshot); permissions and the row filter are the same on every tab.
127
+
128
+ A new report needs only its group, datasource and query: it appears in the menu at once and opens
129
+ on its grid. Designs come later, one `UPDATE` each, no restart:
130
+
131
+ ```sql
132
+ UPDATE drs_report SET html_design_uri = 'file:html/att_summary.html' WHERE report_code = 'ATT_SUMMARY';
133
+ UPDATE drs_report SET bi_design_uri = 'https://bi.company.local/superset/dashboard/7/' WHERE report_code = 'HR_DASHBOARD';
134
+ ```
135
+
136
+ A tab whose design is missing shows "This report has no design yet" (`DESIGN_NOT_SET`); the other
137
+ tabs work. `python -m drscore report validate` lists the state of every design.
138
+
139
+ Print / PDF: the Layout tab and the Grid tab have a "Print / Save PDF" button that opens the
140
+ browser's print dialog (choose "Save as PDF"); the Grid prints every row the user may see. A
141
+ Superset dashboard is saved as PDF with Superset's own "Download" menu.
142
+
143
+ ## BI with Apache Superset
144
+
145
+ A BI report with `bi_dataset_table` feeds a table (`drs_bi.<name>` on PostgreSQL; table `<name>` of
146
+ the datasets file `runtime/bi/datasets.sqlite3` on SQLite) from its
147
+ result, following its retention; a Superset dashboard designed on that table is shown in the
148
+ Dashboard tab, embedded with a guest token issued by DRS (the user needs no Superset account).
149
+ Setup: `docker/compose.yml` and `docs/superset-setup.md`. Row-level security in the guest token is
150
+ not built yet: a report with row-filter rules cannot be embedded.
151
+
152
+ ## Administration
153
+
154
+ Everything can be done without SQL on the admin pages (`/admin/`, administrators only, see
155
+ `docs/admin-guide.md`): every save is validated and written to the audit log. Reports designed on
156
+ SQLite move to PostgreSQL with `metadata export` / `metadata import`.
157
+
158
+ ## Report sources
159
+
160
+ | `db_type` | Versions | Driver (`drs_datasource.driver`) | Notes |
161
+ | --- | --- | --- | --- |
162
+ | `mssql` | SQL Server 2008 R2 and later | empty = pyodbc + ODBC Driver 18; an ODBC driver name; `pymssql` | 2008 R2: use `pymssql`, or set `{"Encrypt": "no"}` in `options_json`. pyodbc needs the Microsoft ODBC driver (and unixODBC on Linux). |
163
+ | `oracle` | 12.1 and later (thin); 11.2 with `thick` | empty / `thin`; `thick` | `--database` is the service name; option `sid` to connect by SID; option `lib_dir` = Instant Client folder for thick mode. |
164
+ | `postgresql` | 10 and later (tested with 16) | - | Runs every report in a read-only transaction. |
165
+ | `sqlite` | - | - | `--database` is the file path; opened read-only. Used by the demo. |
166
+
167
+ Every connection setting is a column of `drs_datasource`, as a DBA tool such as Navicat or
168
+ DBeaver keeps it:
169
+
170
+ | Setting | Column | `datasource add` option |
171
+ | --- | --- | --- |
172
+ | Description | `description` | `--description` |
173
+ | Server, port | `host`, `port` | `--host`, `--port` |
174
+ | SQL Server named instance | `instance_name` | `--instance SQLEXPRESS` |
175
+ | Database (Oracle: service name, or SID) | `database_name`, `oracle_connect_by` | `--database`, `--sid` |
176
+ | Default schema (PostgreSQL, Oracle) | `default_schema` | `--schema` |
177
+ | Authentication | `auth_method`: password / windows / none | `--auth` |
178
+ | User, password | `username`, `secret_ref` (encrypted, or `env:VARIABLE`) | `--user`, hidden prompt or `--password-env` |
179
+ | SSL / encryption | `ssl_mode`: disable / prefer / require / verify; `trust_server_certificate` | `--ssl-mode`, `--trust-server-certificate` |
180
+ | Connect timeout | `connect_timeout_seconds` (default 15) | `--connect-timeout` |
181
+ | Driver | `driver` | `--driver` |
182
+ | Any other driver option | `options_json` | `--option KEY=VALUE` |
183
+
184
+ The password is asked at a hidden prompt and stored encrypted; `DRS_SECRET_KEY` must be set
185
+ (`python -m drscore secret new-key` prints one).
186
+
187
+ ```bash
188
+ python -m drscore datasource add HRMS_PROD --type mssql --host 10.0.0.8 --database HRMS --user drs_ro \
189
+ --description "HRMS production, read-only login"
190
+ python -m drscore datasource add HRMS_OLD --type mssql --host 10.0.0.5 --instance SQL2008 --database HR \
191
+ --user drs_ro --ssl-mode disable --driver "ODBC Driver 17 for SQL Server"
192
+ python -m drscore datasource add ERP --type oracle --host 10.0.0.9 --database ORCLPDB1 --schema HR --user drs_ro
193
+ python -m drscore datasource add DWH --type postgresql --host 10.0.0.7 --database dwh --schema report \
194
+ --user drs_ro --ssl-mode require
195
+ python -m drscore datasource show HRMS_PROD # every setting, never the password
196
+ python -m drscore datasource test HRMS_PROD # connect and run a trivial query
197
+ python -m drscore datasource set-password HRMS_PROD # new password, encrypted
198
+ ```
199
+
200
+ The login of a source must be read-only there (SELECT, and EXECUTE on the report procedures).
201
+
202
+ Every component is free (requirement R02); see `THIRD_PARTY_LICENSES.md`.
203
+
204
+ ## Deploying on a server
205
+
206
+ `docs/deployment.md` is the full guide: PostgreSQL preparation, installation, configuration and
207
+ secrets, first start, Linux service (systemd) or Windows service (NSSM), HTTPS behind nginx / IIS,
208
+ source drivers, backup, upgrade, every configuration key, troubleshooting. Sample files are in
209
+ `deploy/`.
210
+
211
+ In short, with PostgreSQL:
212
+
213
+ ```bash
214
+ psql -U postgres -f deploy/postgres/create_drs_database.sql # login drs_app + database drs (edit the password)
215
+ python3 -m venv .venv && .venv/bin/pip install .
216
+ cp config/database.example.toml config/database.toml # active = "postgresql", [postgresql] host / user
217
+ cp config/app.example.toml config/app.toml
218
+ .venv/bin/python -m drscore secret new-key # once; keep the key safe
219
+ export DRS_DB_PASSWORD='...' DRS_SECRET_KEY='<the key>' # a service reads them from /etc/drs/drs.env
220
+ .venv/bin/python -m drscore serve # creates schema "drs", every table and the administrator, then serves
221
+ ```
222
+
223
+ `serve` connects, creates or migrates the DRS database (`[app] auto_migrate = true`), gives a
224
+ database without an administrator the default one (`admin` / `admin`, to be changed at the first
225
+ sign-in), checks the set-up (secret key, HTTPS cookie, administrator) and starts `[app] workers`
226
+ processes.
227
+
228
+ ## Requirements
229
+
230
+ - Python 3.11 or newer
231
+ - For production: PostgreSQL 14 or newer. For design and test nothing else is needed (SQLite).
232
+
233
+ ## First install
234
+
235
+ Windows (PowerShell):
236
+
237
+ ```powershell
238
+ cd D:\Projects\DRS
239
+ py -3 -m venv .venv
240
+ .\.venv\Scripts\Activate.ps1
241
+ pip install -e ".[test]"
242
+ Copy-Item config\database.example.toml config\database.toml
243
+ Copy-Item config\app.example.toml config\app.toml
244
+ python -m drscore db upgrade
245
+ python -m drscore db check
246
+ ```
247
+
248
+ Linux:
249
+
250
+ ```bash
251
+ cd /path/to/DRS
252
+ python3 -m venv .venv
253
+ . .venv/bin/activate
254
+ pip install -e ".[test]"
255
+ cp config/database.example.toml config/database.toml
256
+ cp config/app.example.toml config/app.toml
257
+ python -m drscore db upgrade
258
+ python -m drscore db check
259
+ ```
260
+
261
+ The real config files are git-ignored; only the `*.example.toml` files are committed. The config
262
+ folder can be moved with the environment variable `DRS_CONFIG_DIR`.
263
+
264
+ ## Choosing the DRS database engine
265
+
266
+ `config/database.toml` alone decides it:
267
+
268
+ ```toml
269
+ active = "sqlite" # or "postgresql"
270
+ ```
271
+
272
+ To switch: change `active` (or set the environment variable `DRS_DB_ACTIVE`), then run
273
+ `python -m drscore db upgrade`. No code changes.
274
+
275
+ For PostgreSQL, fill the `[postgresql]` section and put the password in the environment variable it
276
+ names (default `DRS_DB_PASSWORD`). The tables are created in the schema `schema` (default `drs`);
277
+ `db upgrade` creates the schema when it is missing.
278
+
279
+ ## Secrets
280
+
281
+ `python -m drscore secret new-key` prints a new encryption key. Put it in the environment variable named
282
+ by `app.secret_key_env` (default `DRS_SECRET_KEY`). It encrypts datasource passwords.
283
+
284
+ ## Tests
285
+
286
+ ```bash
287
+ python -m pytest # SQLite
288
+ DRS_TEST_PG_URL=postgresql://user:password@127.0.0.1:5432/dbname python -m pytest # SQLite and PostgreSQL
289
+ ```
290
+
291
+ With `DRS_TEST_PG_URL` set, every database test runs twice, once per engine. On PostgreSQL each
292
+ run uses a throw-away schema, dropped at the end. Use a test database, never a production one.
293
+
294
+ ## Commands available so far
295
+
296
+ | Command | Purpose |
297
+ | --- | --- |
298
+ | `python -m drscore db upgrade` | Create / migrate the DRS database on the active engine |
299
+ | `python -m drscore db check` | Active engine, migration version, every table reachable |
300
+ | `python -m drscore secret new-key` | Print a new encryption key |
301
+ | `python -m drscore serve [--host H] [--port P] [--workers N]` | Create / migrate the DRS database if needed, check the set-up, start the web server |
302
+ | `python -m drscore user add NAME [--display-name D] [--email E] [--admin] [--sso-subject S] [--no-password]` | Add a user; the password is asked at a hidden prompt |
303
+ | `python -m drscore user list / disable / enable / set-password / set-admin [--off]` | Users |
304
+ | `python -m drscore user attr set USER NAME VALUE... / remove USER NAME [VALUE] / list USER` | Row-filter attributes (`*` = every value) |
305
+ | `python -m drscore role add CODE [--name N] / list / member add CODE USER / member remove CODE USER` | Roles |
306
+ | `python -m drscore grant group CODE / grant report CODE --user U \| --role R [--export\|--no-export] [--refresh\|--no-refresh]` | Grants |
307
+ | `python -m drscore revoke group CODE / revoke report CODE --user U \| --role R` | Remove a grant |
308
+ | `python -m drscore grant show --user U` | What a user can see, and through which grant |
309
+
310
+ The first administrator is made by `serve`: a DRS database without an administrator gets user
311
+ `admin` with the password `admin`. That password opens only the account page, where it must be
312
+ replaced at the first sign-in. Another administrator:
313
+
314
+ ```bash
315
+ python -m drscore user add NAME --display-name "Administrator" --admin
316
+ ```
317
+
318
+ | Command | Purpose |
319
+ | --- | --- |
320
+ | `python -m drscore datasource add / list / test` | Report sources |
321
+ | `python -m drscore report run --code C --as-user U [--param k=v ...] [--format grid\|json] [--refresh] [--out F]` | Run a report exactly as that user gets it |
322
+ | `python -m drscore report validate [--code C]` | Check report definitions and design state |
323
+ | `python -m drscore cache purge [--report C]` | Move every expired snapshot to the history |
324
+ | `python -m drscore cache clear --report C` | Move every snapshot of one report to the history |
325
+ | `python -m drscore cache warm [--report C]` | Run reports with their default parameters ahead of the users |
326
+ | `python -m drscore metadata export --out F [--report C ...]` | Report definitions, datasources (no secrets), users (no passwords), roles and grants as one JSON file |
327
+ | `python -m drscore metadata import --in F [--dry-run]` | Create / update them in this DRS database, matched by code (e.g. SQLite to PostgreSQL) |
328
+ | `python -m drscore seed-demo [--force]` | Demo source, reports, role and users |