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 #1477

Merged
merged 98 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0a8cea6
refactor(uuid): Prepare uuid query to support other types as well
kulla May 3, 2024
f3615ef
test: Make MSW to bypass to DB-Layer
kulla May 3, 2024
268244c
refactor: Move taxonomy to uuid query
kulla May 3, 2024
c5c839b
refactor(taxonomy): Add SQl for TaxonomySetNameAndDescription
kulla May 3, 2024
f4728db
Fix lint errors
kulla May 3, 2024
f23036e
fix(taxonomy): Add event when setting name and description
kulla May 4, 2024
47c8137
chore: Enable source-maps in "yarn start"
kulla May 4, 2024
61c624f
refactor(database): Add fetchOptional() + better transaction handling
kulla May 4, 2024
fee05ba
refactor(taxonomy): Move SQL for creating taxonomies
kulla May 4, 2024
40109e9
fix(database): Use proper rollback()
kulla May 4, 2024
104c634
test(database): Close DB after tests
kulla May 4, 2024
9c9ed50
Merge branch 'staging' into DJ9dI-kulla-2024-05-03-18-35
kulla May 4, 2024
9521598
Fix lint errors
kulla May 4, 2024
88bd9cf
fix(subject): Use fetchOptional()
kulla May 4, 2024
436f95f
chore(github): Test metadata endpoint extra
kulla May 4, 2024
de1e29f
refactor(taxonomy): Add SQL for sort taxonomies
kulla May 4, 2024
cd279a7
refactor(taxonomy): Add SQL to taxonomy.deleteEntityLink()
kulla May 4, 2024
8cd2efc
refactor(taxonomy): Move SQL into taxonomy.createEntityLinks()
kulla May 4, 2024
fbcd5c1
refactor(uuid): Replace UuidSetState with SQL
kulla May 4, 2024
f093e43
Fix lint errors
kulla May 4, 2024
7a4186f
test: Move taxonomyTermQuery to __utils__
kulla May 5, 2024
fc9fe5f
Merge branch 'staging' into DJ9dI-kulla-2024-05-03-18-35
AndreasHuber May 6, 2024
d68bced
fix(uuid resolver): restore rename accidentally undone during merge
AndreasHuber May 6, 2024
ed4d47a
fix(uuid resolver): add missing comma in SQL query
AndreasHuber May 6, 2024
da85ce2
style(uuid resolver): format SQL query
AndreasHuber May 6, 2024
a5d5a1c
style(uuid resolver): format SQL query
AndreasHuber May 6, 2024
095030d
refactor(resolveUuidFromDatabase): define BaseUser
AndreasHuber May 6, 2024
53fdd54
refactor(resolveUuidFromDatabase): add LEFT JOINs for user to SQL query
AndreasHuber May 6, 2024
9183a59
refactor(resolveUuidFromDatabase): add SELECTs for user to SQL query
AndreasHuber May 6, 2024
d8b8410
refactor(resolveUuidFromDatabase): add case BaseUser.is(baseUuid)
AndreasHuber May 6, 2024
f4c08a3
Merge branch 'staging' into make-resolveUuidFromDatabase-also-return-…
AndreasHuber May 6, 2024
f487e56
fix(resolveUuidFromDatabase): add missing commas to SQL query
AndreasHuber May 6, 2024
be0e1ae
Merge branch 'staging' into DJ9dI-kulla-2024-05-03-18-35
hugotiburtino May 6, 2024
d6e42b7
Merge branch 'DJ9dI-kulla-2024-05-03-18-35' into w2UlG-kulla-2024-05-…
hugotiburtino May 6, 2024
dab7c05
Merge pull request #1458 from serlo/w2UlG-kulla-2024-05-03-22-58
hugotiburtino May 6, 2024
accfd36
Merge pull request #1460 from serlo/fxHiA-kulla-2024-05-04-07-19
hugotiburtino May 6, 2024
50ce5eb
Merge pull request #1466 from serlo/pMtgC-kulla-2024-05-04-18-06
hugotiburtino May 6, 2024
c9f96de
Merge pull request #1465 from serlo/D15TX-kulla-2024-05-04-16-38
hugotiburtino May 6, 2024
b61a44d
Merge pull request #1467 from serlo/jlnRa-kulla-2024-05-04-18-51
hugotiburtino May 6, 2024
d123bda
Merge pull request #1470 from serlo/t0Jjl-kulla-2024-05-05-14-53
hugotiburtino May 6, 2024
81c0509
Merge pull request #1456 from serlo/DJ9dI-kulla-2024-05-03-18-35
hugotiburtino May 6, 2024
614711c
Merge pull request #1468 from serlo/wSiDw-kulla-2024-05-04-19-58
hugotiburtino May 6, 2024
8fb67ef
chore: move emptySubjects to fixtures
elbotho May 6, 2024
03712bc
Merge pull request #1478 from serlo/move-to-fixture
elbotho May 6, 2024
57f79ab
chore(cache): Add myself to allowed users
May 7, 2024
b9eb9cd
chore(resolveUuidFromDatabase): find arguments to return
AndreasHuber May 7, 2024
424350a
chore(resolveUuidFromDatabase): cleanup
AndreasHuber May 7, 2024
dbadb59
Merge pull request #1479 from serlo/chore/add-mikey-to-allowed-users
AndreasHuber May 7, 2024
246e21b
Merge branch 'staging' into make-resolveUuidFromDatabase-also-return-…
AndreasHuber May 7, 2024
fbd2ccc
chore: fix lint errors with imports
AndreasHuber May 7, 2024
d9202ab
fix(resolveUuidFromDatabase): add proper alias property
AndreasHuber May 7, 2024
9787a3b
chore(resolveUuidFromDatabase): remove unused property
AndreasHuber May 7, 2024
d5cc3f3
refactor(setEmail): migrate SQL from database-layer to resolver
AndreasHuber May 7, 2024
2fef783
test(setEmail): remove tests testing case of database-layer error res…
AndreasHuber May 7, 2024
1a6d690
test(setEmail): remove from serlo model
AndreasHuber May 7, 2024
693f4e5
refactor(setEmail): do not remove cache entry as mail is not in cache
AndreasHuber May 7, 2024
98905ac
fix(bull-arena): Make it an external dependency
kulla May 7, 2024
182ed10
Merge pull request #1481 from serlo/bgeqS-kulla-2024-05-07-19-02
kulla May 7, 2024
c0070b6
Merge pull request #1476 from serlo/make-resolveUuidFromDatabase-also…
hugotiburtino May 7, 2024
ced7326
chore(vidis): add container for local test to vidis
hugotiburtino May 7, 2024
933c190
doc(readme): remove not so important info
hugotiburtino May 7, 2024
8661c1d
fix(swr-queue): Add needed context variables for value updates
kulla May 8, 2024
a4cab5f
Merge pull request #1484 from serlo/1483-error-cannot-read-properties…
hugotiburtino May 8, 2024
31ec0a7
Merge pull request #1480 from serlo/migrate-set-email
hugotiburtino May 8, 2024
1fcbbc5
refactor(setEmail): remove from database-layer.ts
AndreasHuber May 8, 2024
b2bca1c
test(setEmail): remove mock
AndreasHuber May 8, 2024
2722ce9
Merge pull request #1485 from serlo/migrate-set-email
hugotiburtino May 8, 2024
068d452
refactor(deleteRegularUser): remove from serlo model
AndreasHuber May 8, 2024
21c8a6e
refactor(deleteRegularUser): remove from database-layer.ts
AndreasHuber May 8, 2024
b0e3d18
refactor(deleteRegularUser): move SQL to resolver
AndreasHuber May 8, 2024
56b9a59
test(setEmail): Test that email has been changed
kulla May 8, 2024
8b7f663
Merge pull request #1487 from serlo/60z8H-kulla-2024-05-08-11-10
kulla May 8, 2024
72fc01e
refactor(subject): Shorten code to query subjects
kulla May 8, 2024
a30dcd5
test(deleteRegularUser): remove mocks and tests for database-layer fa…
AndreasHuber May 8, 2024
4c3792b
Merge pull request #1486 from serlo/BDkOQ-kulla-2024-05-08-11-05
kulla May 8, 2024
a98c652
fix(deleteRegularUser): await promise
AndreasHuber May 8, 2024
24339cc
test(deleteRegularUser): remove unused imports
AndreasHuber May 8, 2024
3dc7e6d
test(deleteRegularUser): format
AndreasHuber May 8, 2024
72f9856
fix(deleteRegularUser): await promise
AndreasHuber May 8, 2024
b369ce7
feat(kratos): extend SLO to provider vidis
hugotiburtino May 8, 2024
56b3deb
fix(deleteRegularUser): use transaction
AndreasHuber May 8, 2024
fa602ee
refactor(deleteRegularUser): revert to id instead of user.id
AndreasHuber May 8, 2024
080e47b
feature(deleteRegularUser): only commit database transaction if remov…
AndreasHuber May 8, 2024
f1d8456
doc(readme): minor change
hugotiburtino May 8, 2024
9d6ed5b
Merge pull request #1482 from serlo/vidis
hugotiburtino May 8, 2024
2c70a57
chore(deps): bump semver from 7.0.0 to 7.6.1
dependabot[bot] May 8, 2024
faa6db0
Merge pull request #1490 from serlo/dependabot/npm_and_yarn/semver-7.6.1
kulla May 8, 2024
1540366
chore(kratos): upgrade image
hugotiburtino May 8, 2024
3e1509e
chore: Set default cache type to "redis" for "yarn start"
kulla May 9, 2024
6da0145
test(subject): Add `subjectQuery`
kulla May 9, 2024
7992233
Merge pull request #1493 from serlo/uJbfv-kulla-2024-05-09-18-00
kulla May 9, 2024
42fa576
Merge pull request #1492 from serlo/mG0Ls-kulla-2024-05-09-17-53
hugotiburtino May 9, 2024
ef63299
test(deleteRegularUser): put test back that might still make sense an…
AndreasHuber May 10, 2024
2af8933
Merge pull request #1491 from serlo/kratos-upgrade
kulla May 10, 2024
5b9c319
test(deleteRegularUser): comment test step that cannot work while the…
AndreasHuber May 10, 2024
7e3069a
feature(deleteRegularUser): await completion of all mutations instead…
AndreasHuber May 10, 2024
4dcdf56
refactor(user): minor wording change at error msg
hugotiburtino May 11, 2024
6f1a9f8
Merge pull request #1488 from serlo/migrate-delete-regular-user
hugotiburtino May 11, 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
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ ROCKET_CHAT_API_AUTH_TOKEN=an-auth-token
ROCKET_CHAT_URL=https://community.serlo.org/
SERLO_ORG_DATABASE_LAYER_HOST=127.0.0.1:8080
SERLO_ORG_SECRET=serlo.org-secret
CACHE_TYPE=empty
# Set the following value to `empty` to disable caching
CACHE_TYPE=redis

