Skip to content

Commit

Permalink
call notify project ownership change method in projects tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Aug 5, 2024
1 parent ef55167 commit 59490d8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { User } from '../../../entities/user';
import { refreshProjectEstimatedMatchingView } from '../../../services/projectViewsService';
import { extractAdminJsReferrerUrlParams } from '../adminJs';
import { relateManyProjectsToQfRound } from '../../../repositories/qfRoundRepository2';
import { NotificationCenterAdapter } from '../../../adapters/notifications/NotificationCenterAdapter';

// add queries depending on which filters were selected
export const buildProjectsQuery = (
Expand Down Expand Up @@ -658,6 +659,22 @@ export const exportProjectsWithFiltersToCsv = async (
};
}
};

async function sendOwnershipChangeEmails(
project: Project,
previousOwnerUser: User | null,
newOwnerUser: User | null,
) {
const notificationCenter = new NotificationCenterAdapter();

const params = {
previousOwnerUser,
newOwnerUser,
projectName: project.title,
};
await notificationCenter.notifyProjectOwnershipChange(params);
}

export const projectsTab = {
resource: Project,
options: {
Expand Down Expand Up @@ -1082,9 +1099,10 @@ export const projectsTab = {
});
if (project) {
if (request?.record?.params?.adminChanged) {
const adminUser = await User.findOne({
const newAdminUser = await User.findOne({
where: { id: request?.record?.params?.newAdminId },
});
const previousAdminUser = project.adminUser;
const previousAdminAddress = project.adminUser?.walletAddress;
if (previousAdminAddress) {
if (project.adminAddressHistory) {
Expand All @@ -1093,8 +1111,13 @@ export const projectsTab = {
project.adminAddressHistory = [previousAdminAddress];
}
}
project.adminUser = adminUser!;
project.adminUser = newAdminUser!;
await project.save();
await sendOwnershipChangeEmails(
project,
previousAdminUser,
newAdminUser,
);
}
// Not required for now
// Project.notifySegment(project, SegmentEvents.PROJECT_EDITED);
Expand Down

0 comments on commit 59490d8

Please sign in to comment.