Skip to content

Commit 468a5db

Browse files
fix: Remove console.log statements, add share permission check, update stage-9 plan, and add OAuth learning doc
- Replace console.log with NestJS Logger in prisma.service.ts - Remove security-sensitive password logging in users.service.ts - Remove debug logging in spaces.controller.ts and register page - Add proper permission check in share.service.ts (was TODO) - Remove stale TODO comment in tiptap-utils.ts - Use immutable pattern in users.service.ts avatar URL handling - Update stage-9 plan: mark all 20 features as completed - Add OAuth learning doc covering GitHub/Google full flow and principles
1 parent af380f3 commit 468a5db

8 files changed

Lines changed: 709 additions & 89 deletions

File tree

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
1+
import { Injectable, OnModuleInit, OnModuleDestroy, Logger } from '@nestjs/common';
22
import { PrismaClient } from '@prisma/client';
33

44
@Injectable()
55
export class PrismaService
66
extends PrismaClient
77
implements OnModuleInit, OnModuleDestroy
88
{
9+
private readonly logger = new Logger(PrismaService.name);
10+
911
async onModuleInit() {
1012
await this.$connect();
11-
console.log('Prisma Client connected to database');
13+
this.logger.log('Prisma Client connected to database');
1214
}
1315

1416
async onModuleDestroy() {
1517
await this.$disconnect();
16-
console.log('👋 Prisma Client disconnected from database');
18+
this.logger.log('Prisma Client disconnected from database');
1719
}
1820
}

apps/api/src/share/share.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@ export class ShareService {
2121
async create(userId: string, createShareDto: CreateShareDto) {
2222
const { documentId, type, password, expiresAt } = createShareDto;
2323

24-
// Check if document exists and user has permission (ownership or write)
25-
// For simplicity, checking if user is owner or has access.
26-
// Ideally use a permission guard system, but here we enforce it before creation.
2724
const document = await this.prisma.document.findUnique({
2825
where: { id: documentId },
29-
include: { space: true },
26+
include: {
27+
space: {
28+
include: {
29+
permissions: { where: { userId } },
30+
},
31+
},
32+
},
3033
});
3134

3235
if (!document) {
3336
throw new NotFoundException('Document not found');
3437
}
3538

36-
// TODO: Strict permission check can be added here.
37-
// Assuming the controller guard handles basic access, but we should verify ownership or editor role.
39+
if (document.space.permissions.length === 0) {
40+
throw new ForbiddenException('No permission to share this document');
41+
}
3842

3943
let hashedPassword = null;
4044
if (type === ShareType.PASSWORD && password) {
@@ -142,7 +146,7 @@ export class ShareService {
142146
where: { id: share.id },
143147
data: { viewCount: { increment: 1 } },
144148
})
145-
.catch(console.error);
149+
.catch(() => undefined);
146150

147151
if (share.type === ShareType.PASSWORD) {
148152
if (!accessToken) {

apps/api/src/spaces/spaces.controller.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,8 @@ export class SpacesController {
6666

6767
@Delete(':id')
6868
@ApiOperation({ summary: '删除空间' })
69-
async remove(@Request() req: RequestWithUser, @Param('id') id: string) {
70-
console.log(
71-
`[SpacesController] Deleting space ${id} for user ${req.user.id}`,
72-
);
73-
try {
74-
const result = await this.spacesService.remove(id, req.user.id);
75-
console.log(`[SpacesController] Successfully deleted space ${id}`);
76-
return result;
77-
} catch (error) {
78-
console.error(`[SpacesController] Failed to delete space ${id}:`, error);
79-
throw error;
80-
}
69+
remove(@Request() req: RequestWithUser, @Param('id') id: string) {
70+
return this.spacesService.remove(id, req.user.id);
8171
}
8272

8373
// ==================== Member Management ====================

apps/api/src/users/users.service.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ export class UsersService {
2121
}
2222

2323
// 哈希密码
24-
console.log(
25-
`Creating user ${email}, password length before hash: ${password.length}`,
26-
);
2724
const hashedPassword = await bcrypt.hash(password, 10);
2825

2926
// 创建用户
@@ -75,12 +72,7 @@ export class UsersService {
7572
plainPassword: string,
7673
hashedPassword: string,
7774
): Promise<boolean> {
78-
console.log(
79-
`Validating password. Plain length: ${plainPassword.length}, Hash length: ${hashedPassword.length}`,
80-
);
81-
const result = await bcrypt.compare(plainPassword, hashedPassword);
82-
console.log(`Password validation result: ${result}`);
83-
return result;
75+
return bcrypt.compare(plainPassword, hashedPassword);
8476
}
8577

8678
async updatePassword(userId: string, newPassword: string) {
@@ -118,7 +110,7 @@ export class UsersService {
118110
if (user.avatarUrl && !user.avatarUrl.startsWith('http')) {
119111
const baseUrl =
120112
process.env.MINIO_PUBLIC_ENDPOINT || 'http://localhost:9000';
121-
user.avatarUrl = `${baseUrl}/${user.avatarUrl}`;
113+
return { ...user, avatarUrl: `${baseUrl}/${user.avatarUrl}` };
122114
}
123115
return user;
124116
}

apps/web/src/app/auth/register/page.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export default function RegisterPage() {
5454
setIsLoading(true);
5555

5656
try {
57-
console.log('Register attempt:', {
58-
email: formData.email,
59-
passwordLength: formData.password.length,
60-
});
6157
await register({
6258
email: formData.email,
6359
name: formData.name,

apps/web/src/lib/tiptap-utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ export function findNodePosition(props: {
251251
let foundNode: PMNode | null = null
252252

253253
editor.state.doc.descendants((currentNode, pos) => {
254-
// TODO: Needed?
255-
// if (currentNode.type && currentNode.type.name === node!.type.name) {
256254
if (currentNode === node) {
257255
foundPos = pos
258256
foundNode = currentNode

0 commit comments

Comments
 (0)