Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: amend data seeder with scopes #7898

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading