From 9d0a62033101b003d2574c4605612d1d19995a90 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 14:00:54 +0100 Subject: [PATCH 1/3] prefix admin right with ADMIN_ --- backend/src/auth/RIGHTS.ts | 26 +++++++++---------- .../resolver/ContributionLinkResolver.ts | 6 ++--- .../graphql/resolver/ContributionResolver.ts | 8 +++--- .../resolver/TransactionLinkResolver.ts | 2 +- backend/src/graphql/resolver/UserResolver.ts | 10 +++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index 8b0e82c86..f6db44b90 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -37,21 +37,21 @@ export enum RIGHTS { LIST_ALL_CONTRIBUTION_MESSAGES = 'LIST_ALL_CONTRIBUTION_MESSAGES', OPEN_CREATIONS = 'OPEN_CREATIONS', // Admin - SEARCH_USERS = 'SEARCH_USERS', - SET_USER_ROLE = 'SET_USER_ROLE', - DELETE_USER = 'DELETE_USER', - UNDELETE_USER = 'UNDELETE_USER', + ADMIN_SEARCH_USERS = 'SEARCH_USERS', + ADMIN_SET_USER_ROLE = 'SET_USER_ROLE', + ADMIN_DELETE_USER = 'DELETE_USER', + ADMIN_UNDELETE_USER = 'UNDELETE_USER', ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION', ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION', ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION', - LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', - CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', - SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', - CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', - LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', - CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', - DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', - UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', + ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', + ADMIN_CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', + ADMIN_SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', + ADMIN_CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', + ADMIN_LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', + ADMIN_CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', + ADMIN_DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', + ADMIN_UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', - DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', + ADMIN_DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', } diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 39f202848..d3c77cb82 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -24,7 +24,7 @@ import LogError from '@/server/LogError' @Resolver() export class ContributionLinkResolver { - @Authorized([RIGHTS.CREATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_CREATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async createContributionLink( @Args() @@ -90,7 +90,7 @@ export class ContributionLinkResolver { } } - @Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) @Mutation(() => Date, { nullable: true }) async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { const contributionLink = await DbContributionLink.findOne(id) @@ -103,7 +103,7 @@ export class ContributionLinkResolver { return newContributionLink ? newContributionLink.deletedAt : null } - @Authorized([RIGHTS.UPDATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async updateContributionLink( @Args() diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 1b8d24d2b..0d27739f9 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -390,7 +390,7 @@ export class ContributionResolver { return result } - @Authorized([RIGHTS.LIST_UNCONFIRMED_CONTRIBUTIONS]) + @Authorized([RIGHTS.ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS]) @Query(() => ContributionListResult) // [UnconfirmedContribution] async adminListAllContributions( @Args() @@ -461,7 +461,7 @@ export class ContributionResolver { return !!res } - @Authorized([RIGHTS.CONFIRM_CONTRIBUTION]) + @Authorized([RIGHTS.ADMIN_CONFIRM_CONTRIBUTION]) @Mutation(() => Boolean) async confirmContribution( @Arg('id', () => Int) id: number, @@ -566,7 +566,7 @@ export class ContributionResolver { return true } - @Authorized([RIGHTS.CREATION_TRANSACTION_LIST]) + @Authorized([RIGHTS.ADMIN_CREATION_TRANSACTION_LIST]) @Query(() => ContributionListResult) async creationTransactionList( @Args() @@ -612,7 +612,7 @@ export class ContributionResolver { }) } - @Authorized([RIGHTS.DENY_CONTRIBUTION]) + @Authorized([RIGHTS.ADMIN_DENY_CONTRIBUTION]) @Mutation(() => Boolean) async denyContribution( @Arg('id', () => Int) id: number, diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index ab5b52bad..66d0fbb4b 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -336,7 +336,7 @@ export class TransactionLinkResolver { ) } - @Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN]) + @Authorized([RIGHTS.ADMIN_LIST_TRANSACTION_LINKS_ADMIN]) @Query(() => TransactionLinkResult) async listTransactionLinksAdmin( @Args() diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 435ca3c82..d79b0444e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -640,7 +640,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.SEARCH_USERS]) + @Authorized([RIGHTS.ADMIN_SEARCH_USERS]) @Query(() => SearchUsersResult) async searchUsers( @Args() @@ -706,7 +706,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.SET_USER_ROLE]) + @Authorized([RIGHTS.ADMIN_SET_USER_ROLE]) @Mutation(() => Date, { nullable: true }) async setUserRole( @Arg('userId', () => Int) @@ -748,7 +748,7 @@ export class UserResolver { return newUser ? newUser.isAdmin : null } - @Authorized([RIGHTS.DELETE_USER]) + @Authorized([RIGHTS.ADMIN_DELETE_USER]) @Mutation(() => Date, { nullable: true }) async deleteUser( @Arg('userId', () => Int) userId: number, @@ -770,7 +770,7 @@ export class UserResolver { return newUser ? newUser.deletedAt : null } - @Authorized([RIGHTS.UNDELETE_USER]) + @Authorized([RIGHTS.ADMIN_UNDELETE_USER]) @Mutation(() => Date, { nullable: true }) async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise { const user = await DbUser.findOne({ id: userId }, { withDeleted: true }) @@ -785,7 +785,7 @@ export class UserResolver { } // TODO this is an admin function - needs refactor - @Authorized([RIGHTS.SEND_ACTIVATION_EMAIL]) + @Authorized([RIGHTS.ADMIN_SEND_ACTIVATION_EMAIL]) @Mutation(() => Boolean) async sendActivationEmail( @Arg('email') email: string, From d204e79cd5ddbdbfe2eb01a07c86ca96c52e2ba3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 6 Mar 2023 15:29:37 +0100 Subject: [PATCH 2/3] rename eventProtocolType to eventType --- backend/src/event/Event.ts | 64 ++++++------------- .../{EventProtocolType.ts => EventType.ts} | 2 +- .../resolver/ContributionResolver.test.ts | 22 +++---- .../resolver/TransactionResolver.test.ts | 6 +- .../src/graphql/resolver/UserResolver.test.ts | 20 +++--- backend/src/graphql/resolver/UserResolver.ts | 4 +- 6 files changed, 45 insertions(+), 73 deletions(-) rename backend/src/event/{EventProtocolType.ts => EventType.ts} (98%) diff --git a/backend/src/event/Event.ts b/backend/src/event/Event.ts index 7ed75fd45..720cb2799 100644 --- a/backend/src/event/Event.ts +++ b/backend/src/event/Event.ts @@ -4,10 +4,10 @@ import { ContributionMessage as DbContributionMessage } from '@entity/Contributi import { Contribution as DbContribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import Decimal from 'decimal.js-light' -import { EventProtocolType } from './EventProtocolType' +import { EventType } from './EventType' export const Event = ( - type: EventProtocolType, + type: EventType, affectedUser: DbUser, actingUser: DbUser, involvedUser: DbUser | null = null, @@ -33,48 +33,21 @@ export const EVENT_CONTRIBUTION_CREATE = async ( contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_CREATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_CREATE, user, user, null, null, contribution, null, amount).save() export const EVENT_CONTRIBUTION_DELETE = async ( user: DbUser, contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_DELETE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_DELETE, user, user, null, null, contribution, null, amount).save() export const EVENT_CONTRIBUTION_UPDATE = async ( user: DbUser, contribution: DbContribution, amount: Decimal, ): Promise => - Event( - EventProtocolType.CONTRIBUTION_UPDATE, - user, - user, - null, - null, - contribution, - null, - amount, - ).save() + Event(EventType.CONTRIBUTION_UPDATE, user, user, null, null, contribution, null, amount).save() export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( user: DbUser, @@ -83,7 +56,7 @@ export const EVENT_ADMIN_CONTRIBUTION_CREATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + EventType.ADMIN_CONTRIBUTION_CREATE, user, moderator, null, @@ -100,7 +73,7 @@ export const EVENT_ADMIN_CONTRIBUTION_UPDATE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + EventType.ADMIN_CONTRIBUTION_UPDATE, user, moderator, null, @@ -117,7 +90,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DELETE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + EventType.ADMIN_CONTRIBUTION_DELETE, user, moderator, null, @@ -134,7 +107,7 @@ export const EVENT_CONTRIBUTION_CONFIRM = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.CONTRIBUTION_CONFIRM, + EventType.CONTRIBUTION_CONFIRM, user, moderator, null, @@ -151,7 +124,7 @@ export const EVENT_ADMIN_CONTRIBUTION_DENY = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.ADMIN_CONTRIBUTION_DENY, + EventType.ADMIN_CONTRIBUTION_DENY, user, moderator, null, @@ -168,7 +141,7 @@ export const EVENT_TRANSACTION_SEND = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_SEND, + EventType.TRANSACTION_SEND, user, user, involvedUser, @@ -185,7 +158,7 @@ export const EVENT_TRANSACTION_RECEIVE = async ( amount: Decimal, ): Promise => Event( - EventProtocolType.TRANSACTION_RECEIVE, + EventType.TRANSACTION_RECEIVE, user, involvedUser, involvedUser, @@ -196,22 +169,21 @@ export const EVENT_TRANSACTION_RECEIVE = async ( ).save() export const EVENT_LOGIN = async (user: DbUser): Promise => - Event(EventProtocolType.LOGIN, user, user).save() + Event(EventType.LOGIN, user, user).save() export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() + Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save() export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise => - Event(EventProtocolType.SEND_CONFIRMATION_EMAIL, user, user).save() + Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save() export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async ( user: DbUser, moderator: DbUser, -): Promise => - Event(EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() +): Promise => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save() export const EVENT_REGISTER = async (user: DbUser): Promise => - Event(EventProtocolType.REGISTER, user, user).save() + Event(EventType.REGISTER, user, user).save() export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise => - Event(EventProtocolType.ACTIVATE_ACCOUNT, user, user).save() + Event(EventType.ACTIVATE_ACCOUNT, user, user).save() diff --git a/backend/src/event/EventProtocolType.ts b/backend/src/event/EventType.ts similarity index 98% rename from backend/src/event/EventProtocolType.ts rename to backend/src/event/EventType.ts index 3a4c914c1..360d5efb4 100644 --- a/backend/src/event/EventProtocolType.ts +++ b/backend/src/event/EventType.ts @@ -1,4 +1,4 @@ -export enum EventProtocolType { +export enum EventType { // VISIT_GRADIDO = 'VISIT_GRADIDO', REGISTER = 'REGISTER', REDEEM_REGISTER = 'REDEEM_REGISTER', diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index def4fdf96..cc2115f3f 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -45,7 +45,7 @@ import { Event as DbEvent } from '@entity/Event' import { Contribution } from '@entity/Contribution' import { Transaction as DbTransaction } from '@entity/Transaction' import { User } from '@entity/User' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { logger, i18n as localization } from '@test/testSetup' import { UserInputError } from 'apollo-server-express' import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz' @@ -276,7 +276,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CREATE, + type: EventType.CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -582,7 +582,7 @@ describe('ContributionResolver', () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_UPDATE, + type: EventType.CONTRIBUTION_UPDATE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: pendingContribution.data.createContribution.id, @@ -813,7 +813,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DENY event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DENY, + type: EventType.ADMIN_CONTRIBUTION_DENY, affectedUserId: bibi.id, actingUserId: admin.id, involvedContributionId: contributionToDeny.data.createContribution.id, @@ -941,7 +941,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_DELETE, + type: EventType.CONTRIBUTION_DELETE, affectedUserId: bibi.id, actingUserId: bibi.id, involvedContributionId: contributionToDelete.data.createContribution.id, @@ -2032,7 +2032,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_CREATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_CREATE, + type: EventType.ADMIN_CONTRIBUTION_CREATE, affectedUserId: bibi.id, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2258,7 +2258,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: 300, @@ -2300,7 +2300,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_UPDATE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_UPDATE, + type: EventType.ADMIN_CONTRIBUTION_UPDATE, affectedUserId: creation?.userId, actingUserId: admin.id, amount: expect.decimalEqual(200), @@ -2386,7 +2386,7 @@ describe('ContributionResolver', () => { it('stores the ADMIN_CONTRIBUTION_DELETE event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_CONTRIBUTION_DELETE, + type: EventType.ADMIN_CONTRIBUTION_DELETE, affectedUserId: creation?.userId, actingUserId: admin.id, involvedContributionId: creation?.id, @@ -2544,7 +2544,7 @@ describe('ContributionResolver', () => { it('stores the CONTRIBUTION_CONFIRM event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.CONTRIBUTION_CONFIRM, + type: EventType.CONTRIBUTION_CONFIRM, }), ) }) @@ -2576,7 +2576,7 @@ describe('ContributionResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, }), ) }) diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index 6ddbb8191..590a1fca3 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import Decimal from 'decimal.js-light' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { userFactory } from '@/seeds/factory/user' import { confirmContribution, @@ -339,7 +339,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_SEND, + type: EventType.TRANSACTION_SEND, affectedUserId: user[1].id, actingUserId: user[1].id, involvedUserId: user[0].id, @@ -357,7 +357,7 @@ describe('send coins', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.TRANSACTION_RECEIVE, + type: EventType.TRANSACTION_RECEIVE, affectedUserId: user[0].id, actingUserId: user[1].id, involvedUserId: user[1].id, diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index e627f4f0f..36a591a49 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -34,7 +34,7 @@ import { contributionLinkFactory } from '@/seeds/factory/contributionLink' import { transactionLinkFactory } from '@/seeds/factory/transactionLink' import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' import { Event as DbEvent } from '@entity/Event' import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' @@ -184,7 +184,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REGISTER, + type: EventType.REGISTER, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -214,7 +214,7 @@ describe('UserResolver', () => { it('stores the SEND_CONFIRMATION_EMAIL event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_CONFIRMATION_EMAIL, + type: EventType.SEND_CONFIRMATION_EMAIL, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -260,7 +260,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, + type: EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: 0, }), @@ -361,7 +361,7 @@ describe('UserResolver', () => { it('stores the ACTIVATE_ACCOUNT event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ACTIVATE_ACCOUNT, + type: EventType.ACTIVATE_ACCOUNT, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -371,7 +371,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: result.data.createUser.id, actingUserId: result.data.createUser.id, involvedContributionId: link.id, @@ -456,7 +456,7 @@ describe('UserResolver', () => { it('stores the REDEEM_REGISTER event in the database', async () => { await expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.REDEEM_REGISTER, + type: EventType.REDEEM_REGISTER, affectedUserId: newUser.data.createUser.id, actingUserId: newUser.data.createUser.id, involvedTransactionId: transactionLink.id, @@ -689,7 +689,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: userConatct.user.id, actingUserId: userConatct.user.id, }), @@ -938,7 +938,7 @@ describe('UserResolver', () => { it('stores the LOGIN event in the database', () => { expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.LOGIN, + type: EventType.LOGIN, affectedUserId: user[0].id, actingUserId: user[0].id, }), @@ -1858,7 +1858,7 @@ describe('UserResolver', () => { ) expect(DbEvent.find()).resolves.toContainEqual( expect.objectContaining({ - type: EventProtocolType.ADMIN_SEND_CONFIRMATION_EMAIL, + type: EventType.ADMIN_SEND_CONFIRMATION_EMAIL, affectedUserId: userConatct.user.id, actingUserId: admin.id, }), diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index d79b0444e..67f263709 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -65,7 +65,7 @@ import { FULL_CREATION_AVAILABLE } from './const/const' import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor' import { PasswordEncryptionType } from '../enum/PasswordEncryptionType' import LogError from '@/server/LogError' -import { EventProtocolType } from '@/event/EventProtocolType' +import { EventType } from '@/event/EventType' // eslint-disable-next-line @typescript-eslint/no-var-requires const sodium = require('sodium-native') @@ -269,7 +269,7 @@ export class UserResolver { const gradidoID = await newGradidoID() const eventRegisterRedeem = Event( - EventProtocolType.REDEEM_REGISTER, + EventType.REDEEM_REGISTER, { id: 0 } as DbUser, { id: 0 } as DbUser, ) From 413f663e4d7b81a56a5752bba89f9f05e362050a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 23 Mar 2023 11:59:38 +0100 Subject: [PATCH 3/3] reverted 9d0a62033101b003d2574c4605612d1d19995a90 --- backend/src/auth/RIGHTS.ts | 26 +++++++++---------- .../resolver/ContributionLinkResolver.ts | 6 ++--- .../graphql/resolver/ContributionResolver.ts | 8 +++--- .../resolver/TransactionLinkResolver.ts | 2 +- backend/src/graphql/resolver/UserResolver.ts | 10 +++---- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index f6db44b90..8b0e82c86 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -37,21 +37,21 @@ export enum RIGHTS { LIST_ALL_CONTRIBUTION_MESSAGES = 'LIST_ALL_CONTRIBUTION_MESSAGES', OPEN_CREATIONS = 'OPEN_CREATIONS', // Admin - ADMIN_SEARCH_USERS = 'SEARCH_USERS', - ADMIN_SET_USER_ROLE = 'SET_USER_ROLE', - ADMIN_DELETE_USER = 'DELETE_USER', - ADMIN_UNDELETE_USER = 'UNDELETE_USER', + SEARCH_USERS = 'SEARCH_USERS', + SET_USER_ROLE = 'SET_USER_ROLE', + DELETE_USER = 'DELETE_USER', + UNDELETE_USER = 'UNDELETE_USER', ADMIN_CREATE_CONTRIBUTION = 'ADMIN_CREATE_CONTRIBUTION', ADMIN_UPDATE_CONTRIBUTION = 'ADMIN_UPDATE_CONTRIBUTION', ADMIN_DELETE_CONTRIBUTION = 'ADMIN_DELETE_CONTRIBUTION', - ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', - ADMIN_CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', - ADMIN_SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', - ADMIN_CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', - ADMIN_LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', - ADMIN_CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', - ADMIN_DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', - ADMIN_UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', + LIST_UNCONFIRMED_CONTRIBUTIONS = 'LIST_UNCONFIRMED_CONTRIBUTIONS', + CONFIRM_CONTRIBUTION = 'CONFIRM_CONTRIBUTION', + SEND_ACTIVATION_EMAIL = 'SEND_ACTIVATION_EMAIL', + CREATION_TRANSACTION_LIST = 'CREATION_TRANSACTION_LIST', + LIST_TRANSACTION_LINKS_ADMIN = 'LIST_TRANSACTION_LINKS_ADMIN', + CREATE_CONTRIBUTION_LINK = 'CREATE_CONTRIBUTION_LINK', + DELETE_CONTRIBUTION_LINK = 'DELETE_CONTRIBUTION_LINK', + UPDATE_CONTRIBUTION_LINK = 'UPDATE_CONTRIBUTION_LINK', ADMIN_CREATE_CONTRIBUTION_MESSAGE = 'ADMIN_CREATE_CONTRIBUTION_MESSAGE', - ADMIN_DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', + DENY_CONTRIBUTION = 'DENY_CONTRIBUTION', } diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index d3c77cb82..39f202848 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -24,7 +24,7 @@ import LogError from '@/server/LogError' @Resolver() export class ContributionLinkResolver { - @Authorized([RIGHTS.ADMIN_CREATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.CREATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async createContributionLink( @Args() @@ -90,7 +90,7 @@ export class ContributionLinkResolver { } } - @Authorized([RIGHTS.ADMIN_DELETE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.DELETE_CONTRIBUTION_LINK]) @Mutation(() => Date, { nullable: true }) async deleteContributionLink(@Arg('id', () => Int) id: number): Promise { const contributionLink = await DbContributionLink.findOne(id) @@ -103,7 +103,7 @@ export class ContributionLinkResolver { return newContributionLink ? newContributionLink.deletedAt : null } - @Authorized([RIGHTS.ADMIN_UPDATE_CONTRIBUTION_LINK]) + @Authorized([RIGHTS.UPDATE_CONTRIBUTION_LINK]) @Mutation(() => ContributionLink) async updateContributionLink( @Args() diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 0d27739f9..1b8d24d2b 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -390,7 +390,7 @@ export class ContributionResolver { return result } - @Authorized([RIGHTS.ADMIN_LIST_UNCONFIRMED_CONTRIBUTIONS]) + @Authorized([RIGHTS.LIST_UNCONFIRMED_CONTRIBUTIONS]) @Query(() => ContributionListResult) // [UnconfirmedContribution] async adminListAllContributions( @Args() @@ -461,7 +461,7 @@ export class ContributionResolver { return !!res } - @Authorized([RIGHTS.ADMIN_CONFIRM_CONTRIBUTION]) + @Authorized([RIGHTS.CONFIRM_CONTRIBUTION]) @Mutation(() => Boolean) async confirmContribution( @Arg('id', () => Int) id: number, @@ -566,7 +566,7 @@ export class ContributionResolver { return true } - @Authorized([RIGHTS.ADMIN_CREATION_TRANSACTION_LIST]) + @Authorized([RIGHTS.CREATION_TRANSACTION_LIST]) @Query(() => ContributionListResult) async creationTransactionList( @Args() @@ -612,7 +612,7 @@ export class ContributionResolver { }) } - @Authorized([RIGHTS.ADMIN_DENY_CONTRIBUTION]) + @Authorized([RIGHTS.DENY_CONTRIBUTION]) @Mutation(() => Boolean) async denyContribution( @Arg('id', () => Int) id: number, diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index 66d0fbb4b..ab5b52bad 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -336,7 +336,7 @@ export class TransactionLinkResolver { ) } - @Authorized([RIGHTS.ADMIN_LIST_TRANSACTION_LINKS_ADMIN]) + @Authorized([RIGHTS.LIST_TRANSACTION_LINKS_ADMIN]) @Query(() => TransactionLinkResult) async listTransactionLinksAdmin( @Args() diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 67f263709..4ca2889e2 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -640,7 +640,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.ADMIN_SEARCH_USERS]) + @Authorized([RIGHTS.SEARCH_USERS]) @Query(() => SearchUsersResult) async searchUsers( @Args() @@ -706,7 +706,7 @@ export class UserResolver { } } - @Authorized([RIGHTS.ADMIN_SET_USER_ROLE]) + @Authorized([RIGHTS.SET_USER_ROLE]) @Mutation(() => Date, { nullable: true }) async setUserRole( @Arg('userId', () => Int) @@ -748,7 +748,7 @@ export class UserResolver { return newUser ? newUser.isAdmin : null } - @Authorized([RIGHTS.ADMIN_DELETE_USER]) + @Authorized([RIGHTS.DELETE_USER]) @Mutation(() => Date, { nullable: true }) async deleteUser( @Arg('userId', () => Int) userId: number, @@ -770,7 +770,7 @@ export class UserResolver { return newUser ? newUser.deletedAt : null } - @Authorized([RIGHTS.ADMIN_UNDELETE_USER]) + @Authorized([RIGHTS.UNDELETE_USER]) @Mutation(() => Date, { nullable: true }) async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise { const user = await DbUser.findOne({ id: userId }, { withDeleted: true }) @@ -785,7 +785,7 @@ export class UserResolver { } // TODO this is an admin function - needs refactor - @Authorized([RIGHTS.ADMIN_SEND_ACTIVATION_EMAIL]) + @Authorized([RIGHTS.SEND_ACTIVATION_EMAIL]) @Mutation(() => Boolean) async sendActivationEmail( @Arg('email') email: string,