Merge branch 'master' into fix-admin-creation-list

This commit is contained in:
Moriz Wahl 2022-01-11 13:01:30 +01:00
commit e4c8225799
21 changed files with 77 additions and 30 deletions

View File

@ -470,7 +470,7 @@ jobs:
report_name: Coverage Admin Interface report_name: Coverage Admin Interface
type: lcov type: lcov
result_path: ./coverage/lcov.info result_path: ./coverage/lcov.info
min_coverage: 76 min_coverage: 77
token: ${{ github.token }} token: ${{ github.token }}
############################################################################## ##############################################################################

View File

@ -7,6 +7,7 @@ export const verifyLogin = gql`
lastName lastName
isAdmin isAdmin
id id
language
} }
} }
` `

View File

@ -42,7 +42,7 @@ Vue.use(Toasted, {
}, },
}) })
addNavigationGuards(router, store, apolloProvider.defaultClient) addNavigationGuards(router, store, apolloProvider.defaultClient, i18n)
new Vue({ new Vue({
moment, moment,

View File

@ -42,15 +42,13 @@ export default {
{ key: 'lastName', label: this.$t('lastname') }, { key: 'lastName', label: this.$t('lastname') },
{ {
key: 'creation', key: 'creation',
// label: this.$t('open_creation') + 'Jan | Feb | März', label: [
label: this.$moment().subtract(2, 'month').format('MMM'),
this.$moment().subtract(2, 'month').format('MMM') + this.$moment().subtract(1, 'month').format('MMM'),
' | ' +
this.$moment().subtract(1, 'month').format('MMM') +
' | ' +
this.$moment().format('MMM'), this.$moment().format('MMM'),
].join(' | '),
formatter: (value, key, item) => { formatter: (value, key, item) => {
return String(value[0]) + ` | ` + String(value[1]) + ` | ` + String(value[2]) return value.join(' | ')
}, },
}, },
{ key: 'show_details', label: this.$t('details') }, { key: 'show_details', label: this.$t('details') },

View File

@ -1,7 +1,7 @@
import { verifyLogin } from '../graphql/verifyLogin' import { verifyLogin } from '../graphql/verifyLogin'
import CONFIG from '../config' import CONFIG from '../config'
const addNavigationGuards = (router, store, apollo) => { const addNavigationGuards = (router, store, apollo, i18n) => {
// store token on `authenticate` // store token on `authenticate`
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
if (to.path === '/authenticate' && to.query && to.query.token) { if (to.path === '/authenticate' && to.query && to.query.token) {
@ -14,6 +14,7 @@ const addNavigationGuards = (router, store, apollo) => {
.then((result) => { .then((result) => {
const moderator = result.data.verifyLogin const moderator = result.data.verifyLogin
if (moderator.isAdmin) { if (moderator.isAdmin) {
i18n.locale = moderator.language
store.commit('moderator', moderator) store.commit('moderator', moderator)
next({ path: '/' }) next({ path: '/' })
} else { } else {

View File

@ -6,9 +6,11 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
data: { data: {
verifyLogin: { verifyLogin: {
isAdmin: true, isAdmin: true,
language: 'de',
}, },
}, },
}) })
const i18nLocaleMock = jest.fn()
const store = { const store = {
commit: storeCommitMock, commit: storeCommitMock,
@ -21,7 +23,11 @@ const apollo = {
query: apolloQueryMock, query: apolloQueryMock,
} }
addNavigationGuards(router, store, apollo) const i18n = {
locale: i18nLocaleMock,
}
addNavigationGuards(router, store, apollo, i18n)
describe('navigation guards', () => { describe('navigation guards', () => {
beforeEach(() => { beforeEach(() => {
@ -33,19 +39,23 @@ describe('navigation guards', () => {
const next = jest.fn() const next = jest.fn()
describe('with valid token and as admin', () => { describe('with valid token and as admin', () => {
beforeEach(() => { beforeEach(async () => {
navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next) await navGuard({ path: '/authenticate', query: { token: 'valid-token' } }, {}, next)
}) })
it('commits the token to the store', async () => { it('commits the token to the store', () => {
expect(storeCommitMock).toBeCalledWith('token', 'valid-token') expect(storeCommitMock).toBeCalledWith('token', 'valid-token')
}) })
it('commits the moderator to the store', () => { it.skip('sets the locale', () => {
expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true }) expect(i18nLocaleMock).toBeCalledWith('de')
}) })
it('redirects to /', async () => { it('commits the moderator to the store', () => {
expect(storeCommitMock).toBeCalledWith('moderator', { isAdmin: true, language: 'de' })
})
it('redirects to /', () => {
expect(next).toBeCalledWith({ path: '/' }) expect(next).toBeCalledWith({ path: '/' })
}) })
}) })

View File

@ -65,9 +65,9 @@ export class AdminResolver {
loginPendingTaskAdmin.memo = memo loginPendingTaskAdmin.memo = memo
loginPendingTaskAdmin.moderator = moderator loginPendingTaskAdmin.moderator = moderator
loginPendingTasksAdminRepository.save(loginPendingTaskAdmin) await loginPendingTasksAdminRepository.save(loginPendingTaskAdmin)
} }
return await getUserCreations(user.id) return getUserCreations(user.id)
} }
@Authorized([RIGHTS.CREATE_PENDING_CREATION]) @Authorized([RIGHTS.CREATE_PENDING_CREATION])

View File

@ -8,7 +8,11 @@ const plugins = [
willSendResponse(requestContext: any) { willSendResponse(requestContext: any) {
const { setHeaders = [] } = requestContext.context const { setHeaders = [] } = requestContext.context
setHeaders.forEach(({ key, value }: { [key: string]: string }) => { setHeaders.forEach(({ key, value }: { [key: string]: string }) => {
if (requestContext.response.http.headers.get(key)) {
requestContext.response.http.headers.set(key, value)
} else {
requestContext.response.http.headers.append(key, value) requestContext.response.http.headers.append(key, value)
}
}) })
return requestContext return requestContext
}, },

View File

@ -19,7 +19,7 @@ define(LoginUser, (faker: typeof Faker, context?: LoginUserContext) => {
user.privKey = context.privKey ? context.privKey : randomBytes(80) user.privKey = context.privKey ? context.privKey : randomBytes(80)
user.emailHash = context.emailHash ? context.emailHash : randomBytes(32) user.emailHash = context.emailHash ? context.emailHash : randomBytes(32)
user.createdAt = context.createdAt ? context.createdAt : faker.date.recent() user.createdAt = context.createdAt ? context.createdAt : faker.date.recent()
user.emailChecked = context.emailChecked ? context.emailChecked : true user.emailChecked = context.emailChecked === undefined ? false : context.emailChecked
user.passphraseShown = context.passphraseShown ? context.passphraseShown : false user.passphraseShown = context.passphraseShown ? context.passphraseShown : false
user.language = context.language ? context.language : 'en' user.language = context.language ? context.language : 'en'
user.disabled = context.disabled ? context.disabled : false user.disabled = context.disabled ? context.disabled : false

View File

@ -6,6 +6,7 @@ import { CreatePeterLustigSeed } from './seeds/users/peter-lustig.admin.seed'
import { CreateBibiBloxbergSeed } from './seeds/users/bibi-bloxberg.seed' import { CreateBibiBloxbergSeed } from './seeds/users/bibi-bloxberg.seed'
import { CreateRaeuberHotzenplotzSeed } from './seeds/users/raeuber-hotzenplotz.seed' import { CreateRaeuberHotzenplotzSeed } from './seeds/users/raeuber-hotzenplotz.seed'
import { CreateBobBaumeisterSeed } from './seeds/users/bob-baumeister.seed' import { CreateBobBaumeisterSeed } from './seeds/users/bob-baumeister.seed'
import { CreateGarrickOllivanderSeed } from './seeds/users/garrick-ollivander.seed'
import { DecayStartBlockSeed } from './seeds/decay-start-block.seed' import { DecayStartBlockSeed } from './seeds/decay-start-block.seed'
import { resetDB, pool, migration } from './helpers' import { resetDB, pool, migration } from './helpers'
@ -44,6 +45,7 @@ const run = async (command: string) => {
await runSeeder(CreateBibiBloxbergSeed) await runSeeder(CreateBibiBloxbergSeed)
await runSeeder(CreateRaeuberHotzenplotzSeed) await runSeeder(CreateRaeuberHotzenplotzSeed)
await runSeeder(CreateBobBaumeisterSeed) await runSeeder(CreateBobBaumeisterSeed)
await runSeeder(CreateGarrickOllivanderSeed)
break break
default: default:
throw new Error(`Unsupported command ${command}`) throw new Error(`Unsupported command ${command}`)

View File

@ -23,7 +23,7 @@ export interface LoginUserContext {
language?: string language?: string
disabled?: boolean disabled?: boolean
groupId?: number groupId?: number
publisherId?: number | null publisherId?: number
} }
export interface LoginUserBackupContext { export interface LoginUserBackupContext {

View File

@ -15,7 +15,7 @@ export interface UserInterface {
language?: string language?: string
disabled?: boolean disabled?: boolean
groupId?: number groupId?: number
publisherId?: number | null publisherId?: number
// from login user backup // from login user backup
passphrase?: string passphrase?: string
mnemonicType?: number mnemonicType?: number

View File

@ -17,7 +17,6 @@ export const bibiBloxberg = {
language: 'de', language: 'de',
disabled: false, disabled: false,
groupId: 1, groupId: 1,
publisherId: null,
passphrase: passphrase:
'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ', 'knife normal level all hurdle crucial color avoid warrior stadium road bachelor affair topple hawk pottery right afford immune two ceiling budget glance hour ',
mnemonicType: 2, mnemonicType: 2,

View File

@ -17,7 +17,6 @@ export const bobBaumeister = {
language: 'de', language: 'de',
disabled: false, disabled: false,
groupId: 1, groupId: 1,
publisherId: null,
passphrase: passphrase:
'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ', 'detail master source effort unable waste tilt flush domain orchard art truck hint barrel response gate impose peanut secret merry three uncle wink resource ',
mnemonicType: 2, mnemonicType: 2,

View File

@ -0,0 +1,9 @@
import { Factory, Seeder } from 'typeorm-seeding'
import { garrickOllivander } from './garrick-ollivander'
import { userSeeder } from '../helpers/user-helpers'
export class CreateGarrickOllivanderSeed implements Seeder {
public async run(factory: Factory): Promise<void> {
await userSeeder(factory, garrickOllivander)
}
}

View File

@ -0,0 +1,21 @@
export const garrickOllivander = {
email: 'garrick@ollivander.com',
firstName: 'Garrick',
lastName: 'Ollivander',
username: 'garrick',
description: `Curious ... curious ...
Renowned wandmaker Mr Ollivander owns the wand shop Ollivanders: Makers of Fine Wands Since 382 BC in Diagon Alley. His shop is widely considered the best place to purchase a wand.`,
password: BigInt('0'),
emailHash: Buffer.from('91e358000e908146342789979d62a7255b2b88a71dad0c6a10e32af44be57886', 'hex'),
createdAt: new Date('2022-01-10T10:23:17'),
emailChecked: false,
passphraseShown: false,
language: 'en',
disabled: false,
groupId: 1,
passphrase:
'human glide theory clump wish history other duty door fringe neck industry ostrich equal plate diesel tornado neck people antenna door category moon hen ',
mnemonicType: 2,
isAdmin: false,
addBalance: false,
}

View File

@ -17,7 +17,6 @@ export const peterLustig = {
language: 'de', language: 'de',
disabled: false, disabled: false,
groupId: 1, groupId: 1,
publisherId: null,
passphrase: passphrase:
'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ', 'okay property choice naive calm present weird increase stuff royal vibrant frame attend wood one else tribe pull hedgehog woman kitchen hawk snack smart ',
mnemonicType: 2, mnemonicType: 2,

View File

@ -17,7 +17,6 @@ export const raeuberHotzenplotz = {
language: 'de', language: 'de',
disabled: false, disabled: false,
groupId: 1, groupId: 1,
publisherId: null,
passphrase: passphrase:
'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ', 'gospel trip tenant mouse spider skill auto curious man video chief response same little over expire drum display fancy clinic keen throw urge basket ',
mnemonicType: 2, mnemonicType: 2,

View File

@ -28,7 +28,7 @@ Vue.toasted.register(
loadAllRules(i18n) loadAllRules(i18n)
addNavigationGuards(router, store, apolloProvider.defaultClient) addNavigationGuards(router, store, apolloProvider.defaultClient, i18n)
if (!store) { if (!store) {
setTimeout( setTimeout(

View File

@ -1,6 +1,6 @@
import { verifyLogin } from '../graphql/queries' import { verifyLogin } from '../graphql/queries'
const addNavigationGuards = (router, store, apollo) => { const addNavigationGuards = (router, store, apollo, i18n) => {
// handle publisherId // handle publisherId
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const publisherId = to.query.pid const publisherId = to.query.pid
@ -21,6 +21,7 @@ const addNavigationGuards = (router, store, apollo) => {
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
}) })
.then((result) => { .then((result) => {
i18n.locale = result.data.verifyLogin.language
store.dispatch('login', result.data.verifyLogin) store.dispatch('login', result.data.verifyLogin)
next({ path: '/overview' }) next({ path: '/overview' })
}) })

View File

@ -23,7 +23,11 @@ const apollo = {
query: apolloQueryMock, query: apolloQueryMock,
} }
addNavigationGuards(router, store, apollo) const i18n = {
locale: jest.fn(),
}
addNavigationGuards(router, store, apollo, i18n)
describe('navigation guards', () => { describe('navigation guards', () => {
beforeEach(() => { beforeEach(() => {