From 35a33b29c0ea3dc9013ed6435a99e143325bc22a Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 29 Nov 2023 00:34:37 -0500 Subject: [PATCH 1/2] add multisig session admin tab --- src/repositories/multisigSessionRepository.ts | 1 + src/routes/v1/adminbroRouter.ts | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/src/repositories/multisigSessionRepository.ts b/src/repositories/multisigSessionRepository.ts index 7b49ac9..aab3140 100644 --- a/src/repositories/multisigSessionRepository.ts +++ b/src/repositories/multisigSessionRepository.ts @@ -33,6 +33,7 @@ export const findNonExpiredMultisigSessions = async ( .andWhere('lower("multisigAddress") = :multisigAddress', { multisigAddress: multisigAddress.toLowerCase(), }) + .andWhere('active = true') .orderBy('"createdAt"', 'DESC') .getOne(); diff --git a/src/routes/v1/adminbroRouter.ts b/src/routes/v1/adminbroRouter.ts index 87f1feb..3b01ea8 100644 --- a/src/routes/v1/adminbroRouter.ts +++ b/src/routes/v1/adminbroRouter.ts @@ -13,6 +13,7 @@ import { Database, Resource } from '@adminjs/typeorm'; import { logger } from '../../utils/logger'; import { AccessToken } from '../../entities/accessToken'; import { findAdminByEmail } from '../../repositories/adminRepository'; +import { MultisigSession } from '@/src/entities/multisigSession'; // eslint:disable-next-line:no-var-requires const RedisStore = require('connect-redis')(session); @@ -74,6 +75,108 @@ const getAdminBroInstance = async () => { softwareBrothers: false, }, resources: [ + { + resource: MultisigSession, + options: { + properties: { + multisigAddress: { + isVisible: { + list: true, + filter: true, + show: true, + edit: false, + new: false, + }, + }, + safeMessageHash: { + isVisible: { + list: false, + filter: false, + show: false, + edit: false, + new: false, + }, + }, + network: { + isVisible: { + list: true, + filter: true, + show: true, + edit: false, + new: false, + }, + }, + active: { + isVisible: { + list: true, + filter: true, + show: true, + edit: true, + new: false, + }, + }, + status: { + isVisible: { + list: true, + filter: true, + show: true, + edit: false, + new: false, + }, + }, + expirationDate: { + isVisible: { + list: false, + filter: false, + show: true, + edit: false, + new: false, + }, + }, + approvalExpirationDate: { + isVisible: { + list: false, + filter: false, + show: true, + edit: false, + new: false, + }, + }, + createdAt: { + isVisible: { + list: false, + filter: false, + show: true, + edit: false, + new: false, + }, + }, + updatedAt: { + isVisible: { + list: false, + filter: false, + show: true, + edit: false, + new: false, + }, + }, + }, + actions: { + delete: { + isVisible: false, + }, + bulkDelete: { + isVisible: false, + }, + new: { + isVisible: false, + }, + edit: { + isVisible: true, + }, + }, + }, + }, { resource: Admin, options: { From 9f92bdd81311f5757400111143c877598b53d9de Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 29 Nov 2023 13:56:17 -0500 Subject: [PATCH 2/2] add default user migration for local and staging development --- config/.env.example | 2 + .../1701273095150-addDefaultAdminUser.ts | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 migrations/1701273095150-addDefaultAdminUser.ts diff --git a/config/.env.example b/config/.env.example index 0344064..e2132b2 100644 --- a/config/.env.example +++ b/config/.env.example @@ -5,6 +5,8 @@ TYPEORM_DATABASE_USER=postgres TYPEORM_DATABASE_PASSWORD=postgres TYPEORM_DATABASE_HOST=127.0.0.1 TYPEORM_DATABASE_PORT=5443 +# Handle as local, develop, staging, production +ENVIRONMENT=local JWT_SECRET=fdksjalkfhjio472389roiewfhskjahfjka ACCESS_TOKEN_LIFETIME_HOURS=2000 diff --git a/migrations/1701273095150-addDefaultAdminUser.ts b/migrations/1701273095150-addDefaultAdminUser.ts new file mode 100644 index 0000000..8ee5a75 --- /dev/null +++ b/migrations/1701273095150-addDefaultAdminUser.ts @@ -0,0 +1,38 @@ +import { Admin, AdminRole } from '@/src/entities/admin'; +import { MigrationInterface, QueryRunner } from 'typeorm'; +const bcrypt = require('bcrypt'); + +export class addDefaultAdminUser1701273095150 implements MigrationInterface { + private defaultAdminEmail = 'admin@example.com'; + + public async up(queryRunner: QueryRunner): Promise { + const isStagingOrLocal = + process.env.ENVIRONMENT === 'local' || + process.env.ENVIRONMENT === 'staging' || + process.env.ENVIRONMENT === 'develop'; + + if (isStagingOrLocal) { + const defaultAdmin = new Admin(); + defaultAdmin.email = this.defaultAdminEmail; + const hash = await bcrypt.hash( + 'password', + Number(process.env.BCRYPT_SALT), + ); + defaultAdmin.encryptedPassword = hash; // Set your default password here + + // Assign a default role if needed + defaultAdmin.role = AdminRole.ADMIN; + + await queryRunner.manager.save(defaultAdmin); + } + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.manager + .createQueryBuilder() + .delete() + .from(Admin) + .where('email = :email', { email: this.defaultAdminEmail }) + .execute(); + } +}