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

Show previous admin user addresses in adminJS #1744

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions migration/1722549878186-addAdminAddressHistoryToProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

export class AddAdminAddressHistoryToProject1722549878186
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumn(
'project',
new TableColumn({
name: 'adminAddressHistory',
type: 'text',
isArray: true,
isNullable: true,
}),
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn('project', 'adminAddressHistory');
}
}
4 changes: 4 additions & 0 deletions src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,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,
Expand Down Expand Up @@ -1030,6 +1041,14 @@ export const projectsTab = {
const adminUser = await User.findOne({
where: { id: request?.record?.params?.newAdminId },
});
const previousAdminAddress = project.adminUser.walletAddress;
if (previousAdminAddress) {
if (project.adminAddressHistory) {
project.adminAddressHistory.push(previousAdminAddress);
} else {
project.adminAddressHistory = [previousAdminAddress];
}
}
Comment on lines +1044 to +1051
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the previous admin user exists before accessing the wallet address.

The code assumes that project.adminUser always exists. Add a check to avoid potential runtime errors.

- const previousAdminAddress = project.adminUser.walletAddress;
+ const previousAdminAddress = project.adminUser ? project.adminUser.walletAddress : null;
+ if (previousAdminAddress) {
+   if (project.adminAddressHistory) {
+     project.adminAddressHistory.push(previousAdminAddress);
+   } else {
+     project.adminAddressHistory = [previousAdminAddress];
+   }
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const previousAdminAddress = project.adminUser.walletAddress;
if (previousAdminAddress) {
if (project.adminAddressHistory) {
project.adminAddressHistory.push(previousAdminAddress);
} else {
project.adminAddressHistory = [previousAdminAddress];
}
}
const previousAdminAddress = project.adminUser ? project.adminUser.walletAddress : null;
if (previousAdminAddress) {
if (project.adminAddressHistory) {
project.adminAddressHistory.push(previousAdminAddress);
} else {
project.adminAddressHistory = [previousAdminAddress];
}
}

project.adminUser = adminUser!;
await project.save();
}
Expand Down
Loading