mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat: user usage gql & test case improve (#5076)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { HttpStatus } from '@nestjs/common';
|
||||
import {
|
||||
Args,
|
||||
Context,
|
||||
Field,
|
||||
Int,
|
||||
Mutation,
|
||||
@@ -254,8 +255,13 @@ export class UserSubscriptionResolver {
|
||||
constructor(private readonly db: PrismaService) {}
|
||||
|
||||
@ResolveField(() => UserSubscriptionType, { nullable: true })
|
||||
async subscription(@CurrentUser() me: User, @Parent() user: User) {
|
||||
if (me.id !== user.id) {
|
||||
async subscription(
|
||||
@Context() ctx: { isAdminQuery: boolean },
|
||||
@CurrentUser() me: User,
|
||||
@Parent() user: User
|
||||
) {
|
||||
// allow admin to query other user's subscription
|
||||
if (!ctx.isAdminQuery && me.id !== user.id) {
|
||||
throw new GraphQLError(
|
||||
'You are not allowed to access this subscription',
|
||||
{
|
||||
|
||||
@@ -17,5 +17,4 @@ import { QuotaManagementService } from './storage';
|
||||
export class QuotaModule {}
|
||||
|
||||
export { QuotaManagementService, QuotaService };
|
||||
export { PrismaService } from '../../prisma';
|
||||
export { Quota_FreePlanV1, Quota_ProPlanV1, Quotas, QuotaType } from './types';
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
Args,
|
||||
Context,
|
||||
Field,
|
||||
ID,
|
||||
Int,
|
||||
@@ -267,10 +268,15 @@ export class UserResolver {
|
||||
},
|
||||
})
|
||||
@Query(() => [UserType])
|
||||
async listEarlyAccess(@CurrentUser() user: UserType): Promise<UserType[]> {
|
||||
async earlyAccessUsers(
|
||||
@Context() ctx: { isAdminQuery: boolean },
|
||||
@CurrentUser() user: UserType
|
||||
): Promise<UserType[]> {
|
||||
if (!this.feature.isStaff(user.email)) {
|
||||
throw new ForbiddenException('You are not allowed to do this');
|
||||
}
|
||||
// allow query other user's subscription
|
||||
ctx.isAdminQuery = true;
|
||||
return this.feature.listEarlyAccess();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user