Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ FILESYSTEM_MOUNT_DIR_SCRATCH=/path/to/scratch/mount/dir
SCRATCH_INGESTION_RESTRICTED_DIRS=/path/to/scratch/restricted/dir

UPLOAD_DIR=/path/to/upload/destination

QUEUE_URL=localhost:5672/myvhost
QUEUE_USERNAME=user
QUEUE_PASSWORD=password
5 changes: 5 additions & 0 deletions api/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@
},
"restricted_ingestion_dirs": {
"slateScratch": "SCRATCH_INGESTION_RESTRICTED_DIRS"
},
"queue": {
"url": "QUEUE_URL",
"username": "QUEUE_USERNAME",
"password": "QUEUE_PASSWORD"
}
}
12 changes: 12 additions & 0 deletions api/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,17 @@
"enabled_for_roles": ["admin"]
},
"downloads": true
},
"queue": {
"url": "",
"username": "",
"password": ""
},
"notifications": {
"event_queue": "events",
"notification_queues": {
"email": "email_notifications",
"app": "app_notifications"
}
}
}
Binary file added api/docs/assets/notifications.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions api/docs/diagrams/notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
```mermaid
flowchart LR;
subgraph "Event Generation"
A[API] -->|Publish Event| B[Event Queue]
A1[Workers] --> |Publish Event| B
end

subgraph "Event Processing"
B -->|Consume Event| C@{ shape: procs, label: "Event Processor Jobs"}
C <-->|Query Subscriptions| D[Postgres DB - notification_subscription, user]
C <-->|Construct Message| E[Message Templates]
end

subgraph "Notification Dispatch"
C --> F[Email Queue]
C --> G[Slack Queue]
C --> H[SMS Queue]
end

subgraph "Channel Processing"
F -->|Process Email| I@{ shape: procs, label: "Email Processors"}
G -->|Process Slack| J@{ shape: procs, label: "Slack Processors"}
H -->|Process SMS| K@{ shape: procs, label: "SMS Processors"}
end
```
(https://mermaid.live/edit#pako:eNp9U9Fu0zAU_ZUrP3cPvAaE2NKu26CoECQkkgo5zm1izbEjXxs0Nf13HIeNlC71U5Jzz_HxOc6BCVMhS9hemd-i4dbBp69vCw1hkS9ry7sGCrb6hdrBGjVa7qTRBRtHhnWdX2_vd3B19b7f-lJJaiCO93CTj7wvHj3uJow3-XdjH9FSpMEZbxxFXRV6xsrWGoFEUtdTKzfRRWo0-Raf1dIPB6CGd5hAF1i0AMVLVMn_WsbCgympYMd_gim8GxTDAewTZL4kYWU3BEA9LPOtIVdbJFiGjUEbJ_dSxHx-0mR2AZ7Q7s5UB5_OeuFgE7bnNfawyv8-wjdsO8Ud0u5SGJ8ne8JSUsedaKaJpDHg23zVcqnOihjRdZ4pLh5n0Ls822Qn2OtW0oZrjWqmmdvxfowYRDc93F9oJvp9aea0lfWJWDTfw8O82Hi8GbG7U7FN1sPHC1Ihi1eEYiRswVq0wXgV_qfDABTMNdhiwQZqhXvulRtSOYZR7p3JnrRgSbgDuGC-q0LdS8lDoC1L9lxR-GqNr5uXt47rH8Y8o8c_FDY0aw)
40 changes: 40 additions & 0 deletions api/docs/notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### **Requirements for Notification Feature**

<img src="assets/notifications.png" >

#### **Overview**
The notification feature is designed to provide users with alerts regarding important events within the system, including both user-specific events (e.g., dataset staging completion) and system-wide notifications (e.g., scheduled maintenance announcements). Users can opt-in to receive notifications for specific events and delivery methods while having the flexibility to opt-out of notifications for particular events.

#### **1. Notification Preferences**
- Users must have the ability to manage their notification preferences, allowing them to select preferred delivery methods (e.g., email, Slack, in-app notifications).
- Users can enable or disable notifications for each delivery method independently.
- Users may opt-out of notifications for specific events while still receiving other notifications.

#### **2. Event Types**
- The system must support various types of events that can trigger notifications, with each event type having a defined name, description, and associated notification message template.
- Admins should be able to define new event types and indicate whether an event is intended for system-wide notification.

#### **3. User Subscriptions**
- Users will automatically subscribe to notifications for specific events when they request actions that lead to those events (e.g., staging a dataset).
- Each subscription will be tied to a specific resource (e.g., dataset, project) to ensure relevant notifications are sent.

#### **4. System-Wide Notifications**
- The system must support sending notifications for events marked as system-wide, targeting all users regardless of their individual subscriptions.
- System-wide notifications must be sent using the preferred delivery methods selected by each user.

#### **5. Notification Sending Logic**
- Upon the occurrence of an event, the system must determine whether it is a user-specific event or a system-wide event.
- For user-specific events, the system must send notifications only to users who have opted in for that specific event and resource.
- For system-wide events, the system must send notifications to all users who have enabled notifications for any type of events.

#### **6. User Experience**
- Users should be able to view and manage their notification preferences easily through the user interface.
- Users should receive timely notifications through their chosen delivery methods, providing clear information about the events.
- Notifications should include relevant details, such as the type of event, affected resource, and any necessary follow-up actions.

#### **7. Administration and Management**
- Admins must have the ability to view and manage event types and templates used for notifications.
- Admins should be able to access logs or reports of notifications sent, including successful deliveries and any failures.

### **Conclusion**
This notification feature aims to enhance user engagement and ensure that users remain informed about relevant events in the system. By providing flexible subscription options and clear management of event notifications, the system can deliver timely and pertinent information to users effectively.
7 changes: 7 additions & 0 deletions api/ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ module.exports = [{
exp_backoff_restart_delay: 100,
max_restarts: 3,
watch: false,
}, {
script: 'src/scripts/notification_processor.js',
name: 'notification_processor',
exec_mode: 'fork',
exp_backoff_restart_delay: 100,
max_restarts: 3,
watch: false,
}];
53 changes: 53 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@iusca/iulogin-helper": "^0.1.4",
"@prisma/client": "^5.18.0",
"accesscontrol": "^2.2.1",
"amqplib": "^0.10.5",
"axios": "^1.5.0",
"compression": "^1.7.4",
"config": "^3.3.9",
Expand Down
51 changes: 51 additions & 0 deletions api/prisma/migrations/20250225015611_notifications/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- CreateTable
CREATE TABLE "event_type" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"tags" TEXT[],
"description" TEXT,

CONSTRAINT "event_type_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "notification_preference" (
"id" SERIAL NOT NULL,
"user_id" INTEGER NOT NULL,
"delivery_method" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL DEFAULT true,
"updated_at" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "notification_preference_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "notification_subscription" (
"id" SERIAL NOT NULL,
"is_system_wide" BOOLEAN NOT NULL DEFAULT false,
"user_id" INTEGER,
"role_id" INTEGER,
"is_active" BOOLEAN NOT NULL DEFAULT true,
"created_at" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expires_at" TIMESTAMP(6),
"event_type_id" INTEGER NOT NULL,
"resource_id" TEXT,
"resource_type" TEXT,

CONSTRAINT "notification_subscription_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "notification_preference_user_id_delivery_method_key" ON "notification_preference"("user_id", "delivery_method");

-- AddForeignKey
ALTER TABLE "notification_preference" ADD CONSTRAINT "notification_preference_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_subscription" ADD CONSTRAINT "notification_subscription_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_subscription" ADD CONSTRAINT "notification_subscription_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "role"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_subscription" ADD CONSTRAINT "notification_subscription_event_type_id_fkey" FOREIGN KEY ("event_type_id") REFERENCES "event_type"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Loading