SERVER_HYDRA_HOST=http://localhost:4445
SERVER_KRATOS_PUBLIC_HOST=http://localhost:4433
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ jobs:
- uses: serlo/configure-repositories/actions/setup-mysql@main
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn start:containers
- run: yarn test
# It seems that running tests for changing taxonomies in parallel
# to metadata query messes up with internal optimizatons so that
# testing metadata endpoint runs into a timout
# => solution: Run tests for metadata in an extra step
- run: yarn test metadata.ts
- run: yarn test --testPathIgnorePatterns metadata.ts __utils__

codegen:
runs-on: ubuntu-latest
Expand Down
Binary file not shown.
Binary file not shown.
29 changes: 12 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Happy coding!

### Stop

Interrupt the `yarn start` command to stop the dev server and run `yarn stop:redis` to stop Redis.
Interrupt the `yarn start` command to stop the dev server and run `yarn down` to remove all containers.

### Automatically check your codebase before pushing

Expand All @@ -89,17 +89,6 @@ chmod +x .git/hooks/pre-push

With `git push --no-verify` you can bypass the automatic checks.

### Repository structure

- `__fixtures__` contains test data (used by both unit and contract tests).
- `__tests__` contains the unit tests.
- `__tests-pacts__` contains the contract test.
- `src/internals` contains a couple of internal data structures. In most cases, you won't need to touch this. Here we hide complexity that isn't needed for typical development tasks.
- `src/model` defines the model.
- `src/schema` defines the GraphQL schema.

We have `~` as an absolute path alias for `./src` in place, e.g. `~/internals` refers to `./src/internals`.

### Other commands

- `yarn build:server` builds the server (only needed for deployment)
Expand Down Expand Up @@ -129,14 +118,17 @@ For more info about it see its [documentation](https://www.ory.sh/docs/kratos).

### Integrating Keycloak

First of all add `nbp` as host
First of all add `nbp` and `vidis` as host
`sudo bash -c "echo '127.0.0.1 nbp'" >> /etc/hosts`
`sudo bash -c "echo '127.0.0.1 vidis'" >> /etc/hosts`

_why do I need it? Kratos makes a request to the url of the oauth2 provider, but since it is running inside a container, it cannot easily use the host port. nbp is a dns that is discoverable for the kratos container, so the host can also use it._
_why do I need it? Kratos makes a request to the url of the oauth2 provider, but since it is running inside a container, it cannot easily use the host port. These DNSs are discoverable for the kratos container, so the host can also use it._

Run `yarn start:nbp`.
Run `yarn start:sso`.
_Make sure you already run `yarn start:kratos` before._

Keycloak UI is available on `nbp:11111` (username: admin, pw: admin).
Keycloak UI is available on `nbp:11111` and `vidis:11112`.
Username: admin, pw: admin.
There you have to configure Serlo as a client.

> Client -> Create Client
Expand All @@ -145,6 +137,7 @@ There you have to configure Serlo as a client.
> id: serlo
> home and root url: http://localhost:3000
> redirect uri: http://localhost:4433/self-service/methods/oidc/callback/nbp
> // OR redirect uri: http://localhost:4433/self-service/methods/oidc/callback/vidis
> ```

Get the credentials and go to `kratos/config.yml`:
Expand All @@ -156,14 +149,16 @@ selfservice:
enabled: true
config:
providers:
- id: nbp
- id: nbp # or vidis
provider: generic
client_id: serlo
client_secret: <put secret here>
```

Run the local frontend (not forgetting to change environment in its `.env` to local) to test.

Hint: you may want to create some users in Keycloak in order to test.

### Email templates

Kratos has to be rebuilt every time you change an email template. Use the following workflow:
Expand Down
2 changes: 2 additions & 0 deletions __fixtures__/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './license-id'
export * from './notification'
export * from './uuid'
export * from './subjects'
export * from './metadata'
10 changes: 10 additions & 0 deletions __fixtures__/subjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const emptySubjects = [
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
]
29 changes: 29 additions & 0 deletions __tests__/__utils__/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type Storage } from '@google-cloud/storage'
import type { OAuth2Api } from '@ory/client'
import * as Sentry from '@sentry/node'
import { DocumentNode } from 'graphql'
import gql from 'graphql-tag'
import * as R from 'ramda'

import { given, nextUuid } from '.'
Expand Down Expand Up @@ -121,6 +122,8 @@ export class Query<
const result = await this.execute()

if (result.body.kind === 'single') {
expect(result.body.singleResult['errors']).toBeUndefined()

return result.body.singleResult['data']
}

Expand Down Expand Up @@ -237,6 +240,32 @@ export async function assertErrorEvent(args?: {
expect(global.sentryEvents.some(eventPredicate)).toBe(true)
}

export async function expectEvent(
event: {
__typename: string
objectId: number
},
first = 1,
) {
const data = (await new Client()
.prepareQuery({
query: gql`
query ($first: Int!) {
events(first: $first) {
nodes {
__typename
objectId
}
}
}
`,
variables: { first },
})
.getData()) as { events: { nodes: unknown[] } }

expect(data.events.nodes).toContainEqual(event)
}

/**
* Assertation that no error events have been triggert to sentry
*/
Expand Down
1 change: 1 addition & 0 deletions __tests__/__utils__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as R from 'ramda'
export * from './assertions'
export * from './handlers'
export * from './services'
export * from './query'

export function getTypenameAndId(value: { __typename: string; id: number }) {
return R.pick(['__typename', 'id'], value)
Expand Down
52 changes: 52 additions & 0 deletions __tests__/__utils__/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import gql from 'graphql-tag'

import { Client } from './assertions'

export const taxonomyTermQuery = new Client().prepareQuery({
query: gql`
query ($id: Int!) {
uuid(id: $id) {
__typename
... on TaxonomyTerm {
id
trashed
type
instance
alias
title
name
description
weight
taxonomyId
path {
id
}
parent {
id
}
children {
nodes {
id
}
}
}
}
}
`,
})

export const subjectQuery = new Client().prepareQuery({
query: gql`
query ($instance: Instance!) {
subject {
subjects(instance: $instance) {
id
taxonomyTerm {
name
}
}
}
}
`,
variables: { instance: 'de' },
})
2 changes: 1 addition & 1 deletion __tests__/schema/entity/checkout-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
articleRevision,
user as baseUser,
taxonomyTermSubject,
emptySubjects,
} from '../../../__fixtures__'
import { getTypenameAndId, nextUuid, given, Client } from '../../__utils__'
import { emptySubjects } from '../subject'
import { Instance } from '~/types'

const user = { ...baseUser, roles: ['de_reviewer'] }
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schema/entity/reject-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
articleRevision,
taxonomyTermSubject,
user as baseUser,
emptySubjects,
} from '../../../__fixtures__'
import { given, getTypenameAndId, nextUuid, Client } from '../../__utils__'
import { emptySubjects } from '../subject'
import { Instance } from '~/types'

const user = { ...baseUser, roles: ['de_reviewer'] }
Expand Down
7 changes: 2 additions & 5 deletions __tests__/schema/entity/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,8 @@ testCases.forEach((testCase) => {
await mutationWithEntityId.shouldFailWithError('INTERNAL_SERVER_ERROR')
})

test('fails when parent does not exists', async () => {
given('UuidQuery')
.withPayload({ id: testCase.parent.id })
.returnsNotFound()

// TODO: Make it a proper test when doing the migration
test.skip('fails when parent does not exists', async () => {
await mutationWithParentId.shouldFailWithError('BAD_USER_INPUT')
})

Expand Down
64 changes: 8 additions & 56 deletions __tests__/schema/subject.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
import gql from 'graphql-tag'

import { article, taxonomyTermSubject } from '../../__fixtures__'
import { Client, given } from '../__utils__'
import { Instance } from '~/types'

export const emptySubjects = [
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
]
import { article, emptySubjects, taxonomyTermSubject } from '../../__fixtures__'
import { Client, given, subjectQuery } from '../__utils__'

test('endpoint "subjects" returns list of all subjects for an instance', async () => {
given('UuidQuery').for(taxonomyTermSubject)

await new Client()
.prepareQuery({
query: gql`
query ($instance: Instance!) {
subject {
subjects(instance: $instance) {
taxonomyTerm {
name
}
}
}
}
`,
})
.withVariables({ instance: Instance.En })
.shouldReturnData({
subject: {
subjects: [{ taxonomyTerm: { name: 'Math' } }],
},
})
await subjectQuery.withVariables({ instance: 'en' }).shouldReturnData({
subject: { subjects: [{ taxonomyTerm: { name: 'Math' } }] },
})
})

test('`Subject.id` returns encoded id of subject', async () => {
given('UuidQuery').for(taxonomyTermSubject)

await new Client()
.prepareQuery({
query: gql`
query ($instance: Instance!) {
subject {
subjects(instance: $instance) {
id
}
}
}
`,
})
.withVariables({ instance: Instance.En })
.shouldReturnData({
subject: {
subjects: [{ id: 'czIzNTkz' }],
},
})
await subjectQuery.withVariables({ instance: 'en' }).shouldReturnData({
subject: { subjects: [{ id: 'czIzNTkz' }] },
})
})

test('`Subject.unrevisedEntities` returns list of unrevisedEntities', async () => {
Expand Down
Loading