-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add user alerts #1094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add user alerts #1094
Changes from all commits
1a36ce7
7bb74e0
e5762a2
8806cea
ee162b7
f3c1cdf
c4f5df2
ddc810d
9b5675a
3b8be71
91d8622
c0109ad
fafffbb
01bcc30
eacd588
8901c54
736a0fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """add alerts table | ||
|
|
||
| Revision ID: 5ec28ea89e0a | ||
| Revises: d437be68a4fb | ||
| Create Date: 2025-11-05 13:41:25.972261 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| from renku_data_services.utils.sqlalchemy import ULIDType | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "5ec28ea89e0a" | ||
| down_revision = "42049656cdb8" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table( | ||
| "alerts", | ||
| sa.Column("id", ULIDType(), nullable=False), | ||
| sa.Column("title", sa.String(), nullable=False), | ||
| sa.Column("message", sa.String(), nullable=False), | ||
| sa.Column("user_id", sa.String(), nullable=False), | ||
| sa.Column("session_name", sa.String(), nullable=True), | ||
| sa.Column("creation_date", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False), | ||
| sa.Column("resolved_at", sa.DateTime(timezone=True), nullable=True), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| schema="notifications", | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_table("alerts", schema="notifications") | ||
| # ### end Alembic commands ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Blueprints for notifications.""" |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good start π
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @leafty!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made these changes now |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| openapi: 3.0.2 | ||
| info: | ||
| title: Renku Data Services API | ||
| description: | | ||
| A service that allows alerts to be sent to users. | ||
| version: v1 | ||
| servers: | ||
| - url: /api/data | ||
| paths: | ||
| /alerts: | ||
| post: | ||
| summary: Send an alert to a user. Requires admin permissions. | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/AlertPost" | ||
| responses: | ||
| "201": | ||
| description: Alert successfully created | ||
| content: | ||
| "application/json": | ||
| schema: | ||
| $ref: "#/components/schemas/Alert" | ||
| default: | ||
| $ref: "#/components/responses/Error" | ||
| tags: | ||
| - alerts | ||
| get: | ||
| summary: Retrieve all active alerts for the authenticated user. | ||
| parameters: | ||
| - name: session_name | ||
| in: query | ||
| description: Optional filter to only retrieve alerts for a specific session. | ||
| required: false | ||
| schema: | ||
| $ref: "#/components/schemas/SessionName" | ||
| responses: | ||
| "200": | ||
| description: A list of active alerts for the authenticated user. | ||
| content: | ||
| "application/json": | ||
| schema: | ||
| $ref: "#/components/schemas/AlertList" | ||
| default: | ||
| $ref: "#/components/responses/Error" | ||
| tags: | ||
| - alerts | ||
| /alerts/{alert_id}: | ||
| patch: | ||
| summary: Resolve an alert. Requires admin permissions. | ||
| description: Mark an alert as resolved. The alert remains in the database but is no longer active. | ||
| parameters: | ||
| - in: path | ||
| name: alert_id | ||
| required: true | ||
| schema: | ||
| $ref: "#/components/schemas/Ulid" | ||
| description: The ID of the alert to resolve. | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/AlertPatch" | ||
| responses: | ||
| "200": | ||
| description: Alert successfully updated | ||
| content: | ||
| "application/json": | ||
| schema: | ||
| $ref: "#/components/schemas/Alert" | ||
| "404": | ||
| description: Alert not found | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/ErrorResponse" | ||
| default: | ||
| $ref: "#/components/responses/Error" | ||
| tags: | ||
| - alerts | ||
| components: | ||
| schemas: | ||
| AlertPatch: | ||
| description: Data to update an alert. | ||
| type: object | ||
| additionalProperties: false | ||
| properties: | ||
| resolved: | ||
| type: boolean | ||
| description: Set to true to mark the alert as resolved. The resolved_at timestamp will be set automatically. | ||
| Ulid: | ||
| description: ULID identifier | ||
| type: string | ||
| minLength: 26 | ||
| maxLength: 26 | ||
| pattern: "^[0-7][0-9A-HJKMNP-TV-Z]{25}$" # This is case-insensitive | ||
| Alert: | ||
| description: An alert sent or displayed to a user. | ||
| type: object | ||
| properties: | ||
leafty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id: | ||
| $ref: "#/components/schemas/Ulid" | ||
| title: | ||
| $ref: "#/components/schemas/AlertTitle" | ||
| message: | ||
| $ref: "#/components/schemas/AlertMessage" | ||
| user_id: | ||
| $ref: "#/components/schemas/UserId" | ||
| session_name: | ||
| $ref: "#/components/schemas/SessionName" | ||
| creation_date: | ||
| type: string | ||
| format: date-time | ||
| description: The date and time when the alert was created. | ||
| resolved_at: | ||
| type: string | ||
| format: date-time | ||
| nullable: true | ||
| description: The date and time when the alert was resolved, or null if it is still active. | ||
| required: | ||
| - id | ||
| - title | ||
| - message | ||
| - user_id | ||
| - creation_date | ||
| AlertPost: | ||
| description: Data required to create an alert. | ||
| type: object | ||
| properties: | ||
| title: | ||
| $ref: "#/components/schemas/AlertTitle" | ||
| message: | ||
| $ref: "#/components/schemas/AlertMessage" | ||
| user_id: | ||
| $ref: "#/components/schemas/UserId" | ||
| session_name: | ||
| $ref: "#/components/schemas/SessionName" | ||
| required: | ||
| - title | ||
| - message | ||
| - user_id | ||
| AlertTitle: | ||
| type: string | ||
| description: The title of the alert. | ||
| AlertMessage: | ||
| type: string | ||
| description: The message body of the alert. | ||
| SessionName: | ||
| description: Renku session name | ||
| type: string | ||
| minLength: 1 | ||
| maxLength: 99 | ||
| example: My Renku Session :) | ||
| UserId: | ||
| type: string | ||
| description: Keycloak user ID | ||
| example: f74a228b-1790-4276-af5f-25c2424e9b0c | ||
| pattern: "^[A-Za-z0-9]{1}[A-Za-z0-9-]+$" | ||
| AlertList: | ||
| type: array | ||
| description: A list of alerts. | ||
| items: | ||
| $ref: "#/components/schemas/Alert" | ||
| ErrorResponse: | ||
| type: object | ||
| properties: | ||
| error: | ||
| type: object | ||
| properties: | ||
| code: | ||
| type: integer | ||
| minimum: 0 | ||
| exclusiveMinimum: true | ||
| example: 1404 | ||
| detail: | ||
| type: string | ||
| example: A more detailed optional message showing what the problem was | ||
| message: | ||
| type: string | ||
| example: Something went wrong - please try again later | ||
| required: | ||
| - code | ||
| - message | ||
| required: | ||
| - error | ||
|
|
||
| responses: | ||
| Error: | ||
| description: The schema for all 4xx and 5xx responses | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/ErrorResponse" | ||
Uh oh!
There was an error while loading. Please reload this page.