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

Deployment #1796

Merged
merged 18 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1736825
chore(deps-dev): bump @google-cloud/storage from 7.13.0 to 7.14.0
dependabot[bot] Nov 4, 2024
ae5282e
chore(deps-dev): bump @apollo/server from 4.11.0 to 4.11.2
dependabot[bot] Nov 4, 2024
1c9d53e
chore(deps-dev): bump lerna from 8.1.8 to 8.1.9
dependabot[bot] Nov 4, 2024
c2fde0b
chore(deps-dev): bump @graphql-codegen/typescript-resolvers
dependabot[bot] Nov 4, 2024
bcb1727
chore(deps-dev): bump pg and @types/pg
dependabot[bot] Nov 4, 2024
173d7cd
fix(deadlock): avoid selecting while inserting
hugotiburtino Nov 4, 2024
bb2705c
Merge pull request #1795 from serlo/fix-deadlock
hugotiburtino Nov 4, 2024
9fa424a
Merge branch 'staging' into dependabot/npm_and_yarn/multi-8de63dc217
hugotiburtino Nov 4, 2024
2788f8c
Merge pull request #1794 from serlo/dependabot/npm_and_yarn/multi-8de…
hugotiburtino Nov 4, 2024
4bbaaf4
Merge branch 'staging' into dependabot/npm_and_yarn/graphql-codegen/t…
hugotiburtino Nov 4, 2024
e607bec
Merge branch 'staging' into dependabot/npm_and_yarn/lerna-8.1.9
hugotiburtino Nov 4, 2024
7442bed
Merge branch 'staging' into dependabot/npm_and_yarn/apollo/server-4.11.2
hugotiburtino Nov 4, 2024
88bef1d
Merge branch 'staging' into dependabot/npm_and_yarn/google-cloud/stor…
hugotiburtino Nov 4, 2024
e679036
Merge pull request #1791 from serlo/dependabot/npm_and_yarn/apollo/se…
hugotiburtino Nov 4, 2024
a5d93f1
Merge pull request #1790 from serlo/dependabot/npm_and_yarn/google-cl…
hugotiburtino Nov 4, 2024
908fa0f
Merge pull request #1793 from serlo/dependabot/npm_and_yarn/graphql-c…
hugotiburtino Nov 4, 2024
5f60d75
chore(db-migration): fix command
hugotiburtino Nov 4, 2024
c3de5bc
Merge pull request #1792 from serlo/dependabot/npm_and_yarn/lerna-8.1.9
hugotiburtino Nov 4, 2024
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
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