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
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
12 changes: 12 additions & 0 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
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 changeLog = 'previous admin user address: ' + project.adminUser.walletAddress;
+ const changeLog = project.adminUser
+   ? 'previous admin user address: ' + project.adminUser.walletAddress
+   : 'previous admin user address not available';
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 changeLog =
'previous admin user address: ' +
project.adminUser.walletAddress;
const changeLog = project.adminUser
? 'previous admin user address: ' + project.adminUser.walletAddress
: 'previous admin user address not available';

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,
});
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 ProjectUpdate insertion handles errors gracefully.

The current code does not handle potential errors during the insertion of the ProjectUpdate record. Add error handling to ensure robustness.

- await ProjectUpdate.insert({
-   userId: currentAdmin.id,
-   projectId: project.id,
-   content: changeLog,
-   title: 'admin user changed',
-   createdAt: moment().toDate(),
-   isMain: false,
- });
+ try {
+   await ProjectUpdate.insert({
+     userId: currentAdmin.id,
+     projectId: project.id,
+     content: changeLog,
+     title: 'admin user changed',
+     createdAt: moment().toDate(),
+     isMain: false,
+   });
+ } catch (error) {
+   logger.error('Failed to insert project update', error);
+ }
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
await ProjectUpdate.insert({
userId: currentAdmin.id,
projectId: project.id,
content: changeLog,
title: 'admin user changed',
createdAt: moment().toDate(),
isMain: false,
});
try {
await ProjectUpdate.insert({
userId: currentAdmin.id,
projectId: project.id,
content: changeLog,
title: 'admin user changed',
createdAt: moment().toDate(),
isMain: false,
});
} catch (error) {
logger.error('Failed to insert project update', error);
}

}
// Not required for now
// Project.notifySegment(project, SegmentEvents.PROJECT_EDITED);
Expand Down
Loading