Skip to content

Commit

Permalink
chore: amend data seeder with scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil20 committed Nov 5, 2024
1 parent 0cd4934 commit b9b5c4a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/data-seeder/src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,27 @@ async function getUsers(token: string) {

const userRoles = parsedUsers.data.map((user) => user.role)

const rolesUrl = joinURL(COUNTRY_CONFIG_HOST, 'roles')
const rolesUrl = joinURL(env.COUNTRY_CONFIG_HOST, 'roles')

const response = await fetch(rolesUrl)

if (!response.ok) raise(`Error fetching roles: ${response.status}`)

const allRoles: Roles[] = await response.json()

let isNationalSysAdminScopeAvailable = false
let isConfigUpdateAllScopeAvailable = false
const configScope = 'config.update:all' as const

for (const userRole of userRoles) {
const currRole = allRoles.find((role: Roles) => role.id === userRole)
if (!currRole)
raise(`Role with id ${userRole} is not found in roles.json file`)
if (currRole.scopes.includes('natlsysadmin'))
isNationalSysAdminScopeAvailable = true
if (currRole.scopes.includes(configScope))
isConfigUpdateAllScopeAvailable = true
}

if (!isNationalSysAdminScopeAvailable) {
raise(`At least one user with "natlsysadmin" scope must be created`)
if (!isConfigUpdateAllScopeAvailable) {
raise(`At least one user with ${configScope} scope must be created`)
}
return parsedUsers.data
}
Expand Down

0 comments on commit b9b5c4a

Please sign in to comment.