Skip to content

Commit

Permalink
Merge pull request #1796 from serlo/staging
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
hugotiburtino authored Nov 9, 2024
2 parents dde84f4 + c3de5bc commit bfa2c80
Show file tree
Hide file tree
Showing 43 changed files with 268 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-migration-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Build and push Docker image
run: |
cd packages/db-migrations
DOCKER_REGISTRY=ghcr.io DOCKER_REPOSITORY=$(echo $GITHUB_REPOSITORY)/db-migration lerna run --stream push-image
DOCKER_REGISTRY=ghcr.io DOCKER_REPOSITORY=$(echo $GITHUB_REPOSITORY)/db-migration yarn push-image
env:
DOCKER_REGISTRY: ghcr.io
DOCKER_REPOSITORY: ${{ github.repository }}/db-migration
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/nx-npm-19.2.3-4610c51ee8-11cd6b5e4f.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/pg-npm-8.12.0-85d43dc352-8450b61c78.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions __tests__/schema/user/add-role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ test('updates the cache', async () => {
})
})

test('Is successful even when user has already role', async () => {
await uuidQuery.shouldReturnData({
uuid: {
roles: {
nodes: [{ role: Role.Login, scope: Scope.Serlo }],
},
},
})
await mutation
.withInput({ username: regularUser.username, role: Role.Login })
.execute()
await uuidQuery.shouldReturnData({
uuid: {
roles: {
nodes: [{ role: Role.Login, scope: Scope.Serlo }],
},
},
})
})

test('fails when user is not authenticated', async () => {
await mutation.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})
Expand Down
23 changes: 16 additions & 7 deletions packages/server/src/schema/uuid/user/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,29 @@ export const resolvers: Resolvers = {
throw new UserInputError('no user with given username')
}

const userHasAlreadyRole = await database.fetchOptional(
`
SELECT 1
FROM role_user
WHERE user_id = ?
AND role_id = ( SELECT id
FROM role
WHERE name = ?)`,
[id, generateRole(role, instance)],
)

if (userHasAlreadyRole) {
return { success: true, query: {} }
}

await database.mutate(
`
INSERT INTO role_user (user_id, role_id)
SELECT ?, role.id
FROM role
WHERE role.name = ?
AND NOT EXISTS (
SELECT 1
FROM role_user
WHERE role_user.user_id = ?
AND role_user.role_id = role.id
)
`,
[id, generateRole(role, instance), id],
[id, generateRole(role, instance)],
)

await UuidResolver.removeCacheEntry({ id }, context)
Expand Down
Loading

0 comments on commit bfa2c80

Please sign in to comment.