From cefc96378061d4ec024330b3e88482c58e060018 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 20 Nov 2021 16:30:22 +0100 Subject: [PATCH] implemented `isAdmin` from backend --- backend/src/graphql/model/User.ts | 4 +++ backend/src/graphql/resolver/UserResolver.ts | 32 ++++++++++++++++++++ frontend/src/graphql/queries.js | 1 + frontend/src/store/store.js | 7 ++++- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index 5b7682e01..33dce434b 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -20,6 +20,7 @@ export class User { this.pubkey = json.public_hex this.language = json.language this.publisherId = json.publisher_id + this.isAdmin = json.isAdmin } } @@ -71,6 +72,9 @@ export class User { @Field(() => Int, { nullable: true }) publisherId?: number + @Field(() => Boolean) + isAdmin: boolean + @Field(() => Boolean) coinanimation: boolean diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index bb769f377..60ea265b2 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -194,6 +194,36 @@ const SecretKeyCryptographyDecrypt = (encryptedMessage: Buffer, encryptionKey: B @Resolver() export class UserResolver { + /* + @Authorized() + @Query(() => User) + async verifyLogin(@Ctx() context: any): Promise { + const loginUserRepository = getCustomRepository(LoginUserRepository) + loginUser = loginUserRepository.findByPubkeyHex() + const user = new User(result.data.user) + + this.email = json.email + this.firstName = json.first_name + this.lastName = json.last_name + this.username = json.username + this.description = json.description + this.pubkey = json.public_hex + this.language = json.language + this.publisherId = json.publisher_id + this.isAdmin = json.isAdmin + + const userSettingRepository = getCustomRepository(UserSettingRepository) + const coinanimation = await userSettingRepository + .readBoolean(userEntity.id, Setting.COIN_ANIMATION) + .catch((error) => { + throw new Error(error) + }) + user.coinanimation = coinanimation + user.isAdmin = true // TODO implement + return user + } + */ + @Query(() => User) @UseMiddleware(klicktippNewsletterStateMiddleware) async login( @@ -267,6 +297,8 @@ export class UserResolver { }) user.coinanimation = coinanimation + user.isAdmin = true // TODO implement + context.setHeaders.push({ key: 'token', value: encode(loginUser.pubKey), diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 01021f601..9cd364ed7 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -15,6 +15,7 @@ export const login = gql` } hasElopage publisherId + isAdmin } } ` diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 1173a8685..c49197059 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -34,6 +34,9 @@ export const mutations = { if (isNaN(pubId)) pubId = null state.publisherId = pubId }, + isAdmin: (state, isAdmin) => { + state.isAdmin = !!isAdmin + }, community: (state, community) => { state.community = community }, @@ -57,6 +60,7 @@ export const actions = { commit('newsletterState', data.klickTipp.newsletterState) commit('hasElopage', data.hasElopage) commit('publisherId', data.publisherId) + commit('isAdmin', data.isAdmin) }, logout: ({ commit, state }) => { commit('token', null) @@ -69,6 +73,7 @@ export const actions = { commit('newsletterState', null) commit('hasElopage', false) commit('publisherId', null) + commit('isAdmin', false) localStorage.clear() }, } @@ -87,7 +92,7 @@ export const store = new Vuex.Store({ username: '', description: '', token: null, - isAdmin: true, // TODO implement this properly + isAdmin: false, coinanimation: true, newsletterState: null, community: {