mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
check rights on all resolvers
This commit is contained in:
parent
44365bccf1
commit
a24c6119a6
@ -8,10 +8,11 @@ import { BalanceRepository } from '../../typeorm/repository/Balance'
|
|||||||
import { UserRepository } from '../../typeorm/repository/User'
|
import { UserRepository } from '../../typeorm/repository/User'
|
||||||
import { calculateDecay } from '../../util/decay'
|
import { calculateDecay } from '../../util/decay'
|
||||||
import { roundFloorFrom4 } from '../../util/round'
|
import { roundFloorFrom4 } from '../../util/round'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class BalanceResolver {
|
export class BalanceResolver {
|
||||||
@Authorized()
|
@Authorized([RIGHTS.BALANCE])
|
||||||
@Query(() => Balance)
|
@Query(() => Balance)
|
||||||
async balance(@Ctx() context: any): Promise<Balance> {
|
async balance(@Ctx() context: any): Promise<Balance> {
|
||||||
// load user and balance
|
// load user and balance
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import { Resolver, Query } from 'type-graphql'
|
import { Resolver, Query, Authorized } from 'type-graphql'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
import CONFIG from '../../config'
|
import CONFIG from '../../config'
|
||||||
import { Community } from '../model/Community'
|
import { Community } from '../model/Community'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class CommunityResolver {
|
export class CommunityResolver {
|
||||||
|
@Authorized([RIGHTS.GET_COMMUNITY_INFO])
|
||||||
@Query(() => Community)
|
@Query(() => Community)
|
||||||
async getCommunityInfo(): Promise<Community> {
|
async getCommunityInfo(): Promise<Community> {
|
||||||
return new Community({
|
return new Community({
|
||||||
@ -17,6 +19,7 @@ export class CommunityResolver {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.COMMUNITIES])
|
||||||
@Query(() => [Community])
|
@Query(() => [Community])
|
||||||
async communities(): Promise<Community[]> {
|
async communities(): Promise<Community[]> {
|
||||||
if (CONFIG.PRODUCTION)
|
if (CONFIG.PRODUCTION)
|
||||||
|
|||||||
@ -9,10 +9,11 @@ import Paginated from '../arg/Paginated'
|
|||||||
import { apiGet } from '../../apis/HttpRequest'
|
import { apiGet } from '../../apis/HttpRequest'
|
||||||
import { UserRepository } from '../../typeorm/repository/User'
|
import { UserRepository } from '../../typeorm/repository/User'
|
||||||
import { Order } from '../enum/Order'
|
import { Order } from '../enum/Order'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class GdtResolver {
|
export class GdtResolver {
|
||||||
@Authorized()
|
@Authorized([RIGHTS.LIST_GDT_ENTRIES])
|
||||||
@Query(() => GdtEntryList)
|
@Query(() => GdtEntryList)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
async listGDTEntries(
|
async listGDTEntries(
|
||||||
@ -33,7 +34,7 @@ export class GdtResolver {
|
|||||||
return new GdtEntryList(resultGDT.data)
|
return new GdtEntryList(resultGDT.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.EXIST_PID])
|
||||||
@Query(() => Number)
|
@Query(() => Number)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
async existPid(@Arg('pid') pid: number): Promise<number> {
|
async existPid(@Arg('pid') pid: number): Promise<number> {
|
||||||
|
|||||||
@ -8,29 +8,30 @@ import {
|
|||||||
unsubscribe,
|
unsubscribe,
|
||||||
signIn,
|
signIn,
|
||||||
} from '../../apis/KlicktippController'
|
} from '../../apis/KlicktippController'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
import SubscribeNewsletterArgs from '../arg/SubscribeNewsletterArgs'
|
import SubscribeNewsletterArgs from '../arg/SubscribeNewsletterArgs'
|
||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class KlicktippResolver {
|
export class KlicktippResolver {
|
||||||
@Authorized()
|
@Authorized([RIGHTS.GET_KLICKTIPP_USER])
|
||||||
@Query(() => String)
|
@Query(() => String)
|
||||||
async getKlicktippUser(@Arg('email') email: string): Promise<string> {
|
async getKlicktippUser(@Arg('email') email: string): Promise<string> {
|
||||||
return await getKlickTippUser(email)
|
return await getKlickTippUser(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.GET_KLICKTIPP_TAG_MAP])
|
||||||
@Query(() => String)
|
@Query(() => String)
|
||||||
async getKlicktippTagMap(): Promise<string> {
|
async getKlicktippTagMap(): Promise<string> {
|
||||||
return await getKlicktippTagMap()
|
return await getKlicktippTagMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.UNSUBSCRIBE_NEWSLETTER])
|
||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async unsubscribeNewsletter(@Arg('email') email: string): Promise<boolean> {
|
async unsubscribeNewsletter(@Arg('email') email: string): Promise<boolean> {
|
||||||
return await unsubscribe(email)
|
return await unsubscribe(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.SUBSCRIBE_NEWSLETTER])
|
||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async subscribeNewsletter(
|
async subscribeNewsletter(
|
||||||
@Args() { email, language }: SubscribeNewsletterArgs,
|
@Args() { email, language }: SubscribeNewsletterArgs,
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import { TransactionTypeId } from '../enum/TransactionTypeId'
|
|||||||
import { TransactionType } from '../enum/TransactionType'
|
import { TransactionType } from '../enum/TransactionType'
|
||||||
import { hasUserAmount, isHexPublicKey } from '../../util/validate'
|
import { hasUserAmount, isHexPublicKey } from '../../util/validate'
|
||||||
import { LoginUserRepository } from '../../typeorm/repository/LoginUser'
|
import { LoginUserRepository } from '../../typeorm/repository/LoginUser'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
# Test
|
# Test
|
||||||
@ -465,7 +466,7 @@ async function getPublicKey(email: string): Promise<string | null> {
|
|||||||
|
|
||||||
@Resolver()
|
@Resolver()
|
||||||
export class TransactionResolver {
|
export class TransactionResolver {
|
||||||
@Authorized()
|
@Authorized([RIGHTS.TRANSACTION_LIST])
|
||||||
@Query(() => TransactionList)
|
@Query(() => TransactionList)
|
||||||
async transactionList(
|
async transactionList(
|
||||||
@Args() { currentPage = 1, pageSize = 25, order = Order.DESC }: Paginated,
|
@Args() { currentPage = 1, pageSize = 25, order = Order.DESC }: Paginated,
|
||||||
@ -499,7 +500,7 @@ export class TransactionResolver {
|
|||||||
return transactions
|
return transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.SEND_COINS])
|
||||||
@Mutation(() => String)
|
@Mutation(() => String)
|
||||||
async sendCoins(
|
async sendCoins(
|
||||||
@Args() { email, amount, memo }: TransactionSendArgs,
|
@Args() { email, amount, memo }: TransactionSendArgs,
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { LoginViaVerificationCode } from '../model/LoginViaVerificationCode'
|
|||||||
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
import { SendPasswordResetEmailResponse } from '../model/SendPasswordResetEmailResponse'
|
||||||
import { User } from '../model/User'
|
import { User } from '../model/User'
|
||||||
import { User as DbUser } from '@entity/User'
|
import { User as DbUser } from '@entity/User'
|
||||||
import encode from '../../jwt/encode'
|
import { encode } from '../../auth/JWT'
|
||||||
import ChangePasswordArgs from '../arg/ChangePasswordArgs'
|
import ChangePasswordArgs from '../arg/ChangePasswordArgs'
|
||||||
import CheckUsernameArgs from '../arg/CheckUsernameArgs'
|
import CheckUsernameArgs from '../arg/CheckUsernameArgs'
|
||||||
import CreateUserArgs from '../arg/CreateUserArgs'
|
import CreateUserArgs from '../arg/CreateUserArgs'
|
||||||
@ -30,6 +30,7 @@ import { LoginUserBackup } from '@entity/LoginUserBackup'
|
|||||||
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
|
||||||
import { sendEMail } from '../../util/sendEMail'
|
import { sendEMail } from '../../util/sendEMail'
|
||||||
import { LoginElopageBuysRepository } from '../../typeorm/repository/LoginElopageBuys'
|
import { LoginElopageBuysRepository } from '../../typeorm/repository/LoginElopageBuys'
|
||||||
|
import { RIGHTS } from '../../auth/RIGHTS'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const sodium = require('sodium-native')
|
const sodium = require('sodium-native')
|
||||||
@ -224,6 +225,7 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.LOGIN])
|
||||||
@Query(() => User)
|
@Query(() => User)
|
||||||
@UseMiddleware(klicktippNewsletterStateMiddleware)
|
@UseMiddleware(klicktippNewsletterStateMiddleware)
|
||||||
async login(
|
async login(
|
||||||
@ -307,6 +309,7 @@ export class UserResolver {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.LOGIN_VIA_EMAIL_VERIFICATION_CODE])
|
||||||
@Query(() => LoginViaVerificationCode)
|
@Query(() => LoginViaVerificationCode)
|
||||||
async loginViaEmailVerificationCode(
|
async loginViaEmailVerificationCode(
|
||||||
@Arg('optin') optin: string,
|
@Arg('optin') optin: string,
|
||||||
@ -322,7 +325,7 @@ export class UserResolver {
|
|||||||
return new LoginViaVerificationCode(result.data)
|
return new LoginViaVerificationCode(result.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.LOGOUT])
|
||||||
@Query(() => String)
|
@Query(() => String)
|
||||||
async logout(): Promise<boolean> {
|
async logout(): Promise<boolean> {
|
||||||
// TODO: We dont need this anymore, but might need this in the future in oder to invalidate a valid JWT-Token.
|
// TODO: We dont need this anymore, but might need this in the future in oder to invalidate a valid JWT-Token.
|
||||||
@ -333,6 +336,7 @@ export class UserResolver {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.CREATE_USER])
|
||||||
@Mutation(() => String)
|
@Mutation(() => String)
|
||||||
async createUser(
|
async createUser(
|
||||||
@Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs,
|
@Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs,
|
||||||
@ -481,6 +485,7 @@ export class UserResolver {
|
|||||||
return 'success'
|
return 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.SEND_RESET_PASSWORD_EMAIL])
|
||||||
@Query(() => SendPasswordResetEmailResponse)
|
@Query(() => SendPasswordResetEmailResponse)
|
||||||
async sendResetPasswordEmail(
|
async sendResetPasswordEmail(
|
||||||
@Arg('email') email: string,
|
@Arg('email') email: string,
|
||||||
@ -497,6 +502,7 @@ export class UserResolver {
|
|||||||
return new SendPasswordResetEmailResponse(response.data)
|
return new SendPasswordResetEmailResponse(response.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.RESET_PASSWORD])
|
||||||
@Mutation(() => String)
|
@Mutation(() => String)
|
||||||
async resetPassword(
|
async resetPassword(
|
||||||
@Args()
|
@Args()
|
||||||
@ -514,7 +520,7 @@ export class UserResolver {
|
|||||||
return 'success'
|
return 'success'
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.UPDATE_USER_INFOS])
|
||||||
@Mutation(() => Boolean)
|
@Mutation(() => Boolean)
|
||||||
async updateUserInfos(
|
async updateUserInfos(
|
||||||
@Args()
|
@Args()
|
||||||
@ -623,6 +629,7 @@ export class UserResolver {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.CHECK_USERNAME])
|
||||||
@Query(() => Boolean)
|
@Query(() => Boolean)
|
||||||
async checkUsername(@Args() { username }: CheckUsernameArgs): Promise<boolean> {
|
async checkUsername(@Args() { username }: CheckUsernameArgs): Promise<boolean> {
|
||||||
// Username empty?
|
// Username empty?
|
||||||
@ -646,6 +653,7 @@ export class UserResolver {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authorized([RIGHTS.CHECK_EMAIL])
|
||||||
@Query(() => CheckEmailResponse)
|
@Query(() => CheckEmailResponse)
|
||||||
@UseMiddleware(klicktippRegistrationMiddleware)
|
@UseMiddleware(klicktippRegistrationMiddleware)
|
||||||
async checkEmail(@Arg('optin') optin: string): Promise<CheckEmailResponse> {
|
async checkEmail(@Arg('optin') optin: string): Promise<CheckEmailResponse> {
|
||||||
@ -658,7 +666,7 @@ export class UserResolver {
|
|||||||
return new CheckEmailResponse(result.data)
|
return new CheckEmailResponse(result.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Authorized()
|
@Authorized([RIGHTS.HAS_ELOPAGE])
|
||||||
@Query(() => Boolean)
|
@Query(() => Boolean)
|
||||||
async hasElopage(@Ctx() context: any): Promise<boolean> {
|
async hasElopage(@Ctx() context: any): Promise<boolean> {
|
||||||
const userRepository = getCustomRepository(UserRepository)
|
const userRepository = getCustomRepository(UserRepository)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user