Skip to content

Commit

Permalink
Merge pull request #311 from logion-network/feature/decentralize-dir
Browse files Browse the repository at this point in the history
Decentralize directory
  • Loading branch information
benoitdevos authored Jun 18, 2024
2 parents f7caf9d + ae99aef commit 5b14acc
Show file tree
Hide file tree
Showing 30 changed files with 775 additions and 146 deletions.
1 change: 0 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ JWT_ISSUER=12D3KooWDCuGU7WY3VaWjBS1E44x4EnmTgK3HRxWFqYG3dqXDfP1 # Replace this v
JWT_TTL_SEC=3600 # TTL of issued JWT tokens
OWNER=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY # Alice
HEALTH_TOKEN="change-me-please"
DIRECTORY_URL=http://localhost:8090
BASE_URL=http://localhost:8080

# E-mail
Expand Down
3 changes: 1 addition & 2 deletions resources/mail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ contain only variables, which are replaced at runtime with their respective valu
All possible variables are available (for copy/paste) in this template: [all-documented-vars.pug](all-documented-vars.pug)

### Legal Officer
legalOfficer.address
legalOfficer.account.address
legalOfficer.additionalDetails
legalOfficer.node

legalOfficer.userIdentity.firstName
legalOfficer.userIdentity.lastName
Expand Down
19 changes: 0 additions & 19 deletions resources/mail/all-documented-vars.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
| === Legal Officer ===
| #{legalOfficer.address};
| #{legalOfficer.additionalDetails};
| #{legalOfficer.node};
|
| #{legalOfficer.userIdentity.firstName};
| #{legalOfficer.userIdentity.lastName};
Expand All @@ -17,26 +16,8 @@
| #{legalOfficer.postalAddress.city};
| #{legalOfficer.postalAddress.country};
|
| === Other Legal Officer ===
| #{otherLegalOfficer.address};
| #{otherLegalOfficer.additionalDetails};
| #{otherLegalOfficer.node};
|
| #{otherLegalOfficer.userIdentity.firstName};
| #{otherLegalOfficer.userIdentity.lastName};
| #{otherLegalOfficer.userIdentity.email};
| #{otherLegalOfficer.userIdentity.phoneNumber};
|
| #{otherLegalOfficer.postalAddress.company};
| #{otherLegalOfficer.postalAddress.line1};
| #{otherLegalOfficer.postalAddress.line2};
| #{otherLegalOfficer.postalAddress.postalCode};
| #{otherLegalOfficer.postalAddress.city};
| #{otherLegalOfficer.postalAddress.country};
|
| === Account Recovery ===
| #{recovery.requesterAddress.address};
| #{recovery.otherLegalOfficerAddress};
| #{recovery.addressToRecover};
| #{recovery.createdOn};
|
Expand Down
2 changes: 1 addition & 1 deletion resources/mail/legal-officer-details.pug
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
|
| Identification key:
| ********************
| #{legalOfficer.address}
| #{legalOfficer.account.address}
|
| Email:
| *******
Expand Down
64 changes: 64 additions & 0 deletions resources/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,70 @@
"description": "The ID of the Secret Recovery"
}
}
},
"FetchLegalOfficersView": {
"type": "object",
"properties": {
"legalOfficers": {
"type": "array",
"description": "All the legal officers",
"items": {
"$ref": "#/components/schemas/LegalOfficerView"
}
}
},
"title": "FetchLegalOfficersView",
"description": "The fetched Legal Officers"
},
"LegalOfficerView": {
"type": "object",
"properties": {
"address": {
"type": "string",
"description": "The SS58 address of the legal officer"
},
"userIdentity": {
"$ref": "#/components/schemas/UserIdentityView"
},
"postalAddress": {
"$ref": "#/components/schemas/LegalOfficerPostalAddressView"
},
"additionalDetails": {
"type": "string",
"description": "Any additional public info"
}
},
"title": "LegalOfficerView",
"description": "The Legal Officer"
},
"CreateOrUpdateLegalOfficerView": {
"type": "object",
"properties": {
"userIdentity": {
"$ref": "#/components/schemas/UserIdentityView"
},
"postalAddress": {
"$ref": "#/components/schemas/LegalOfficerPostalAddressView"
},
"additionalDetails": {
"type": "string",
"description": "Any additional public info"
}
},
"title": "CreateOrUpdateLegalOfficerView",
"description": "The Legal Officer info to created or updated"
},
"LegalOfficerPostalAddressView": {
"type": "object",
"allOf": [{
"$ref": "#/components/schemas/PostalAddressView"
}],
"properties": {
"company": {
"type": "string",
"description": "The company of the Legal Officer"
}
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/logion/app.support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { fillInSpec as fillInSpecTokensRecord, TokensRecordController } from "./
import { fillInSpec as fillInSpecWorkload, WorkloadController } from "./controllers/workload.controller.js";
import { fillInSpec as fillInSpecSecretRecovery, SecretRecoveryController } from "./controllers/secret_recovery.controller.js";
import { fillInSpec as fillInSpecRecovery, RecoveryController } from "./controllers/recovery.controller.js";
import { fillInSpec as fillInSpecLegalOfficer, LegalOfficerController } from "./controllers/legalofficer.controller.js";

const { logger } = Log;

Expand Down Expand Up @@ -66,6 +67,7 @@ export function predefinedSpec(spec: OpenAPIV3.Document): OpenAPIV3.Document {
fillInSpecWorkload(spec);
fillInSpecSecretRecovery(spec);
fillInSpecRecovery(spec);
fillInSpecLegalOfficer(spec);

return spec;
}
Expand Down Expand Up @@ -130,6 +132,7 @@ export function setupApp(expressConfig?: ExpressConfig): Express {
dino.registerController(WorkloadController);
dino.registerController(SecretRecoveryController);
dino.registerController(RecoveryController);
dino.registerController(LegalOfficerController);

dino.dependencyResolver<Container>(AppContainer,
(injector, type) => {
Expand Down
10 changes: 8 additions & 2 deletions src/logion/container/app.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { TransactionController } from '../controllers/transaction.controller.js'
import { CollectionRepository, CollectionFactory } from "../model/collection.model.js";
import { NotificationService } from "../services/notification.service.js";
import { MailService } from "../services/mail.service.js";
import { DirectoryService } from "../services/directory.service.js";
import { LegalOfficerService, TransactionalLegalOfficerService } from "../services/legalOfficerService.js";
import { LegalOfficerController } from "../controllers/legalofficer.controller.js";
import { LegalOfficerRepository, LegalOfficerFactory } from "../model/legalofficer.model.js";
import { VaultTransferRequestController } from '../controllers/vaulttransferrequest.controller.js';
import { VaultTransferRequestFactory, VaultTransferRequestRepository } from '../model/vaulttransferrequest.model.js';
import { LoFileFactory, LoFileRepository } from "../model/lofile.model.js";
Expand Down Expand Up @@ -96,7 +98,10 @@ container.bind(CollectionFactory).toSelf()
container.bind(LogionNodeCollectionService).toSelf();
container.bind(NotificationService).toSelf()
container.bind(MailService).toSelf()
container.bind(DirectoryService).toSelf()
container.bind(LegalOfficerService).toService(TransactionalLegalOfficerService);
container.bind(TransactionalLegalOfficerService).toSelf();
container.bind(LegalOfficerFactory).toSelf();
container.bind(LegalOfficerRepository).toSelf();
container.bind(VaultTransferRequestRepository).toSelf();
container.bind(VaultTransferRequestFactory).toSelf();
container.bind(LoFileFactory).toSelf();
Expand Down Expand Up @@ -177,5 +182,6 @@ container.bind(TokensRecordController).toSelf().inTransientScope();
container.bind(WorkloadController).toSelf().inTransientScope();
container.bind(SecretRecoveryController).toSelf().inTransientScope();
container.bind(RecoveryController).toSelf().inTransientScope();
container.bind(LegalOfficerController).toSelf().inTransientScope();

export { container as AppContainer };
10 changes: 4 additions & 6 deletions src/logion/controllers/account_recovery.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../model/account_recovery.model.js';
import { components } from './components.js';
import { NotificationService, Template, NotificationRecipient } from "../services/notification.service.js";
import { DirectoryService } from "../services/directory.service.js";
import { LegalOfficerService } from "../services/legalOfficerService.js";
import { AccountRecoveryRequestService } from '../services/accountrecoveryrequest.service.js';
import { LocalsObject } from 'pug';
import { LocRequestAdapter, UserPrivateData } from "./adapters/locrequestadapter.js";
Expand Down Expand Up @@ -91,7 +91,7 @@ export class AccountRecoveryController extends ApiController {
private accountRecoveryRequestFactory: AccountRecoveryRequestFactory,
private authenticationService: AuthenticationService,
private notificationService: NotificationService,
private directoryService: DirectoryService,
private legalOfficerService: LegalOfficerService,
private accountRecoveryRequestService: AccountRecoveryRequestService,
private locRequestAdapter: LocRequestAdapter,
private locRequestRepository: LocRequestRepository,
Expand All @@ -114,7 +114,7 @@ export class AccountRecoveryController extends ApiController {
@HttpPost('')
async createRequest(body: CreateAccountRecoveryRequestView): Promise<AccountRecoveryRequestView> {
const requester = await this.authenticationService.authenticatedUser(this.request);
const legalOfficerAddress = await this.directoryService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress);
const legalOfficerAddress = await this.legalOfficerService.requireLegalOfficerAddressOnNode(body.legalOfficerAddress);
const requesterIdentityLoc = requireDefined(body.requesterIdentityLoc);
const request = await this.accountRecoveryRequestFactory.newAccountRecoveryRequest({
id: uuid(),
Expand Down Expand Up @@ -314,16 +314,14 @@ export class AccountRecoveryController extends ApiController {
private async getNotificationInfo(request: AccountRecoveryRequestDescription, userPrivateData?: UserPrivateData, decision?: LegalOfficerDecisionDescription):
Promise<{ legalOfficerEMail: string, userEmail: string | undefined, data: LocalsObject }> {

const legalOfficer = await this.directoryService.get(request.legalOfficerAddress)
const otherLegalOfficer = await this.directoryService.get(request.otherLegalOfficerAddress)
const legalOfficer = await this.legalOfficerService.get(request.legalOfficerAddress)
const { userIdentity, userPostalAddress } = userPrivateData ? userPrivateData : await this.locRequestAdapter.getUserPrivateData(request.requesterIdentityLocId)
return {
legalOfficerEMail: legalOfficer.userIdentity.email,
userEmail: userIdentity?.email,
data: {
recovery: { ...request, decision },
legalOfficer,
otherLegalOfficer,
walletUser: userIdentity,
walletUserPostalAddress: userPostalAddress
}
Expand Down
34 changes: 34 additions & 0 deletions src/logion/controllers/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,40 @@ export interface components {
/** @description The ID of the Secret Recovery */
id?: string;
};
/**
* FetchLegalOfficersView
* @description The fetched Legal Officers
*/
FetchLegalOfficersView: {
/** @description All the legal officers */
legalOfficers?: components["schemas"]["LegalOfficerView"][];
};
/**
* LegalOfficerView
* @description The Legal Officer
*/
LegalOfficerView: {
/** @description The SS58 address of the legal officer */
address?: string;
userIdentity?: components["schemas"]["UserIdentityView"];
postalAddress?: components["schemas"]["LegalOfficerPostalAddressView"];
/** @description Any additional public info */
additionalDetails?: string;
};
/**
* CreateOrUpdateLegalOfficerView
* @description The Legal Officer info to created or updated
*/
CreateOrUpdateLegalOfficerView: {
userIdentity?: components["schemas"]["UserIdentityView"];
postalAddress?: components["schemas"]["LegalOfficerPostalAddressView"];
/** @description Any additional public info */
additionalDetails?: string;
};
LegalOfficerPostalAddressView: {
/** @description The company of the Legal Officer */
company?: string;
} & components["schemas"]["PostalAddressView"];
};
responses: never;
parameters: never;
Expand Down
Loading

0 comments on commit 5b14acc

Please sign in to comment.