Skip to content

Commit

Permalink
Merge branch 'staging' into REseo-kulla-2024-06-16-14-17
Browse files Browse the repository at this point in the history
  • Loading branch information
hugotiburtino committed Jul 11, 2024
2 parents 3eb3e4c + 460918a commit 0480af8
Show file tree
Hide file tree
Showing 178 changed files with 1,219 additions and 1,295 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SERVER_KRATOS_DB_URI=postgres://serlo:secret@localhost:5432/kratos?sslmode=disab
SERVER_SERLO_CLOUDFLARE_WORKER_SECRET=api.serlo.org-playground-secret
SERVER_SERLO_CACHE_WORKER_SECRET=api.serlo.org-cache-worker-secret
SERVER_SERLO_NOTIFICATION_EMAIL_SERVICE_SECRET=api.serlo.org-notification-email-service-secret
SERVER_SERLO_EDITOR_TESTING_SECRET=api.serlo.org-serlo-editor-testing-secret
SERVER_SWR_QUEUE_DASHBOARD_PASSWORD=secret
SERVER_SWR_QUEUE_DASHBOARD_USERNAME=secret

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build the ${{ matrix.image }} image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: false
load: true
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/push-migration-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Push DB migration image
on:
# not a problem if we do it at every push because it will check if the image already exists
push:

jobs:
docker-image:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_KEY_CONTAINER_REGISTRY }}'
- run: gcloud auth configure-docker
- uses: google-github-actions/setup-gcloud@v2
- run: yarn migrate:push-image
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 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 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/glob-npm-8.1.0-65f64af8b1-92fbea3221.zip
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 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/read-npm-2.1.0-0e0cb8a375-e745999138.zip
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.
12 changes: 0 additions & 12 deletions __fixtures__/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ export const createEntityLinkNotificationEvent: Model<'CreateEntityLinkNotificat
childId: coursePage.id,
}

export const removeEntityLinkNotificationEvent: Model<'RemoveEntityLinkNotificationEvent'> =
{
__typename: NotificationEventType.RemoveEntityLink,
id: 55273,
instance: Instance.De,
date: '2014-03-01T20:45:56Z',
actorId: user.id,
objectId: coursePage.id,
parentId: course.id,
childId: coursePage.id,
}

