From b367d4ce3b3c3ccc9d97f28f36e9767068177b40 Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Thu, 1 Aug 2024 06:35:37 +0330 Subject: [PATCH 1/3] Save admin user changes on project update --- src/server/adminJs/tabs/projectsTab.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/server/adminJs/tabs/projectsTab.ts b/src/server/adminJs/tabs/projectsTab.ts index d0cf6fbe2..9c819f750 100644 --- a/src/server/adminJs/tabs/projectsTab.ts +++ b/src/server/adminJs/tabs/projectsTab.ts @@ -7,6 +7,7 @@ import { After, } from 'adminjs/src/backend/actions/action.interface'; import { RecordJSON } from 'adminjs/src/frontend/interfaces/record-json.interface'; +import moment from 'moment/moment'; import { Project, ProjectUpdate, @@ -1030,8 +1031,19 @@ export const projectsTab = { const adminUser = await User.findOne({ where: { id: request?.record?.params?.newAdminId }, }); + const changeLog = + 'previous admin user address: ' + + project.adminUser.walletAddress; project.adminUser = adminUser!; await project.save(); + await ProjectUpdate.insert({ + userId: currentAdmin.id, + projectId: project.id, + content: changeLog, + title: 'admin user changed', + createdAt: moment().toDate(), + isMain: false, + }); } // Not required for now // Project.notifySegment(project, SegmentEvents.PROJECT_EDITED); From 22a6e3f6e860113aa18b8baacea37d4b6f187137 Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Fri, 2 Aug 2024 02:12:51 +0330 Subject: [PATCH 2/3] Add adminAddressHistory field to project --- ...9878186-addAdminAddressHistoryToProject.ts | 21 +++++++++++++++++++ src/entities/project.ts | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 migration/1722549878186-addAdminAddressHistoryToProject.ts diff --git a/migration/1722549878186-addAdminAddressHistoryToProject.ts b/migration/1722549878186-addAdminAddressHistoryToProject.ts new file mode 100644 index 000000000..53c5224ba --- /dev/null +++ b/migration/1722549878186-addAdminAddressHistoryToProject.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; + +export class AddAdminAddressHistoryToProject1722549878186 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn( + 'project', + new TableColumn({ + name: 'adminAddressHistory', + type: 'text', + isArray: true, + isNullable: true, + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn('project', 'adminAddressHistory'); + } +} diff --git a/src/entities/project.ts b/src/entities/project.ts index 83adb224c..215ec0047 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -439,6 +439,10 @@ export class Project extends BaseEntity { @Field(_type => [Campaign], { nullable: true }) campaigns: Campaign[]; + @Field(_type => [String], { nullable: true }) + @Column('text', { array: true, nullable: true }) + adminAddressHistory: string[]; + // only projects with status active can be listed automatically static pendingReviewSince(maximumDaysForListing: number) { const maxDaysForListing = moment() From 36b912fc60b7bca134a37c1532e6616be6538cfc Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Fri, 2 Aug 2024 02:15:14 +0330 Subject: [PATCH 3/3] fill and show adminAddressHistory field in the projectsTab of adminJS --- src/server/adminJs/tabs/projectsTab.ts | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/server/adminJs/tabs/projectsTab.ts b/src/server/adminJs/tabs/projectsTab.ts index 9c819f750..11dca8670 100644 --- a/src/server/adminJs/tabs/projectsTab.ts +++ b/src/server/adminJs/tabs/projectsTab.ts @@ -7,7 +7,6 @@ import { After, } from 'adminjs/src/backend/actions/action.interface'; import { RecordJSON } from 'adminjs/src/frontend/interfaces/record-json.interface'; -import moment from 'moment/moment'; import { Project, ProjectUpdate, @@ -716,6 +715,17 @@ export const projectsTab = { }, position: 1, }, + adminAddressHistory: { + type: 'string[]', + isVisible: { + list: false, + filter: false, + show: true, + edit: false, + new: false, + }, + position: 2, + }, contacts: { isVisible: { list: false, @@ -1031,19 +1041,16 @@ export const projectsTab = { const adminUser = await User.findOne({ where: { id: request?.record?.params?.newAdminId }, }); - const changeLog = - 'previous admin user address: ' + - project.adminUser.walletAddress; + const previousAdminAddress = project.adminUser.walletAddress; + if (previousAdminAddress) { + if (project.adminAddressHistory) { + project.adminAddressHistory.push(previousAdminAddress); + } else { + project.adminAddressHistory = [previousAdminAddress]; + } + } project.adminUser = adminUser!; await project.save(); - await ProjectUpdate.insert({ - userId: currentAdmin.id, - projectId: project.id, - content: changeLog, - title: 'admin user changed', - createdAt: moment().toDate(), - isMain: false, - }); } // Not required for now // Project.notifySegment(project, SegmentEvents.PROJECT_EDITED);