Skip to content

Commit

Permalink
fix: update new sys admin scope in events middleware (#8315)
Browse files Browse the repository at this point in the history
* fix: update new sys admin scope in events middleware

* fix: update scopes in events package
  • Loading branch information
Nil20 authored Jan 10, 2025
1 parent f68d20d commit ab88d0f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
6 changes: 2 additions & 4 deletions packages/events/src/router/locations.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
*/
import { createTestClient } from '@events/tests/utils'
import { payloadGenerator } from '@events/tests/generators'
import { userScopes } from '@opencrvs/commons'
import { SCOPES } from '@opencrvs/commons'

const nationalSystemAdminClient = createTestClient([
userScopes.nationalSystemAdmin
])
const nationalSystemAdminClient = createTestClient([SCOPES.CONFIG_UPDATE_ALL])
const generator = payloadGenerator()

test('Returns empty list when no locations are set', async () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/events/src/router/locations.set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
*/
import { createTestClient } from '@events/tests/utils'
import { payloadGenerator } from '@events/tests/generators'
import { userScopes } from '@opencrvs/commons'
import { SCOPES } from '@opencrvs/commons'

const nationalSystemAdminClient = createTestClient([
userScopes.nationalSystemAdmin
])
const nationalSystemAdminClient = createTestClient([SCOPES.CONFIG_UPDATE_ALL])

const registrarClient = createTestClient()

Expand Down
4 changes: 2 additions & 2 deletions packages/events/src/router/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { inScope, Scope, userScopes } from '@opencrvs/commons'
import { inScope, Scope, SCOPES } from '@opencrvs/commons'
import { TRPCError, AnyTRPCMiddlewareFunction } from '@trpc/server'

import { z } from 'zod'
Expand Down Expand Up @@ -56,7 +56,7 @@ const createScopeAuthMiddleware =
}

const isNationalSystemAdminUser = createScopeAuthMiddleware([
userScopes.nationalSystemAdmin
SCOPES.CONFIG_UPDATE_ALL
])

export const middleware = {
Expand Down
4 changes: 2 additions & 2 deletions packages/events/src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { appRouter, t } from '@events/router'
import * as jwt from 'jsonwebtoken'
import { readFileSync } from 'fs'
import { join } from 'path'
import { Scope, userRoleScopes } from '@opencrvs/commons'
import { Scope, SCOPES } from '@opencrvs/commons'

const { createCallerFactory } = t

Expand All @@ -30,7 +30,7 @@ export function createTestClient(scopes?: Scope[]) {

const createTestToken = (scopes?: Scope[]) =>
jwt.sign(
{ scope: scopes ?? userRoleScopes.REGISTRATION_AGENT },
{ scope: scopes ?? SCOPES.RECORD_SUBMIT_FOR_APPROVAL },
readFileSync(join(__dirname, './cert.key')),
{
algorithm: 'RS256',
Expand Down

0 comments on commit ab88d0f

Please sign in to comment.