export const createEntityRevisionNotificationEvent: Model<'CreateEntityRevisionNotificationEvent'> =
{
__typename: NotificationEventType.CreateEntityRevision,
Expand Down
11 changes: 0 additions & 11 deletions __tests__/schema/event-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
createTaxonomyTermNotificationEvent,
createThreadNotificationEvent,
rejectRevisionNotificationEvent,
removeEntityLinkNotificationEvent,
removeTaxonomyLinkNotificationEvent,
setLicenseNotificationEvent,
setTaxonomyParentNotificationEvent,
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('creates event successfully with right payload', () => {
createTaxonomyTermNotificationEvent,
createThreadNotificationEvent,
rejectRevisionNotificationEvent,
removeEntityLinkNotificationEvent,
removeTaxonomyLinkNotificationEvent,
setLicenseNotificationEvent,
setTaxonomyParentNotificationEvent,
Expand Down Expand Up @@ -196,15 +194,6 @@ async function getLastEvent() {
reason
}
... on RemoveEntityLinkNotificationEvent {
parent {
id
}
child {
id
}
}
... on RemoveTaxonomyLinkNotificationEvent {
parent {
id
Expand Down
67 changes: 42 additions & 25 deletions __tests__/schema/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,52 @@ import gql from 'graphql-tag'

import { user } from '../../__fixtures__'
import { Client } from '../__utils__'
import { Service } from '~/context/service'

const query = new Client({ userId: user.id }).prepareQuery({
query: gql`
query {
media {
newUpload(mediaType: IMAGE_PNG) {
uploadUrl
urlAfterUpload
}
}
}
`,
test('returns url for uploading media file', async () => {
const query = setupQuery()
await query.shouldReturnData({
media: {
newUpload: {
uploadUrl: 'http://google.com/upload',
urlAfterUpload: expect.stringMatching(
/https:\/\/assets.serlo.org\/[\d\-a-f]+\/image.png/,
) as unknown,
},
},
})
})

describe('media.upload', () => {
test('returns url for uploading media file', async () => {
await query.shouldReturnData({
media: {
newUpload: {
uploadUrl: 'http://google.com/upload',
urlAfterUpload: expect.stringMatching(
/https:\/\/assets.serlo.org\/[\d\-a-f]+\/image.png/,
) as unknown,
},
test('returns url for uploading media file for Serlo Editor testing', async () => {
const query = setupQuery({ service: Service.SerloEditorTesting })
await query.shouldReturnData({
media: {
newUpload: {
uploadUrl: 'http://google.com/upload',
urlAfterUpload: expect.stringMatching(
/https:\/\/storage.googleapis.com\/serlo-editor-testing\/[\d\-a-f]+.png/,
) as unknown,
},
})
},
})
})

test('fails for unauthenticated user', async () => {
await query.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})
test('fails for unauthenticated user', async () => {
const query = setupQuery()
await query.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})

function setupQuery(options: { service?: Service } = {}) {
return new Client({ userId: user.id, ...options }).prepareQuery({
query: gql`
query {
media {
newUpload(mediaType: IMAGE_PNG) {
uploadUrl
urlAfterUpload
}
}
}
`,
})
}
109 changes: 82 additions & 27 deletions __tests__/schema/thread/set-thread-status.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,114 @@
import gql from 'graphql-tag'

import { Client, entityQuery } from '../../__utils__'
import { user } from '../../../__fixtures__'
import { Client } from '../../__utils__'
import { encodeThreadId } from '~/schema/thread/utils'

const input = { id: encodeThreadId(34161), status: 'done' }
const mutation = new Client({ userId: 1 }).prepareQuery({
query: gql`
mutation setThreadStatus($input: ThreadSetThreadStatusInput!) {
thread {
setThreadStatus(input: $input) {
success
const moderator = { ...user, id: 10, roles: ['de_moderator'] }
const threadInitiator = { ...user, id: 1194, roles: ['login'] }

const mutation = new Client({ userId: threadInitiator.id })
.prepareQuery({
query: gql`
mutation setThreadStatus($input: ThreadSetThreadStatusInput!) {
thread {
setThreadStatus(input: $input) {
success
}
}
}
`,
})
.withInput({ id: encodeThreadId(35163), status: 'open' })

test('status is actually changed', async function () {
const threadQuery = new Client({ userId: user.id })
.prepareQuery({
query: gql`
query (
$first: Int
$after: String
$instance: Instance
$subjectId: String
$status: CommentStatus
) {
thread {
allThreads(
first: $first
after: $after
instance: $instance
subjectId: $subjectId
status: $status
) {
nodes {
id
status
}
}
}
}
`,
})
.withVariables({ first: 3 })

const queryResult = await threadQuery.getData()
const data = queryResult as {
thread: {
allThreads: {
nodes: Array<{ id: string; status: string }>
}
}
`,
variables: { input },
})
}

test('changes status of thread', async function () {
await entityQuery.withVariables({ id: 34159 }).shouldReturnData({
uuid: { threads: { nodes: [{ status: 'noStatus' }] } },
const threadIDs = data.thread.allThreads.nodes.map((node) => {
expect(node.status).toBe('noStatus')
return node.id
})

await mutation.shouldReturnData({
thread: { setThreadStatus: { success: true } },
})
await mutation
.withContext({ userId: moderator.id })
.withInput({ id: threadIDs, status: 'done' })
.shouldReturnData({
thread: { setThreadStatus: { success: true } },
})

await entityQuery.withVariables({ id: 34159 }).shouldReturnData({
uuid: { threads: { nodes: [{ status: 'done' }] } },
await threadQuery.shouldReturnData({
thread: {
allThreads: {
nodes: threadIDs.map((id) => ({ id, status: 'done' })),
},
},
})
})

test('unauthenticated user gets error', async () => {
await mutation.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})

test('thread initiators are allowed to change thread status', async () => {
await mutation.shouldReturnData({
thread: { setThreadStatus: { success: true } },
})
})

test('commentators are allowed to change thread status', async () => {
await mutation.withContext({ userId: 32543 }).shouldReturnData({
const commentatorId = 266
// Let's remove all other roles of this user to be sure that they will change status although they are just login user
await global.databaseForTests.mutate(
'DELETE FROM role_user WHERE user_id = ? AND role_id > 2',
[commentatorId],
)
await mutation.withContext({ userId: commentatorId }).shouldReturnData({
thread: { setThreadStatus: { success: true } },
})
})

test('moderators are allowed to change thread status', async () => {
const newMutation = await mutation.forUser('de_moderator')
await newMutation.shouldReturnData({
await mutation.withContext({ userId: moderator.id }).shouldReturnData({
thread: { setThreadStatus: { success: true } },
})
})

test('unauthorized users get error', async () => {
await mutation.forLoginUser().shouldFailWithError('FORBIDDEN')
})

test('unauthenticated user gets error', async () => {
await mutation.forUnauthenticatedUser().shouldFailWithError('UNAUTHENTICATED')
})
})
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
ports:
- '6379:6379'
mysql:
image: eu.gcr.io/serlo-shared/serlo-mysql-database:prerelease-entityfield-coursepage-event-taxonomy
image: eu.gcr.io/serlo-shared/serlo-mysql-database:latest
platform: linux/x86_64
pull_policy: always
ports:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"migrate:run": "packages/db-migrations/scripts/run_migrations.sh",
"migrate:all": "lerna run --stream migrate:all",
"migrate:up": "lerna run --stream migrate:up",
"migrate:build": "lerna run --stream build:all",
"migrate:push-image": "lerna run --stream push-image",
"mysql": "docker compose exec mysql serlo-mysql",
"mysql:delete-last-migration": "yarn mysql --execute 'DELETE FROM migrations ORDER BY id DESC LIMIT 1'",
"mysql:delete-all-migrations": "yarn mysql --execute 'DELETE FROM migrations'",
Expand Down
21 changes: 21 additions & 0 deletions packages/db-migrations/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:20-alpine AS base_image
WORKDIR /app
COPY package.json .
RUN corepack enable
RUN yarn set version 3.x

FROM base_image AS build_migrations
COPY scripts scripts
COPY src src
RUN yarn
RUN yarn build:all

FROM base_image AS runner
RUN yarn plugin import workspace-tools
RUN yarn workspaces focus --production
COPY --from=build_migrations /app/migrations migrations
COPY migrations/package.json migrations/package.json
COPY database.json .

ENTRYPOINT ["yarn", "db-migrate"]
CMD ["up"]
Empty file.
41 changes: 0 additions & 41 deletions packages/db-migrations/__tests__/redis.ts

This file was deleted.

Loading

0 comments on commit 0480af8

Please sign in to comment.