• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 11006384343

24 Sep 2024 03:21AM UTC coverage: 84.88%. First build
11006384343

Pull #935

github

web-flow
Merge 6bbc04eb9 into 10c0ccaac
Pull Request #935: feat: cross base link

5630 of 5934 branches covered (94.88%)

64 of 110 new or added lines in 6 files covered. (58.18%)

36944 of 43525 relevant lines covered (84.88%)

1163.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.92
/apps/nestjs-backend/src/features/share/guard/auth.guard.ts
1
import type { ExecutionContext } from '@nestjs/common';
4✔
2
import { Injectable } from '@nestjs/common';
4✔
3
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
4✔
4
import { ANONYMOUS_USER_ID, HttpErrorCode, IdPrefix } from '@teable/core';
4✔
5
import { ClsService } from 'nestjs-cls';
4✔
6
import { CustomHttpException } from '../../../custom.exception';
4✔
7
import type { IClsStore } from '../../../types/cls';
4✔
8
import { ShareAuthService } from '../share-auth.service';
4✔
9
import { SHARE_JWT_STRATEGY } from './constant';
4✔
10

4✔
11
@Injectable()
4✔
12
export class AuthGuard extends PassportAuthGuard([SHARE_JWT_STRATEGY]) {
4✔
13
  constructor(
272✔
14
    private readonly shareAuthService: ShareAuthService,
272✔
15
    private readonly cls: ClsService<IClsStore>
272✔
16
  ) {
272✔
17
    super();
272✔
18
  }
272✔
19

272✔
20
  async validate(context: ExecutionContext, shareId: string) {
272✔
21
    const req = context.switchToHttp().getRequest();
42✔
22
    try {
42✔
23
      const shareInfo = shareId.startsWith(IdPrefix.Field)
42✔
NEW
24
        ? await this.shareAuthService.getLinkViewInfo(shareId)
×
25
        : await this.shareAuthService.getShareViewInfo(shareId);
42✔
26
      req.shareInfo = shareInfo;
40✔
27

40✔
28
      this.cls.set('user', {
40✔
29
        id: ANONYMOUS_USER_ID,
40✔
30
        name: ANONYMOUS_USER_ID,
40✔
31
        email: '',
40✔
32
      });
40✔
33

40✔
34
      if (shareInfo.view?.shareMeta?.password) {
42✔
35
        return (await super.canActivate(context)) as boolean;
4✔
36
      }
4✔
37
      return true;
36✔
38
    } catch (err) {
42✔
39
      throw new CustomHttpException('Unauthorized', HttpErrorCode.UNAUTHORIZED_SHARE);
4✔
40
    }
4✔
41
  }
42✔
42

272✔
43
  async canActivate(context: ExecutionContext): Promise<boolean> {
272✔
44
    const req = context.switchToHttp().getRequest();
42✔
45
    const shareId = req.params.shareId;
42✔
46
    return this.validate(context, shareId);
42✔
47
  }
42✔
48
}
272✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc