mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(server): add public user type (#10006)
This commit is contained in:
@@ -13,4 +13,4 @@ import { UserManagementResolver, UserResolver } from './resolver';
|
||||
})
|
||||
export class UserModule {}
|
||||
|
||||
export { UserType } from './types';
|
||||
export { PublicUserType, UserType } from './types';
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@nestjs/graphql';
|
||||
import type { User } from '@prisma/client';
|
||||
|
||||
import { PublicUser } from '../../models';
|
||||
import { type CurrentUser } from '../auth/session';
|
||||
|
||||
@ObjectType()
|
||||
@@ -42,6 +43,21 @@ export class UserType implements CurrentUser {
|
||||
createdAt?: Date | null;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class PublicUserType implements PublicUser {
|
||||
@Field()
|
||||
id!: string;
|
||||
|
||||
@Field()
|
||||
name!: string;
|
||||
|
||||
@Field()
|
||||
email!: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
avatarUrl!: string | null;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class LimitedUserType implements Partial<User> {
|
||||
@Field({ description: 'User email' })
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
PaginationInput,
|
||||
registerObjectType,
|
||||
} from '../../../base';
|
||||
import { Models } from '../../../models';
|
||||
import { CurrentUser } from '../../auth';
|
||||
import {
|
||||
DOC_ACTIONS,
|
||||
@@ -38,6 +39,7 @@ import {
|
||||
PublicPageMode,
|
||||
WorkspaceRole,
|
||||
} from '../../permission';
|
||||
import { PublicUserType } from '../../user';
|
||||
import { DocID } from '../../utils/doc';
|
||||
import { WorkspaceType } from '../types';
|
||||
|
||||
@@ -117,17 +119,11 @@ class UpdatePageDefaultRoleInput {
|
||||
|
||||
@ObjectType()
|
||||
class GrantedDocUserType {
|
||||
@Field(() => String)
|
||||
workspaceId!: string;
|
||||
|
||||
@Field(() => String)
|
||||
pageId!: string;
|
||||
|
||||
@Field(() => String)
|
||||
userId!: string;
|
||||
|
||||
@Field(() => DocRole, { name: 'role' })
|
||||
type!: DocRole;
|
||||
|
||||
@Field(() => PublicUserType)
|
||||
user!: PublicUserType;
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
@@ -161,7 +157,8 @@ export class PagePermissionResolver {
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaClient,
|
||||
private readonly permission: PermissionService
|
||||
private readonly permission: PermissionService,
|
||||
private readonly models: Models
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -293,7 +290,27 @@ export class PagePermissionResolver {
|
||||
]);
|
||||
});
|
||||
|
||||
return paginate(permissions, 'createdAt', pagination, totalCount);
|
||||
const users = new Map<string, PublicUserType>(
|
||||
await Promise.all(
|
||||
permissions.map(
|
||||
async p =>
|
||||
[p.userId, await this.models.user.getPublicUser(p.userId)] as [
|
||||
string,
|
||||
PublicUserType,
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return paginate(
|
||||
permissions.map(p => ({
|
||||
...p,
|
||||
user: users.get(p.userId),
|
||||
})),
|
||||
'createdAt',
|
||||
pagination,
|
||||
totalCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user