Skip to content

Commit 4f2fc06

Browse files
authored
Merge pull request #4863 from coralproject/develop
v9.11.3
2 parents 401c3f5 + e047615 commit 4f2fc06

File tree

13 files changed

+100
-28
lines changed

13 files changed

+100
-28
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.11.2",
3+
"version": "9.11.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.11.2",
3+
"version": "9.11.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.11.2",
3+
"version": "9.11.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.11.2",
3+
"version": "9.11.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

server/src/core/server/graph/mutators/Comments.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
GQLCreateCommentReplyInput,
3636
GQLCreateIllegalContentInput,
3737
GQLEditCommentInput,
38+
GQLFEATURE_FLAG,
3839
GQLFeatureCommentInput,
3940
GQLMarkCommentsAsSeenInput,
4041
GQLNOTIFICATION_TYPE,
@@ -48,7 +49,7 @@ import { MongoContext } from "coral-server/data/context";
4849
import { Comment } from "coral-server/models/comment";
4950
import { retrieveSite } from "coral-server/models/site";
5051
import { retrieveStory } from "coral-server/models/story";
51-
import { Tenant } from "coral-server/models/tenant";
52+
import { hasFeatureFlag, Tenant } from "coral-server/models/tenant";
5253
import { ExternalNotificationsService } from "coral-server/services/notifications/externalService";
5354
import { validateUserModerationScopes } from "./helpers";
5455
import { validateMaximumLength, WithoutMutationID } from "./util";
@@ -59,7 +60,16 @@ const sendExternalFeatureNotification = async (
5960
tenant: Tenant,
6061
comment: Comment
6162
) => {
62-
if (!externalNotifications.active() || !comment.authorID || !comment.siteID) {
63+
const externalNotificationsDisabledOnTenant = hasFeatureFlag(
64+
tenant,
65+
GQLFEATURE_FLAG.DISABLE_EXTERNAL_NOTIFICATIONS
66+
);
67+
if (
68+
!externalNotifications.active() ||
69+
externalNotificationsDisabledOnTenant ||
70+
!comment.authorID ||
71+
!comment.siteID
72+
) {
6373
return;
6474
}
6575

server/src/core/server/graph/resolvers/Settings.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
import validFeatureFlagsFilter from "coral-server/models/settings/validFeatureFlagsFilter";
77
import {
88
areRepliesFlattened,
9+
hasFeatureFlag,
910
isAMPEnabled,
1011
isForReviewQueueEnabled,
1112
retrieveAnnouncementIfEnabled,
1213
Tenant,
1314
} from "coral-server/models/tenant";
1415

1516
import {
17+
GQLFEATURE_FLAG,
1618
GQLSettingsTypeResolver,
1719
GQLWEBHOOK_EVENT_NAME,
1820
} from "coral-server/graph/schema/__generated__/types";
@@ -88,7 +90,15 @@ export const Settings: GQLSettingsTypeResolver<Tenant> = {
8890
disposableEmailDomains: ({ disposableEmailDomains = { enabled: false } }) =>
8991
disposableEmailDomains,
9092
externalNotifications: (parent, args, ctx) => {
91-
return { active: ctx.externalNotifications.active() };
93+
const externalNotificationsDisabledOnTenant = hasFeatureFlag(
94+
ctx.tenant,
95+
GQLFEATURE_FLAG.DISABLE_EXTERNAL_NOTIFICATIONS
96+
);
97+
return {
98+
active:
99+
ctx.externalNotifications.active() &&
100+
!externalNotificationsDisabledOnTenant,
101+
};
92102
},
93103
inPageNotifications: (
94104
{

server/src/core/server/graph/schema/schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,11 @@ enum FEATURE_FLAG {
595595
COUNTS_V2 will allow the use of the new /counts/v2 api endpoint to retrieve story comment counts.
596596
"""
597597
COUNTS_V2
598+
599+
"""
600+
DISABLE_EXTERNAL_NOTIFICATIONS will disable the external notifications feature at the tenant level.
601+
"""
602+
DISABLE_EXTERNAL_NOTIFICATIONS
598603
}
599604

600605
# The moderation mode of the site.

server/src/core/server/queue/tasks/externalNotifications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const createJobProcessor =
3636
log.info("attempting to send notifications for task");
3737

3838
try {
39-
await externalNotifications.sendMany(notifications);
39+
await externalNotifications.sendMany(notifications, tenantID);
4040
} catch (err) {
4141
log.error(
4242
{ taskID, tenantID, notifications },

server/src/core/server/services/comments/actions.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "coral-server/models/comment";
2525
import { getLatestRevision } from "coral-server/models/comment/helpers";
2626
import { retrieveSite } from "coral-server/models/site";
27-
import { Tenant } from "coral-server/models/tenant";
27+
import { hasFeatureFlag, Tenant } from "coral-server/models/tenant";
2828
import { isSiteBanned } from "coral-server/models/user/helpers";
2929
import { AugmentedRedis } from "coral-server/services/redis";
3030
import {
@@ -33,7 +33,10 @@ import {
3333
} from "coral-server/stacks/helpers";
3434
import { Request } from "coral-server/types/express";
3535

36-
import { GQLCOMMENT_FLAG_REPORTED_REASON } from "coral-server/graph/schema/__generated__/types";
36+
import {
37+
GQLCOMMENT_FLAG_REPORTED_REASON,
38+
GQLFEATURE_FLAG,
39+
} from "coral-server/graph/schema/__generated__/types";
3740

3841
import GraphContext from "coral-server/graph/context";
3942
import { User } from "coral-server/models/user";
@@ -360,7 +363,14 @@ export async function createReaction(
360363
logger.error({ err }, "could not publish comment flag created");
361364
});
362365

363-
if (externalNotifications.active()) {
366+
const externalNotificationsDisabledOnTenant = hasFeatureFlag(
367+
tenant,
368+
GQLFEATURE_FLAG.DISABLE_EXTERNAL_NOTIFICATIONS
369+
);
370+
if (
371+
externalNotifications.active() &&
372+
!externalNotificationsDisabledOnTenant
373+
) {
364374
const reccingUser = author;
365375
const reccedUser = comment.authorID
366376
? await context.loaders.Users.user.load(comment.authorID)
@@ -416,7 +426,14 @@ export async function removeReaction(
416426
}
417427
);
418428

419-
if (ctx.externalNotifications.active()) {
429+
const externalNotificationsDisabledOnTenant = hasFeatureFlag(
430+
ctx.tenant,
431+
GQLFEATURE_FLAG.DISABLE_EXTERNAL_NOTIFICATIONS
432+
);
433+
if (
434+
ctx.externalNotifications.active() &&
435+
!externalNotificationsDisabledOnTenant
436+
) {
420437
const unReccedUser = result.authorID
421438
? await ctx.loaders.Users.user.load(result.authorID)
422439
: null;

server/src/core/server/services/notifications/externalService.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class ExternalNotificationsService {
211211
comment: this.commentToInput(input.comment, input.story),
212212
};
213213

214-
return await this.send(data);
214+
return await this.send(data, input.comment.tenantID);
215215
} catch (err) {
216216
this.logger.warn(
217217
{ err, input },
@@ -243,7 +243,7 @@ export class ExternalNotificationsService {
243243
comment: this.commentToInput(input.comment, input.story),
244244
};
245245

246-
return await this.send(data);
246+
return await this.send(data, input.comment.tenantID);
247247
} catch (err) {
248248
this.logger.warn(
249249
{ err, input },
@@ -287,7 +287,7 @@ export class ExternalNotificationsService {
287287
try {
288288
const data = this.buildReply(input);
289289

290-
return await this.send(data);
290+
return await this.send(data, input.reply.tenantID);
291291
} catch (err) {
292292
this.logger.warn(
293293
{ err, input },
@@ -320,7 +320,7 @@ export class ExternalNotificationsService {
320320
try {
321321
const data = this.buildApprove(input);
322322

323-
return await this.send(data);
323+
return await this.send(data, input.comment.tenantID);
324324
} catch (err) {
325325
this.logger.warn(
326326
{ err, input },
@@ -353,7 +353,7 @@ export class ExternalNotificationsService {
353353
try {
354354
const data = this.buildReject(input);
355355

356-
return await this.send(data);
356+
return await this.send(data, input.comment.tenantID);
357357
} catch (err) {
358358
this.logger.warn(
359359
{ err, input },
@@ -380,7 +380,7 @@ export class ExternalNotificationsService {
380380
comment: this.commentToInput(input.comment, input.story),
381381
};
382382

383-
return await this.send(data);
383+
return await this.send(data, input.comment.tenantID);
384384
} catch (err) {
385385
this.logger.warn(
386386
{ err, input },
@@ -391,15 +391,15 @@ export class ExternalNotificationsService {
391391
return false;
392392
}
393393

394-
public async send(notification: any) {
394+
public async send(notification: any, tenantID: string) {
395395
if (!notification) {
396396
return false;
397397
}
398398

399-
return this.sendMany([notification]);
399+
return this.sendMany([notification], tenantID);
400400
}
401401

402-
public async sendMany(notifications: any[]) {
402+
public async sendMany(notifications: any[], tenantID: string) {
403403
if (!this.active()) {
404404
return false;
405405
}
@@ -418,6 +418,7 @@ export class ExternalNotificationsService {
418418
headers: {
419419
"Content-Type": "application/json",
420420
"x-notifications-api-key": this.apiKey!,
421+
"x-notifications-coral-tenant-id": tenantID,
421422
},
422423
body: JSON.stringify(data),
423424
});

0 commit comments

Comments
 (0)