Skip to content
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

Optimism proposal reviewer notifications #5153

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
58 changes: 58 additions & 0 deletions lib/notifications/documents/createDocumentNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ export async function createDocumentNotifications(webhookData: {
: (webhookData.event.document?.authors.map(({ id }) => id) ?? []);
const documentId = webhookData.event.document?.id;
const postId = webhookData.event.post?.id;
const space = await prisma.space.findUniqueOrThrow({
Devorein marked this conversation as resolved.
Show resolved Hide resolved
where: {
id: spaceId
},
select: {
domain: true
}
});

const comment = webhookData.event.post
? await prisma.postComment.findFirstOrThrow({
Expand Down Expand Up @@ -483,6 +491,56 @@ export async function createDocumentNotifications(webhookData: {
}
}

const document = documentId
? await prisma.page.findUniqueOrThrow({
where: {
id: documentId
},
select: {
type: true,
proposalId: true
}
})
: null;

if (documentId && space.domain === 'op-grants' && document?.type === 'proposal' && document?.proposalId) {
Devorein marked this conversation as resolved.
Show resolved Hide resolved
const spaceRoles = await prisma.spaceRole.findMany({
where: {
spaceId
},
select: {
userId: true
}
});

for (const spaceRole of spaceRoles) {
if (notificationSentUserIds.has(spaceRole.userId) || spaceRole.userId === commentAuthorId) {
continue;
}

const proposalPermissions = await permissionsApiClient.proposals.computeProposalPermissions({
resourceId: document?.proposalId,
userId: spaceRole.userId
});

if (proposalPermissions.evaluate || proposalPermissions.evaluate_appeal) {
const { id } = await saveDocumentNotification({
type: 'comment.created',
Devorein marked this conversation as resolved.
Show resolved Hide resolved
createdAt: webhookData.createdAt,
createdBy: commentAuthorId,
commentId,
pageId: documentId,
spaceId,
userId: spaceRole.userId,
content: comment.content
});

ids.push(id);
notificationSentUserIds.add(spaceRole.userId);
Devorein marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

break;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/webhookPublisher/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { isTestEnv } from '@root/config/constants';
import { addMessageToSQS } from '@root/lib/aws/SQS';
import type { WebhookEvent, WebhookPayload } from '@root/lib/webhookPublisher/interfaces';

import { createNotificationsFromEvent } from '../notifications/createNotificationsFromEvent';
Devorein marked this conversation as resolved.
Show resolved Hide resolved

const SQS_QUEUE_NAME = process.env.SQS_WEBHOOK_PUBLISHER_QUEUE_NAME;

// This function check subscription status by event name AND name space
Expand Down
Loading