|
8 | 8 | ChangeUserRoleBody, |
9 | 9 | CreateAdminMessageBody, |
10 | 10 | CreateOrganizationBody, |
| 11 | + CreateUpdateReleaseNotificationBody, |
11 | 12 | DeleteOrganizationBody, |
12 | 13 | DeleteUserBody, |
13 | 14 | MappedSortedPaginatedUsers, |
|
16 | 17 | ) |
17 | 18 | from controller.auth import manager as auth_manager |
18 | 19 | from controller.auth.kratos import ( |
| 20 | + resolve_user_mail_by_id, |
19 | 21 | resolve_user_name_by_id, |
20 | 22 | ) |
21 | 23 | from controller.organization import manager |
|
24 | 26 | from controller.user import manager as user_manager |
25 | 27 |
|
26 | 28 | from fast_api.routes.client_response import get_silent_success, pack_json_result |
27 | | -from submodules.model.business_objects import organization, user |
| 29 | +from submodules.model.business_objects import organization, release_notification, user |
28 | 30 | from submodules.model.util import sql_alchemy_to_dict |
29 | 31 | from util import notification |
30 | 32 |
|
|
64 | 66 | "file_lifespan_days", |
65 | 67 | "token_limit", |
66 | 68 | } |
| 69 | +RELEASE_NOTIFICATIONS_WHITELIST = {"id", "link", "config"} |
67 | 70 |
|
68 | 71 |
|
69 | 72 | # in use refinery-ui (07.01.25) |
@@ -314,3 +317,58 @@ def get_user_to_organization(request: Request): |
314 | 317 | auth_manager.check_admin_access(request.state.info) |
315 | 318 | data = user.get_user_to_organization() |
316 | 319 | return pack_json_result(data, wrap_for_frontend=False) |
| 320 | + |
| 321 | + |
| 322 | +# in use admin-dashboard (01.10.25) |
| 323 | +@router.get("/all-release-notifications-admin") |
| 324 | +def get_all_release_notifications(request: Request): |
| 325 | + auth_manager.check_admin_access(request.state.info) |
| 326 | + data = sql_alchemy_to_dict(release_notification.get_all()) |
| 327 | + for item in data: |
| 328 | + item["createdByEmail"] = resolve_user_mail_by_id(item["created_by"]) |
| 329 | + return pack_json_result(data) |
| 330 | + |
| 331 | + |
| 332 | +# in use admin-dashboard (08.10.25) |
| 333 | +@router.get("/release-notifications") |
| 334 | +def get_release_notifications(request: Request): |
| 335 | + data = sql_alchemy_to_dict( |
| 336 | + release_notification.get_all(), |
| 337 | + column_whitelist=RELEASE_NOTIFICATIONS_WHITELIST, |
| 338 | + ) |
| 339 | + return pack_json_result(data) |
| 340 | + |
| 341 | + |
| 342 | +# in use admin-dashboard (01.10.25) |
| 343 | +@router.post("/create-release-notification") |
| 344 | +def create_release_notification( |
| 345 | + request: Request, body: CreateUpdateReleaseNotificationBody = Body(...) |
| 346 | +): |
| 347 | + auth_manager.check_admin_access(request.state.info) |
| 348 | + user_id = auth_manager.get_user_id_by_info(request.state.info) |
| 349 | + validate_result = manager.validate_json_release_notification(body.config) |
| 350 | + if validate_result["is_valid"]: |
| 351 | + release_notification.create(body.link, body.config, user_id, with_commit=True) |
| 352 | + return pack_json_result(validate_result, wrap_for_frontend=False) |
| 353 | + |
| 354 | + |
| 355 | +# in use admin-dashboard (02.10.25) |
| 356 | +@router.put("/update-release-notification/{notification_id}") |
| 357 | +def update_release_notification( |
| 358 | + request: Request, |
| 359 | + notification_id: str, |
| 360 | + body: CreateUpdateReleaseNotificationBody = Body(...), |
| 361 | +): |
| 362 | + auth_manager.check_admin_access(request.state.info) |
| 363 | + release_notification.update( |
| 364 | + notification_id, body.link, body.config, with_commit=True |
| 365 | + ) |
| 366 | + return get_silent_success() |
| 367 | + |
| 368 | + |
| 369 | +# in use admin-dashboard (02.10.25) |
| 370 | +@router.delete("/delete-release-notification/{notification_id}") |
| 371 | +def delete_release_notification(request: Request, notification_id: str): |
| 372 | + auth_manager.check_admin_access(request.state.info) |
| 373 | + release_notification.delete(notification_id, with_commit=True) |
| 374 | + return get_silent_success() |
0 commit comments