mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08: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 class UserModule {}
|
||||||
|
|
||||||
export { UserType } from './types';
|
export { PublicUserType, UserType } from './types';
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
} from '@nestjs/graphql';
|
} from '@nestjs/graphql';
|
||||||
import type { User } from '@prisma/client';
|
import type { User } from '@prisma/client';
|
||||||
|
|
||||||
|
import { PublicUser } from '../../models';
|
||||||
import { type CurrentUser } from '../auth/session';
|
import { type CurrentUser } from '../auth/session';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@@ -42,6 +43,21 @@ export class UserType implements CurrentUser {
|
|||||||
createdAt?: Date | null;
|
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()
|
@ObjectType()
|
||||||
export class LimitedUserType implements Partial<User> {
|
export class LimitedUserType implements Partial<User> {
|
||||||
@Field({ description: 'User email' })
|
@Field({ description: 'User email' })
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
PaginationInput,
|
PaginationInput,
|
||||||
registerObjectType,
|
registerObjectType,
|
||||||
} from '../../../base';
|
} from '../../../base';
|
||||||
|
import { Models } from '../../../models';
|
||||||
import { CurrentUser } from '../../auth';
|
import { CurrentUser } from '../../auth';
|
||||||
import {
|
import {
|
||||||
DOC_ACTIONS,
|
DOC_ACTIONS,
|
||||||
@@ -38,6 +39,7 @@ import {
|
|||||||
PublicPageMode,
|
PublicPageMode,
|
||||||
WorkspaceRole,
|
WorkspaceRole,
|
||||||
} from '../../permission';
|
} from '../../permission';
|
||||||
|
import { PublicUserType } from '../../user';
|
||||||
import { DocID } from '../../utils/doc';
|
import { DocID } from '../../utils/doc';
|
||||||
import { WorkspaceType } from '../types';
|
import { WorkspaceType } from '../types';
|
||||||
|
|
||||||
@@ -117,17 +119,11 @@ class UpdatePageDefaultRoleInput {
|
|||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
class GrantedDocUserType {
|
class GrantedDocUserType {
|
||||||
@Field(() => String)
|
|
||||||
workspaceId!: string;
|
|
||||||
|
|
||||||
@Field(() => String)
|
|
||||||
pageId!: string;
|
|
||||||
|
|
||||||
@Field(() => String)
|
|
||||||
userId!: string;
|
|
||||||
|
|
||||||
@Field(() => DocRole, { name: 'role' })
|
@Field(() => DocRole, { name: 'role' })
|
||||||
type!: DocRole;
|
type!: DocRole;
|
||||||
|
|
||||||
|
@Field(() => PublicUserType)
|
||||||
|
user!: PublicUserType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@@ -161,7 +157,8 @@ export class PagePermissionResolver {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaClient,
|
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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ export class UserModel extends BaseModel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPublicUsers(ids: string[]): Promise<PublicUser[]> {
|
||||||
|
return this.db.user.findMany({
|
||||||
|
select: publicUserSelect,
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async getUserByEmail(email: string): Promise<User | null> {
|
async getUserByEmail(email: string): Promise<User | null> {
|
||||||
const rows = await this.db.$queryRaw<User[]>`
|
const rows = await this.db.$queryRaw<User[]>`
|
||||||
SELECT id, name, email, password, registered, email_verified as emailVerifiedAt, avatar_url as avatarUrl, registered, created_at as createdAt
|
SELECT id, name, email, password, registered, email_verified as emailVerifiedAt, avatar_url as avatarUrl, registered, created_at as createdAt
|
||||||
|
|||||||
@@ -385,10 +385,8 @@ input GrantDocUserRolesInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GrantedDocUserType {
|
type GrantedDocUserType {
|
||||||
pageId: String!
|
|
||||||
role: DocRole!
|
role: DocRole!
|
||||||
userId: String!
|
user: PublicUserType!
|
||||||
workspaceId: String!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GrantedDocUserTypeEdge {
|
type GrantedDocUserTypeEdge {
|
||||||
@@ -731,6 +729,13 @@ enum PublicPageMode {
|
|||||||
Page
|
Page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PublicUserType {
|
||||||
|
avatarUrl: String
|
||||||
|
email: String!
|
||||||
|
id: String!
|
||||||
|
name: String!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
collectAllBlobSizes: WorkspaceBlobSizes! @deprecated(reason: "use `user.quotaUsage` instead")
|
collectAllBlobSizes: WorkspaceBlobSizes! @deprecated(reason: "use `user.quotaUsage` instead")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user