Skip to content

Commit

Permalink
Merge pull request #21 from Giveth/feature_add_admin_for_multisig_ses…
Browse files Browse the repository at this point in the history
…sion

add multisig session admin tab
  • Loading branch information
CarlosQ96 authored Nov 29, 2023
2 parents 15a4547 + 9f92bdd commit 7639ff4
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions migrations/1701273095150-addDefaultAdminUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Admin, AdminRole } from '@/src/entities/admin';
import { MigrationInterface, QueryRunner } from 'typeorm';
const bcrypt = require('bcrypt');

Check warning on line 3 in migrations/1701273095150-addDefaultAdminUser.ts

View workflow job for this annotation

GitHub Actions / test

Require statement not part of import statement

export class addDefaultAdminUser1701273095150 implements MigrationInterface {
private defaultAdminEmail = '[email protected]';

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.manager
.createQueryBuilder()
.delete()
.from(Admin)
.where('email = :email', { email: this.defaultAdminEmail })
.execute();
}
}
1 change: 1 addition & 0 deletions src/repositories/multisigSessionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const findNonExpiredMultisigSessions = async (
.andWhere('lower("multisigAddress") = :multisigAddress', {
multisigAddress: multisigAddress.toLowerCase(),
})
.andWhere('active = true')
.orderBy('"createdAt"', 'DESC')
.getOne();

Expand Down
103 changes: 103 additions & 0 deletions src/routes/v1/adminbroRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 7639ff4

Please sign in to comment.