pronto-helpdesk 1.0.2__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 (84) hide show
  1. pronto_helpdesk-1.0.2/LICENSE +201 -0
  2. pronto_helpdesk-1.0.2/PKG-INFO +166 -0
  3. pronto_helpdesk-1.0.2/README.md +139 -0
  4. pronto_helpdesk-1.0.2/accounts/__init__.py +0 -0
  5. pronto_helpdesk-1.0.2/accounts/admin.py +107 -0
  6. pronto_helpdesk-1.0.2/accounts/apps.py +6 -0
  7. pronto_helpdesk-1.0.2/accounts/migrations/0001_initial.py +113 -0
  8. pronto_helpdesk-1.0.2/accounts/migrations/0002_alter_user_options_alter_user_email_and_more.py +49 -0
  9. pronto_helpdesk-1.0.2/accounts/migrations/0003_user_matricola_degree_programme.py +53 -0
  10. pronto_helpdesk-1.0.2/accounts/migrations/0004_studentprofile.py +71 -0
  11. pronto_helpdesk-1.0.2/accounts/migrations/0005_copy_student_data.py +54 -0
  12. pronto_helpdesk-1.0.2/accounts/migrations/0006_remove_user_matricola_degree_programme.py +24 -0
  13. pronto_helpdesk-1.0.2/accounts/migrations/0007_require_user_names.py +55 -0
  14. pronto_helpdesk-1.0.2/accounts/migrations/0008_activate_accounts.py +55 -0
  15. pronto_helpdesk-1.0.2/accounts/migrations/__init__.py +0 -0
  16. pronto_helpdesk-1.0.2/accounts/models.py +141 -0
  17. pronto_helpdesk-1.0.2/accounts/serializers.py +171 -0
  18. pronto_helpdesk-1.0.2/accounts/urls.py +10 -0
  19. pronto_helpdesk-1.0.2/accounts/views.py +47 -0
  20. pronto_helpdesk-1.0.2/booking/__init__.py +0 -0
  21. pronto_helpdesk-1.0.2/booking/admin.py +28 -0
  22. pronto_helpdesk-1.0.2/booking/apps.py +6 -0
  23. pronto_helpdesk-1.0.2/booking/migrations/0001_initial.py +203 -0
  24. pronto_helpdesk-1.0.2/booking/migrations/0002_shift.py +64 -0
  25. pronto_helpdesk-1.0.2/booking/migrations/0003_appointment_suggested_faq.py +26 -0
  26. pronto_helpdesk-1.0.2/booking/migrations/0004_move_office_to_offices.py +43 -0
  27. pronto_helpdesk-1.0.2/booking/migrations/__init__.py +0 -0
  28. pronto_helpdesk-1.0.2/booking/models.py +148 -0
  29. pronto_helpdesk-1.0.2/booking/notifications.py +128 -0
  30. pronto_helpdesk-1.0.2/booking/serializers.py +101 -0
  31. pronto_helpdesk-1.0.2/booking/services.py +264 -0
  32. pronto_helpdesk-1.0.2/booking/templates/booking/email/booked_employee.it.txt +15 -0
  33. pronto_helpdesk-1.0.2/booking/templates/booking/email/booked_student.en.txt +12 -0
  34. pronto_helpdesk-1.0.2/booking/templates/booking/email/booked_student.it.txt +12 -0
  35. pronto_helpdesk-1.0.2/booking/templates/booking/email/cancelled_employee.it.txt +11 -0
  36. pronto_helpdesk-1.0.2/booking/templates/booking/email/cancelled_student.en.txt +12 -0
  37. pronto_helpdesk-1.0.2/booking/templates/booking/email/cancelled_student.it.txt +12 -0
  38. pronto_helpdesk-1.0.2/booking/urls.py +35 -0
  39. pronto_helpdesk-1.0.2/booking/views.py +201 -0
  40. pronto_helpdesk-1.0.2/faq/__init__.py +0 -0
  41. pronto_helpdesk-1.0.2/faq/admin.py +52 -0
  42. pronto_helpdesk-1.0.2/faq/anonymisation.py +140 -0
  43. pronto_helpdesk-1.0.2/faq/apps.py +9 -0
  44. pronto_helpdesk-1.0.2/faq/management/__init__.py +0 -0
  45. pronto_helpdesk-1.0.2/faq/management/commands/__init__.py +0 -0
  46. pronto_helpdesk-1.0.2/faq/management/commands/import_faqs.py +193 -0
  47. pronto_helpdesk-1.0.2/faq/management/commands/rebuild_faq_index.py +21 -0
  48. pronto_helpdesk-1.0.2/faq/matching.py +138 -0
  49. pronto_helpdesk-1.0.2/faq/migrations/0001_initial.py +77 -0
  50. pronto_helpdesk-1.0.2/faq/migrations/0002_inquiry.py +89 -0
  51. pronto_helpdesk-1.0.2/faq/migrations/0003_faq_office_inquiry_office.py +81 -0
  52. pronto_helpdesk-1.0.2/faq/migrations/0004_link_office.py +44 -0
  53. pronto_helpdesk-1.0.2/faq/migrations/0005_remove_faq_office_code_remove_inquiry_office_code.py +58 -0
  54. pronto_helpdesk-1.0.2/faq/migrations/0006_faq_question_text.py +22 -0
  55. pronto_helpdesk-1.0.2/faq/migrations/0007_inquiry_matched_by.py +35 -0
  56. pronto_helpdesk-1.0.2/faq/migrations/0008_inquiry_office_optional.py +27 -0
  57. pronto_helpdesk-1.0.2/faq/migrations/__init__.py +0 -0
  58. pronto_helpdesk-1.0.2/faq/models.py +116 -0
  59. pronto_helpdesk-1.0.2/faq/serializers.py +82 -0
  60. pronto_helpdesk-1.0.2/faq/services.py +38 -0
  61. pronto_helpdesk-1.0.2/faq/signals.py +37 -0
  62. pronto_helpdesk-1.0.2/faq/urls.py +14 -0
  63. pronto_helpdesk-1.0.2/faq/vector_index.py +119 -0
  64. pronto_helpdesk-1.0.2/faq/views.py +78 -0
  65. pronto_helpdesk-1.0.2/offices/__init__.py +0 -0
  66. pronto_helpdesk-1.0.2/offices/admin.py +16 -0
  67. pronto_helpdesk-1.0.2/offices/apps.py +6 -0
  68. pronto_helpdesk-1.0.2/offices/management/__init__.py +0 -0
  69. pronto_helpdesk-1.0.2/offices/management/commands/__init__.py +0 -0
  70. pronto_helpdesk-1.0.2/offices/management/commands/seed_offices.py +26 -0
  71. pronto_helpdesk-1.0.2/offices/migrations/0001_initial.py +90 -0
  72. pronto_helpdesk-1.0.2/offices/migrations/0002_rename_office_table.py +44 -0
  73. pronto_helpdesk-1.0.2/offices/migrations/__init__.py +0 -0
  74. pronto_helpdesk-1.0.2/offices/models.py +35 -0
  75. pronto_helpdesk-1.0.2/offices/seed.py +34 -0
  76. pronto_helpdesk-1.0.2/pronto/__init__.py +0 -0
  77. pronto_helpdesk-1.0.2/pronto/asgi.py +16 -0
  78. pronto_helpdesk-1.0.2/pronto/enums.py +35 -0
  79. pronto_helpdesk-1.0.2/pronto/i18n.py +50 -0
  80. pronto_helpdesk-1.0.2/pronto/permissions.py +23 -0
  81. pronto_helpdesk-1.0.2/pronto/settings.py +251 -0
  82. pronto_helpdesk-1.0.2/pronto/urls.py +11 -0
  83. pronto_helpdesk-1.0.2/pronto/wsgi.py +16 -0
  84. pronto_helpdesk-1.0.2/pyproject.toml +72 -0
