diff --git a/src/api/procedures/__tests__/togglePauseRequirements.ts b/src/api/procedures/__tests__/togglePauseRequirements.ts index b677011650..f9e618acb1 100644 --- a/src/api/procedures/__tests__/togglePauseRequirements.ts +++ b/src/api/procedures/__tests__/togglePauseRequirements.ts @@ -134,9 +134,10 @@ describe('togglePauseRequirements procedure', () => { test('should return the appropriate roles and permissions', () => { const proc = procedureMockUtils.getInstance(mockContext); const boundFunc = getAuthorization.bind(proc); - const args = { + const args: Params = { ticker, - } as Params; + pause: true, + }; expect(boundFunc(args)).toEqual({ identityRoles: [{ type: RoleType.TokenOwner, ticker }], @@ -146,6 +147,17 @@ describe('togglePauseRequirements procedure', () => { portfolios: [], }, }); + + args.pause = false; + + expect(boundFunc(args)).toEqual({ + identityRoles: [{ type: RoleType.TokenOwner, ticker }], + signerPermissions: { + transactions: [TxTags.complianceManager.ResumeAssetCompliance], + tokens: [entityMockUtils.getSecurityTokenInstance({ ticker })], + portfolios: [], + }, + }); }); }); }); diff --git a/src/api/procedures/consumeJoinIdentityAuthorization.ts b/src/api/procedures/consumeJoinIdentityAuthorization.ts index 44bb3c4ec7..429240c33a 100644 --- a/src/api/procedures/consumeJoinIdentityAuthorization.ts +++ b/src/api/procedures/consumeJoinIdentityAuthorization.ts @@ -82,12 +82,13 @@ export async function getAuthorization( let transactions: TxTag[] = []; - let paidByThirdParty = false; + let bypassSignerPermissions = false; if (target instanceof Account) { const { address } = context.getCurrentAccount(); condition = address === target.address; - paidByThirdParty = condition; + // if the current account is joining an identity, it doesn't need (and couldn't possibly have) any permissions + bypassSignerPermissions = condition; } else { did = await fetchDid(); condition = did === target.did; @@ -106,7 +107,7 @@ export async function getAuthorization( const identityRoles = condition && !authRequest.isExpired(); - if (paidByThirdParty) { + if (bypassSignerPermissions) { return { identityRoles, }; diff --git a/src/api/procedures/modifySignerPermissions.ts b/src/api/procedures/modifySignerPermissions.ts index 83784fe1fe..e090c5e048 100644 --- a/src/api/procedures/modifySignerPermissions.ts +++ b/src/api/procedures/modifySignerPermissions.ts @@ -2,7 +2,7 @@ import P from 'bluebird'; import { assertSecondaryKeys } from '~/api/procedures/utils'; import { Procedure } from '~/internal'; -import { PermissionsLike, Signer } from '~/types'; +import { PermissionsLike, Signer, TxTags } from '~/types'; import { tuple } from '~/types/utils'; import { permissionsLikeToPermissions, @@ -64,4 +64,10 @@ export async function prepareModifySignerPermissions( /** * @hidden */ -export const modifySignerPermissions = new Procedure(prepareModifySignerPermissions); +export const modifySignerPermissions = new Procedure(prepareModifySignerPermissions, { + signerPermissions: { + transactions: [TxTags.identity.SetPermissionToSigner], + tokens: [], + portfolios: [], + }, +}); diff --git a/src/api/procedures/setTokenDocuments.ts b/src/api/procedures/setTokenDocuments.ts index d753b0c1ce..f34f44013f 100644 --- a/src/api/procedures/setTokenDocuments.ts +++ b/src/api/procedures/setTokenDocuments.ts @@ -86,7 +86,7 @@ export async function prepareSetTokenDocuments( } if (rawDocuments.length) { - batchArguments(rawDocuments, TxTags.asset.BatchAddDocument).forEach(rawDocumentBatch => { + batchArguments(rawDocuments, TxTags.asset.AddDocuments).forEach(rawDocumentBatch => { this.addTransaction( tx.asset.addDocuments, { batchSize: rawDocumentBatch.length }, diff --git a/src/api/procedures/togglePauseRequirements.ts b/src/api/procedures/togglePauseRequirements.ts index 45847d8dc8..016b110914 100644 --- a/src/api/procedures/togglePauseRequirements.ts +++ b/src/api/procedures/togglePauseRequirements.ts @@ -54,12 +54,16 @@ export async function prepareTogglePauseRequirements( */ export function getAuthorization( this: Procedure, - { ticker }: Params + { ticker, pause }: Params ): ProcedureAuthorization { return { identityRoles: [{ type: RoleType.TokenOwner, ticker }], signerPermissions: { - transactions: [TxTags.complianceManager.PauseAssetCompliance], + transactions: [ + pause + ? TxTags.complianceManager.PauseAssetCompliance + : TxTags.complianceManager.ResumeAssetCompliance, + ], tokens: [new SecurityToken({ ticker }, this.context)], portfolios: [], }, diff --git a/src/base/Procedure.ts b/src/base/Procedure.ts index e9de0c4ba8..107993a0f1 100644 --- a/src/base/Procedure.ts +++ b/src/base/Procedure.ts @@ -54,7 +54,7 @@ export class Procedure, args: Args - ) => Promise | boolean | Promise | ProcedureAuthorization; + ) => Promise | ProcedureAuthorization; private transactions: ( | PolymeshTransaction @@ -67,7 +67,7 @@ export class Procedure, args: Args - ) => - | Promise - | boolean - | Promise - | ProcedureAuthorization) = async (): Promise => true + ) => Promise | ProcedureAuthorization) = async (): Promise< + ProcedureAuthorization + > => ({}) ) { this.prepareTransactions = prepareTransactions; @@ -113,36 +111,36 @@ export class Procedure { context = dsMockUtils.getContextInstance({ hasRoles: false, hasPermissions: false }); await expect(proc.prepare(procArgs, context)).rejects.toThrow( - 'Current account is not authorized to execute this procedure' - ); - - proc = new Procedure(func, { identityRoles: false }); - - await expect(proc.prepare(procArgs, context)).rejects.toThrow( - 'Current account is not authorized to execute this procedure' + "Current Identity doesn't have the required roles to execute this procedure" ); proc = new Procedure(func, { @@ -200,7 +194,7 @@ describe('Procedure class', () => { }); await expect(proc.prepare(procArgs, context)).rejects.toThrow( - 'Current account is not authorized to execute this procedure' + "Current Account doesn't have the required permissions to execute this procedure" ); proc = new Procedure(func, { @@ -208,13 +202,13 @@ describe('Procedure class', () => { }); await expect(proc.prepare(procArgs, context)).rejects.toThrow( - 'Current account is not authorized to execute this procedure' + "Current Account doesn't have the required permissions to execute this procedure" ); - proc = new Procedure(func, async () => false); + proc = new Procedure(func, async () => ({ identityRoles: false })); await expect(proc.prepare(procArgs, context)).rejects.toThrow( - 'Current account is not authorized to execute this procedure' + "Current Identity doesn't have the required roles to execute this procedure" ); }); }); diff --git a/src/utils/__tests__/conversion.ts b/src/utils/__tests__/conversion.ts index df076cb974..8798cc64c9 100644 --- a/src/utils/__tests__/conversion.ts +++ b/src/utils/__tests__/conversion.ts @@ -3777,7 +3777,7 @@ describe('portfolioLikeToPortfolioId', () => { }); test('should convert a DID string to a PortfolioId', async () => { - const result = await portfolioLikeToPortfolioId(did); + const result = portfolioLikeToPortfolioId(did); expect(result).toEqual({ did, number: undefined }); }); @@ -3785,7 +3785,7 @@ describe('portfolioLikeToPortfolioId', () => { test('should convert an Identity to a PortfolioId', async () => { const identity = entityMockUtils.getIdentityInstance({ did }); - const result = await portfolioLikeToPortfolioId(identity); + const result = portfolioLikeToPortfolioId(identity); expect(result).toEqual({ did, number: undefined }); }); @@ -3793,7 +3793,7 @@ describe('portfolioLikeToPortfolioId', () => { test('should convert a NumberedPortfolio to a PortfolioId', async () => { const portfolio = new NumberedPortfolio({ did, id: number }, context); - const result = await portfolioLikeToPortfolioId(portfolio); + const result = portfolioLikeToPortfolioId(portfolio); expect(result).toEqual({ did, number }); }); @@ -3801,16 +3801,16 @@ describe('portfolioLikeToPortfolioId', () => { test('should convert a DefaultPortfolio to a PortfolioId', async () => { const portfolio = new DefaultPortfolio({ did }, context); - const result = await portfolioLikeToPortfolioId(portfolio); + const result = portfolioLikeToPortfolioId(portfolio); expect(result).toEqual({ did, number: undefined }); }); test('should convert a Portfolio identifier object to a PortfolioId', async () => { - let result = await portfolioLikeToPortfolioId({ identity: did, id: number }); + let result = portfolioLikeToPortfolioId({ identity: did, id: number }); expect(result).toEqual({ did, number }); - result = await portfolioLikeToPortfolioId({ + result = portfolioLikeToPortfolioId({ identity: entityMockUtils.getIdentityInstance({ did }), id: number, }); @@ -3846,12 +3846,12 @@ describe('portfolioLikeToPortfolio', () => { }); test('should convert a PortfolioLike to a DefaultPortfolio instance', async () => { - const result = await portfolioLikeToPortfolio(did, context); + const result = portfolioLikeToPortfolio(did, context); expect(result instanceof DefaultPortfolio).toBe(true); }); test('should convert a PortfolioLike to a NumberedPortfolio instance', async () => { - const result = await portfolioLikeToPortfolio({ identity: did, id }, context); + const result = portfolioLikeToPortfolio({ identity: did, id }, context); expect(result instanceof NumberedPortfolio).toBe(true); }); });