-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(api): Delete subscriber channel preference when updating global channel #6767
Changes from 38 commits
5e77371
cda73b9
856a947
22346b8
18523d5
8ba826f
eaf6080
3e3ff65
f5c8d98
0c41453
150e302
6a66a12
5d99857
0fa489a
86b5bc6
56f0d09
70f22b6
7aab8b7
49b8683
a4d5c47
1739863
ae7a520
b1abd25
26c0ffc
4d7479d
a51539c
85addb9
73fe8bf
7177ae2
a5ce239
8ca830f
3c09ccc
c783e5d
32f7ec6
093365d
26891fc
6afe9da
4b54490
a5c0b9b
2ee421d
e383ae2
09107f8
33c0d8e
a53724a
2137bc3
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 |
---|---|---|
|
@@ -19,7 +19,13 @@ import { | |
UpsertPreferences, | ||
UpsertWorkflowPreferencesCommand, | ||
} from '@novu/application-generic'; | ||
import { FeatureFlagsKeysEnum, WorkflowCreationSourceEnum, WorkflowOriginEnum, WorkflowTypeEnum } from '@novu/shared'; | ||
import { | ||
FeatureFlagsKeysEnum, | ||
WorkflowCreationSourceEnum, | ||
WorkflowOriginEnum, | ||
WorkflowTypeEnum, | ||
WorkflowPreferencesPartial, | ||
} from '@novu/shared'; | ||
import { DiscoverOutput, DiscoverStepOutput, DiscoverWorkflowOutput, GetActionEnum } from '@novu/framework/internal'; | ||
|
||
import { SyncCommand } from './sync.command'; | ||
|
@@ -186,7 +192,7 @@ export class Sync { | |
environmentId: savedWorkflow._environmentId, | ||
organizationId: savedWorkflow._organizationId, | ||
templateId: savedWorkflow._id, | ||
preferences: workflow.preferences, | ||
preferences: this.getWorkflowPreferences(workflow), | ||
}) | ||
); | ||
} | ||
|
@@ -323,6 +329,10 @@ export class Sync { | |
return notificationGroupId; | ||
} | ||
|
||
private getWorkflowPreferences(workflow: DiscoverWorkflowOutput): WorkflowPreferencesPartial { | ||
return workflow.preferences || {}; | ||
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. A fallback empty object is now necessary during sync after strengthening validation of the |
||
} | ||
|
||
private getWorkflowName(workflow: DiscoverWorkflowOutput): string { | ||
return workflow.name || workflow.workflowId; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { UserSession } from '@novu/testing'; | ||
import { expect } from 'chai'; | ||
import { StepTypeEnum } from '@novu/shared'; | ||
|
||
describe('Get all preferences - /inbox/preferences (GET)', function () { | ||
let session: UserSession; | ||
|
@@ -9,22 +10,28 @@ describe('Get all preferences - /inbox/preferences (GET)', function () { | |
await session.initialize(); | ||
}); | ||
|
||
it('should always get the global preferences even if workflow preferences are not present', async function () { | ||
it('should return no global preferences if workflow preferences are not present', async function () { | ||
const response = await session.testAgent | ||
.get('/v1/inbox/preferences') | ||
.set('Authorization', `Bearer ${session.subscriberToken}`); | ||
|
||
const globalPreference = response.body.data[0]; | ||
|
||
expect(globalPreference.channels.email).to.equal(true); | ||
expect(globalPreference.channels.in_app).to.equal(true); | ||
expect(globalPreference.channels.email).to.equal(undefined); | ||
expect(globalPreference.channels.in_app).to.equal(undefined); | ||
expect(globalPreference.level).to.equal('global'); | ||
expect(response.body.data.length).to.equal(1); | ||
}); | ||
|
||
it('should get both global and workflow preferences if workflow is present', async function () { | ||
it('should get both global preferences for active channels and workflow preferences if workflow is present', async function () { | ||
await session.createTemplate({ | ||
noFeedId: true, | ||
steps: [ | ||
{ | ||
type: StepTypeEnum.EMAIL, | ||
content: 'Test notification content', | ||
}, | ||
], | ||
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. Explicitly specifying that only email is present, to assert that |
||
}); | ||
|
||
const response = await session.testAgent | ||
|
@@ -34,13 +41,13 @@ describe('Get all preferences - /inbox/preferences (GET)', function () { | |
const globalPreference = response.body.data[0]; | ||
|
||
expect(globalPreference.channels.email).to.equal(true); | ||
expect(globalPreference.channels.in_app).to.equal(true); | ||
expect(globalPreference.channels.in_app).to.equal(undefined); | ||
expect(globalPreference.level).to.equal('global'); | ||
|
||
const workflowPreference = response.body.data[1]; | ||
|
||
expect(workflowPreference.channels.email).to.equal(true); | ||
expect(workflowPreference.channels.in_app).to.equal(true); | ||
expect(workflowPreference.channels.in_app).to.equal(undefined); | ||
expect(workflowPreference.level).to.equal('template'); | ||
}); | ||
|
||
|
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. Here and in the following files, we'll see renaming from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This MongoDB version bump to >5 was needed to solve this runtime error that disallows setting empty objects:
Version 5 supports empty object setting per this thread and referenced documentation.
5.0.29
is the latest LTS 5.x release per the MongoDB changelog. MongoDB 5.0 reaches end of life this month, October 2024.Note, this means that we are effectively dropping support of MongoDB v4 for Novu Self-hosted. MongoDB v4 reached end of life in February 2024.
cc @merrcury
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, Thanks 👍🏼. We will post a note a to community/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call out!