@@ -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 2021 PIKA-lab / eXplanable AI
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.
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: pronto-helpdesk
3
+ Version: 1.0.2
4
+ Summary: Backend of a web application that automates the phone helpdesk of the Campus of Cesena
5
+ License: Apache-2.0
6
+ License-File: LICENSE
7
+ Author: Sara Ladisa
8
+ Author-email: sara.ladisa@studio.unibo.it
9
+ Requires-Python: >=3.10.0,<4.0.0
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Dist: chromadb (>=1.5.9,<2.0.0)
18
+ Requires-Dist: django (>=5.2,<6.0)
19
+ Requires-Dist: django-cors-headers (>=4.4.0,<5.0.0)
20
+ Requires-Dist: djangorestframework (>=3.16.0,<4.0.0)
21
+ Requires-Dist: fastembed (>=0.8.1,<0.10.0)
22
+ Requires-Dist: openpyxl (>=3.1.5,<4.0.0)
23
+ Requires-Dist: psycopg[binary] (>=3.2.0,<4.0.0)
24
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
25
+ Description-Content-Type: text/markdown
26
+
27
+ # PRONTO backend
28
+
29
+ PRONTO automates the phone helpdesk of the Campus of Cesena. Students look for
30
+ an answer among the FAQs of each office and, when none helps, book an
31
+ appointment with the office's staff.
32
+
33
+ This is the backend: a Django and Django REST Framework API on PostgreSQL. The
34
+ frontend is a separate Vue repository.
35
+
36
+ ## Getting started
37
+
38
+ You need Poetry 2.2.1 (the version pinned in the `Dockerfile`).
39
+
40
+ ```bash
41
+ poetry install
42
+ cp .env.example .env # then fill in the values
43
+ poetry run python manage.py migrate
44
+ poetry run python manage.py seed_offices
45
+ poetry run python manage.py import_faqs export.xlsx # optional
46
+ poetry run python manage.py runserver
47
+ ```
48
+
49
+ ### With Docker Compose
50
+
51
+ ```bash
52
+ docker compose up --build
53
+ ```
54
+
55
+ This starts PostgreSQL (`db`), Chroma (`chroma`), the API on
56
+ <http://localhost:8000> and the frontend on <http://localhost:5173>. The
57
+ frontend is built from `../artifact-frontend`, so clone it next to this
58
+ repository.
59
+
60
+ On a new database, create the offices and index the FAQs:
61
+
62
+ ```bash
63
+ docker compose exec backend python manage.py seed_offices
64
+ docker compose exec backend python manage.py rebuild_faq_index
65
+ ```
66
+
67
+ `docker compose down -v` deletes the database volume.
68
+
69
+ ## Tests
70
+
71
+ ```bash
72
+ poetry run poe test # test suite
73
+ poetry run poe coverage # suite with coverage
74
+ poetry run poe coverage-report
75
+ poetry run poe static-checks # ruff and mypy
76
+ poetry run poe format
77
+ ```
78
+
79
+ Tests run on an in-memory SQLite database by default. Full-text search and the
80
+ booking concurrency tests need PostgreSQL: they are marked
81
+ `@pytest.mark.postgres` and skipped on SQLite. To run them:
82
+
83
+ ```bash
84
+ docker compose up -d --wait db
85
+ TEST_DATABASE_URL=postgres://pronto:pronto@localhost:5432/pronto?sslmode=disable \
86
+ poetry run poe test
87
+ ```
88
+
89
+ All tests live in `tests/`.
90
+
91
+ ## Configuration
92
+
93
+ `.env.example` lists every key.
94
+
95
+ | Key | Default | Meaning |
96
+ |-----|---------|---------|
97
+ | `SECRET_KEY` | none | Required outside tests |
98
+ | `DEBUG` | `False` | Debug mode |
99
+ | `ALLOWED_HOSTS` | empty | Comma-separated, required when `DEBUG` is off |
100
+ | `DB_NAME`, `DB_USER`, `DB_PASSWORD`, `DB_HOST`, `DB_PORT` | | PostgreSQL connection |
101
+ | `DB_SSLMODE` | `require` | `disable` for a local server without SSL |
102
+ | `TEST_DATABASE_URL` | empty | Run the tests on PostgreSQL instead of SQLite |
103
+ | `CHROMA_HOST`, `CHROMA_PORT` | empty, `8000` | Semantic FAQ search; off when `CHROMA_HOST` is empty |
104
+ | `EMAIL_BACKEND` | console | Set to the SMTP backend to send real e-mails (`EMAIL_HOST`, `EMAIL_PORT`, ...) |
105
+
106
+ ## API
107
+
108
+ Every endpoint needs a token (`Authorization: Token <key>`) unless marked
109
+ public. Endpoints that return stored text accept `?lang=it|en`.
110
+
111
+ | Method | Path | Who | Description |
112
+ |--------|------|-----|-------------|
113
+ | GET | `/api/health/` | public | Status and version |
114
+ | POST | `/api/auth/register/` | public | Create an account; the role comes from the e-mail domain |
115
+ | POST | `/api/auth/login/` | public | Get a token |
116
+ | POST | `/api/auth/logout/` | token | Delete the token |
117
+ | GET | `/api/auth/me/` | token | Current user |
118
+ | GET | `/api/faqs/` | public | Published FAQs, `?office=<code>` to filter |
119
+ | GET | `/api/faqs/<id>/` | public | One FAQ |
120
+ | POST | `/api/questions/` | student | Ask a question, get the best matching FAQ |
121
+ | POST | `/api/questions/<uuid>/resolve/` | student | Mark the suggested FAQ as helpful |
122
+ | GET | `/api/offices/` | token | Offices taking bookings |
123
+ | GET | `/api/offices/<code>/availability/` | token | Free slots on `?date=YYYY-MM-DD` |
124
+ | GET | `/api/appointments/` | token | The caller's appointments |
125
+ | POST | `/api/appointments/` | student | Book a slot |
126
+ | POST | `/api/appointments/<id>/cancel/` | student, employee | Cancel an appointment |
127
+ | POST | `/api/appointments/<id>/complete/` | employee | Mark an appointment as done |
128
+ | GET, POST | `/api/employee-profile/` | employee | Read or choose the employee's office |
129
+ | GET, POST | `/api/shifts/` | employee | List or add weekly shifts |
130
+ | DELETE | `/api/shifts/<id>/` | employee | Remove a shift |
131
+
132
+ `@studio.unibo.it` addresses register as students, `@unibo.it` addresses as
133
+ employees. Other domains are refused.
134
+
135
+ ## Project structure
136
+
137
+ | App | Contents |
138
+ |-----|----------|
139
+ | `pronto` | Settings, URLs, shared enums and permissions |
140
+ | `accounts` | Users, student profiles, registration and login |
141
+ | `offices` | Offices and the `seed_offices` command |
142
+ | `faq` | FAQs, student questions, matching, import and anonymisation |
143
+ | `booking` | Employee profiles, shifts, appointments and e-mail notifications |
144
+
145
+ FAQ matching tries PostgreSQL full-text search first and falls back to
146
+ semantic search with Chroma. FAQs are managed in the Django admin or imported
147
+ from the helpdesk spreadsheet with `import_faqs`, which anonymises the text and
148
+ leaves the FAQs unpublished.
149
+
150
+ ## CI and releases
151
+
152
+ GitHub Actions runs the checks and the test suite, on SQLite and on
153
+ PostgreSQL, for every push and pull request. A merge into `develop` also
154
+ applies the migrations to the shared Neon database.
155
+
156
+ Releases are made by semantic-release from `master`, based on
157
+ [Conventional Commits](https://www.conventionalcommits.org/). Each release
158
+ creates a tag, a GitHub release, an entry in `CHANGELOG.md`, and publishes the
159
+ `pronto-helpdesk` package to TestPyPI, or to PyPI when the repository variable
160
+ `PUBLISH_TO_PYPI` is `true`. The package index token is the `PYPI_TOKEN`
161
+ secret.
162
+
163
+ ## License
164
+
165
+ Apache 2.0
166
+
@@ -0,0 +1,139 @@
1
+ # PRONTO backend
2
+
3
+ PRONTO automates the phone helpdesk of the Campus of Cesena. Students look for
4
+ an answer among the FAQs of each office and, when none helps, book an
5
+ appointment with the office's staff.
6
+
7
+ This is the backend: a Django and Django REST Framework API on PostgreSQL. The
8
+ frontend is a separate Vue repository.
9
+
10
+ ## Getting started
11
+
12
+ You need Poetry 2.2.1 (the version pinned in the `Dockerfile`).
13
+
14
+ ```bash
15
+ poetry install
16
+ cp .env.example .env # then fill in the values
17
+ poetry run python manage.py migrate
18
+ poetry run python manage.py seed_offices
19
+ poetry run python manage.py import_faqs export.xlsx # optional
20
+ poetry run python manage.py runserver
21
+ ```
22
+
23
+ ### With Docker Compose
24
+
25
+ ```bash
26
+ docker compose up --build
27
+ ```
28
+
29
+ This starts PostgreSQL (`db`), Chroma (`chroma`), the API on
30
+ <http://localhost:8000> and the frontend on <http://localhost:5173>. The
31
+ frontend is built from `../artifact-frontend`, so clone it next to this
32
+ repository.
33
+
34
+ On a new database, create the offices and index the FAQs:
35
+
36
+ ```bash
37
+ docker compose exec backend python manage.py seed_offices
38
+ docker compose exec backend python manage.py rebuild_faq_index
39
+ ```
40
+
41
+ `docker compose down -v` deletes the database volume.
42
+
43
+ ## Tests
44
+
45
+ ```bash
46
+ poetry run poe test # test suite
47
+ poetry run poe coverage # suite with coverage
48
+ poetry run poe coverage-report
49
+ poetry run poe static-checks # ruff and mypy
50
+ poetry run poe format
51
+ ```
52
+
53
+ Tests run on an in-memory SQLite database by default. Full-text search and the
54
+ booking concurrency tests need PostgreSQL: they are marked
55
+ `@pytest.mark.postgres` and skipped on SQLite. To run them:
56
+
57
+ ```bash
58
+ docker compose up -d --wait db
59
+ TEST_DATABASE_URL=postgres://pronto:pronto@localhost:5432/pronto?sslmode=disable \
60
+ poetry run poe test
61
+ ```
62
+
63
+ All tests live in `tests/`.
64
+
65
+ ## Configuration
66
+
67
+ `.env.example` lists every key.
68
+
69
+ | Key | Default | Meaning |
70
+ |-----|---------|---------|
71
+ | `SECRET_KEY` | none | Required outside tests |
72
+ | `DEBUG` | `False` | Debug mode |
73
+ | `ALLOWED_HOSTS` | empty | Comma-separated, required when `DEBUG` is off |
74
+ | `DB_NAME`, `DB_USER`, `DB_PASSWORD`, `DB_HOST`, `DB_PORT` | | PostgreSQL connection |
75
+ | `DB_SSLMODE` | `require` | `disable` for a local server without SSL |
76
+ | `TEST_DATABASE_URL` | empty | Run the tests on PostgreSQL instead of SQLite |
77
+ | `CHROMA_HOST`, `CHROMA_PORT` | empty, `8000` | Semantic FAQ search; off when `CHROMA_HOST` is empty |
78
+ | `EMAIL_BACKEND` | console | Set to the SMTP backend to send real e-mails (`EMAIL_HOST`, `EMAIL_PORT`, ...) |
79
+
80
+ ## API
81
+
82
+ Every endpoint needs a token (`Authorization: Token <key>`) unless marked
83
+ public. Endpoints that return stored text accept `?lang=it|en`.
84
+
85
+ | Method | Path | Who | Description |
86
+ |--------|------|-----|-------------|
87
+ | GET | `/api/health/` | public | Status and version |
88
+ | POST | `/api/auth/register/` | public | Create an account; the role comes from the e-mail domain |
89
+ | POST | `/api/auth/login/` | public | Get a token |
90
+ | POST | `/api/auth/logout/` | token | Delete the token |
91
+ | GET | `/api/auth/me/` | token | Current user |
92
+ | GET | `/api/faqs/` | public | Published FAQs, `?office=<code>` to filter |
93
+ | GET | `/api/faqs/<id>/` | public | One FAQ |
94
+ | POST | `/api/questions/` | student | Ask a question, get the best matching FAQ |
95
+ | POST | `/api/questions/<uuid>/resolve/` | student | Mark the suggested FAQ as helpful |
96
+ | GET | `/api/offices/` | token | Offices taking bookings |
97
+ | GET | `/api/offices/<code>/availability/` | token | Free slots on `?date=YYYY-MM-DD` |
98
+ | GET | `/api/appointments/` | token | The caller's appointments |
99
+ | POST | `/api/appointments/` | student | Book a slot |
100
+ | POST | `/api/appointments/<id>/cancel/` | student, employee | Cancel an appointment |
101
+ | POST | `/api/appointments/<id>/complete/` | employee | Mark an appointment as done |
102
+ | GET, POST | `/api/employee-profile/` | employee | Read or choose the employee's office |
103
+ | GET, POST | `/api/shifts/` | employee | List or add weekly shifts |
104
+ | DELETE | `/api/shifts/<id>/` | employee | Remove a shift |
105
+
106
+ `@studio.unibo.it` addresses register as students, `@unibo.it` addresses as
107
+ employees. Other domains are refused.
108
+
109
+ ## Project structure
110
+
111
+ | App | Contents |
112
+ |-----|----------|
113
+ | `pronto` | Settings, URLs, shared enums and permissions |
114
+ | `accounts` | Users, student profiles, registration and login |
115
+ | `offices` | Offices and the `seed_offices` command |
116
+ | `faq` | FAQs, student questions, matching, import and anonymisation |
117
+ | `booking` | Employee profiles, shifts, appointments and e-mail notifications |
118
+
119
+ FAQ matching tries PostgreSQL full-text search first and falls back to
120
+ semantic search with Chroma. FAQs are managed in the Django admin or imported
121
+ from the helpdesk spreadsheet with `import_faqs`, which anonymises the text and
122
+ leaves the FAQs unpublished.
123
+
124
+ ## CI and releases
125
+
126
+ GitHub Actions runs the checks and the test suite, on SQLite and on
127
+ PostgreSQL, for every push and pull request. A merge into `develop` also
128
+ applies the migrations to the shared Neon database.
129
+
130
+ Releases are made by semantic-release from `master`, based on
131
+ [Conventional Commits](https://www.conventionalcommits.org/). Each release
132
+ creates a tag, a GitHub release, an entry in `CHANGELOG.md`, and publishes the
133
+ `pronto-helpdesk` package to TestPyPI, or to PyPI when the repository variable
134
+ `PUBLISH_TO_PYPI` is `true`. The package index token is the `PYPI_TOKEN`
135
+ secret.
136
+
137
+ ## License
138
+
139
+ Apache 2.0
File without changes
@@ -0,0 +1,107 @@
1
+ from django.contrib import admin
2
+ from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin
3
+ from django.contrib.auth.forms import AdminUserCreationForm
4
+ from django.core.exceptions import ValidationError
5
+ from django.forms.models import BaseInlineFormSet
6
+
7
+ from pronto.enums import Role
8
+
9
+ from .models import StudentProfile, User
10
+
11
+
12
+ class UserCreationFormWithoutUsername(AdminUserCreationForm):
13
+ """Django's admin creation form, with email as the credential."""
14
+
15
+ class Meta(AdminUserCreationForm.Meta):
16
+ model = User
17
+ fields = (
18
+ "email",
19
+ "role",
20
+ "first_name",
21
+ "last_name",
22
+ )
23
+
24
+
25
+ class StudentProfileFormSet(BaseInlineFormSet):
26
+ """Requires a profile for a student and refuses one to anybody else."""
27
+
28
+ def clean(self):
29
+ super().clean()
30
+ kept = [
31
+ form
32
+ for form in self.forms
33
+ if form.cleaned_data and not form.cleaned_data.get("DELETE")
34
+ ]
35
+ if self.instance.role == Role.STUDENT and not kept:
36
+ raise ValidationError("A student needs a matricola and a degree programme.")
37
+ if self.instance.role != Role.STUDENT and kept:
38
+ raise ValidationError("Only students have a student profile.")
39
+
40
+
41
+ class StudentProfileInline(admin.StackedInline):
42
+ """The student data, edited on the user's page."""
43
+
44
+ model = StudentProfile
45
+ formset = StudentProfileFormSet
46
+
47
+ def get_extra(self, request, obj=None, **kwargs):
48
+ if obj is not None and obj.role != Role.STUDENT:
49
+ return 0
50
+ return 1
51
+
52
+
53
+ @admin.register(User)
54
+ class UserAdmin(DjangoUserAdmin):
55
+ """Django's UserAdmin without ``username``."""
56
+
57
+ add_form = UserCreationFormWithoutUsername
58
+ inlines = [StudentProfileInline]
59
+
60
+ list_display = ["email", "last_name", "first_name", "role", "is_active", "is_staff"]
61
+ list_filter = ["role", "is_active", "is_staff"]
62
+ search_fields = [
63
+ "email",
64
+ "last_name",
65
+ "first_name",
66
+ "student_profile__matricola",
67
+ ]
68
+ ordering = ["email"]
69
+
70
+ fieldsets = [
71
+ (None, {"fields": ("email", "password")}),
72
+ (
73
+ "Anagrafica",
74
+ {"fields": ("first_name", "last_name")},
75
+ ),
76
+ (
77
+ "Ruolo e permessi",
78
+ {
79
+ "fields": (
80
+ "role",
81
+ "is_active",
82
+ "is_staff",
83
+ "is_superuser",
84
+ "groups",
85
+ "user_permissions",
86
+ )
87
+ },
88
+ ),
89
+ ("Date", {"fields": ("last_login", "date_joined")}),
90
+ ]
91
+ add_fieldsets = [
92
+ (
93
+ None,
94
+ {
95
+ "classes": ("wide",),
96
+ "fields": (
97
+ "email",
98
+ "role",
99
+ "first_name",
100
+ "last_name",
101
+ "usable_password",
102
+ "password1",
103
+ "password2",
104
+ ),
105
+ },
106
+ ),
107
+ ]
@@ -0,0 +1,6 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class AccountsConfig(AppConfig):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "accounts"