Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Open
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
7 changes: 1 addition & 6 deletions api/src/components/notification/bulletin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,7 @@ export const createBulletin = async (
}

case I.NotificationActionTypeEnum.PUBLICATION_VERSION_LINKED_PREDECESSOR: {
// We use the previous version because this is the one with the link
if (!previousPublishedVersion) {
break;
}

const usersToBeNotified = await userService.getUsersWithDirectLinkFromVersion(previousPublishedVersion.id);
const usersToBeNotified = await userService.getUsersWithDirectLinkFromVersion(currentPublishedVersion.id);

entries = usersToBeNotified.map((user) => ({
userId: user.id,
Expand Down
48 changes: 0 additions & 48 deletions api/src/components/publicationVersion/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as I from 'interface';
import * as response from 'lib/response';
import * as publicationVersionService from 'publicationVersion/service';
import * as publicationService from 'publication/service';
import * as notificationBulletin from 'notification/bulletin';
import * as coAuthorService from 'coAuthor/service';
import * as userService from 'user/service';
import * as Helpers from 'lib/helpers';
Expand Down Expand Up @@ -359,53 +358,6 @@ export const updateStatus = async (
event.queryStringParameters.ariContactConsent
);

const excludedUserIds = publicationVersion.coAuthors
.map((coAuthor) => coAuthor.linkedUser)
.filter((i): i is string => i !== null);

const previousPublishedVersion = await publicationVersionService.getPreviousPublishedVersion(
publicationVersion.versionOf
);

await Promise.all([
// Notifies all users that bookmarked this publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_BOOKMARK_VERSION_CREATED,
publicationVersion,
previousPublishedVersion
),

// Notify all users that red-flagged this publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_RED_FLAG_RAISED,
publicationVersion,
previousPublishedVersion
),

// Notifies authors that peer-reviewed this publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_PEER_REVIEWED,
publicationVersion,
previousPublishedVersion
),

// Notifies authors of child publications (that link FROM this publication)
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_LINKED_PREDECESSOR,
publicationVersion,
previousPublishedVersion,
{ excludedUserIds }
),

// Notifies authors of parent publications (that this publication links TO)
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_LINKED_SUCCESSOR,
publicationVersion,
previousPublishedVersion,
{ excludedUserIds }
)
]);

return response.json(200, { message: 'Publication is now LIVE.' });
} catch (err) {
console.log(err);
Expand Down
53 changes: 52 additions & 1 deletion api/src/components/publicationVersion/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import nodemailer from 'nodemailer';
import { convert } from 'html-to-text';
import { createId } from '@paralleldrive/cuid2';
import { Prisma } from '@prisma/client';

import * as notificationBulletin from 'notification/bulletin';
import * as client from 'lib/client';
import * as doi from 'lib/doi';
import * as email from 'lib/email';
Expand Down Expand Up @@ -700,6 +700,54 @@ export const transferOwnership = (publicationVersionId: string, requesterId: str
}
});

const createBulletinNotifications = async (
publicationVersion: I.PublicationVersion,
previousVersion: I.PublicationVersion | null
) => {
const excludedUserIds = publicationVersion.coAuthors
.map((coAuthor) => coAuthor.linkedUser)
.filter((i): i is string => i !== null);

await Promise.all([
// Notifies all users that bookmarked this publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_BOOKMARK_VERSION_CREATED,
publicationVersion,
previousVersion
),

// Notify all users that red-flagged the previous publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_RED_FLAG_RAISED,
publicationVersion,
previousVersion
),

// Notifies authors that peer-reviewed the previous publication version that a new version is now LIVE.
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_PEER_REVIEWED,
publicationVersion,
previousVersion
),

// Notifies authors of PARENT publications (that link from this publication)
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_LINKED_PREDECESSOR,
publicationVersion,
previousVersion,
{ excludedUserIds }
),

// Notifies authors of CHILD publications (that link to the previous version of this publication)
notificationBulletin.createBulletin(
I.NotificationActionTypeEnum.PUBLICATION_VERSION_LINKED_SUCCESSOR,
publicationVersion,
previousVersion,
{ excludedUserIds }
)
]);
};

// Actions that run after a version is published (changes status to LIVE).
// Pulled out to a separate function because things may need to run when something is
// published immediately (i.e. not going through full drafting workflow) and bypasses the updateStatus function.
Expand Down Expand Up @@ -822,6 +870,9 @@ export const postPublishHook = async (publicationVersion: I.PublicationVersion,
// Complete remaining tasks in parallel.
const postDBUpdatePromises: Array<Promise<unknown>> = [];

// Notifications
postDBUpdatePromises.push(createBulletinNotifications(publicationVersion, previousVersion));

// (Re)index publication in opensearch.
postDBUpdatePromises.push(
new Promise((resolve) => {
Expand Down