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

transfer owner ship of project by address #1749

Open
wants to merge 2 commits into
base: 1722-showAdminWalletAddress
Choose a base branch
from
Open
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
44 changes: 40 additions & 4 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import fs from 'fs';
import path from 'path';
import adminJs from 'adminjs';
import adminJs, { ValidationError } from 'adminjs';
import { SelectQueryBuilder } from 'typeorm';
import {
ActionResponse,
After,
} from 'adminjs/src/backend/actions/action.interface';
import { RecordJSON } from 'adminjs/src/frontend/interfaces/record-json.interface';
import { ethers } from 'ethers';
import {
Project,
ProjectUpdate,
Expand Down Expand Up @@ -726,7 +727,7 @@ export const projectsTab = {
filter: false,
list: false,
show: true,
edit: false,
edit: true,
new: false,
},
position: 2,
Expand Down Expand Up @@ -968,7 +969,7 @@ export const projectsTab = {
canAccessProjectAction({ currentAdmin }, ResourceActions.EDIT),

before: async (request: AdminJsRequestInterface) => {
const { verified, reviewStatus } = request.payload;
const { verified, reviewStatus, adminUserAddress } = request.payload;
const statusChanges: string[] = [];
if (request?.payload?.id) {
// remove addresses from payload to avoid updating them
Expand Down Expand Up @@ -1037,6 +1038,41 @@ export const projectsTab = {
request.payload.adminChanged = true;
request.payload.newAdminId = newID;
}
if (adminUserAddress) {
if (!ethers.utils.isAddress(adminUserAddress)) {
throw new ValidationError({
adminUserAddress: {
message:
'The address is malformed or not a valid Ethereum address',
},
});
}

const newAdminUser = await User.findOne({
where: { walletAddress: adminUserAddress },
});
if (!newAdminUser) {
throw new ValidationError({
adminUserAddress: {
message:
'The address does not correspond to a valid user profile',
},
});
}

if (!newAdminUser.name || !newAdminUser.email) {
throw new ValidationError({
adminUserAddress: {
message: 'The user profile is not completed',
},
});
}

if (newAdminUser.id !== project?.adminUserId) {
request.payload.adminChanged = true;
request.payload.newAdminId = newAdminUser.id;
}
}

// We put these status changes in payload, so in after hook we would know to send notification for users
request.payload.statusChanges = statusChanges.join(',');
Expand All @@ -1057,7 +1093,7 @@ export const projectsTab = {
const adminUser = await User.findOne({
where: { id: request?.record?.params?.newAdminId },
});
const previousAdminAddress = project.adminUser.walletAddress;
const previousAdminAddress = project.adminUser?.walletAddress;
if (previousAdminAddress) {
if (project.adminAddressHistory) {
project.adminAddressHistory.push(previousAdminAddress);
Expand Down