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

teableio / teable / 11007026192

24 Sep 2024 04:31AM UTC coverage: 84.941% (-0.01%) from 84.954%
11007026192

Pull #935

github

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

5652 of 5956 branches covered (94.9%)

93 of 115 new or added lines in 7 files covered. (80.87%)

71 existing lines in 2 files now uncovered.

36974 of 43529 relevant lines covered (84.94%)

1164.31 hits per line

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

74.36
/apps/nestjs-backend/src/features/share/share-socket.service.ts
1
import { BadRequestException, ForbiddenException, Injectable } from '@nestjs/common';
4✔
2
import type { IGetFieldsQuery } from '@teable/core';
4✔
3
import type { IGetRecordsRo } from '@teable/openapi';
4✔
4
import { Knex } from 'knex';
4✔
5
import { difference } from 'lodash';
4✔
6
import { InjectModel } from 'nest-knexjs';
4✔
7
import { FieldService } from '../field/field.service';
4✔
8
import { RecordService } from '../record/record.service';
4✔
9
import { ViewService } from '../view/view.service';
4✔
10
import type { IShareViewInfo } from './share-auth.service';
4✔
11

4✔
12
@Injectable()
4✔
13
export class ShareSocketService {
4✔
14
  constructor(
93✔
15
    private readonly viewService: ViewService,
93✔
16
    private readonly fieldService: FieldService,
93✔
17
    private readonly recordService: RecordService,
93✔
18
    @InjectModel('CUSTOM_KNEX') private readonly knex: Knex
93✔
19
  ) {}
93✔
20

93✔
21
  getViewDocIdsByQuery(shareInfo: IShareViewInfo) {
93✔
22
    const { tableId, view } = shareInfo;
2✔
23
    if (!view) {
2✔
NEW
24
      throw new BadRequestException('view id is required');
×
NEW
25
    }
×
26
    return this.viewService.getDocIdsByQuery(tableId, {
2✔
27
      includeIds: [view.id],
2✔
28
    });
2✔
29
  }
2✔
30

93✔
31
  getViewSnapshotBulk(shareInfo: IShareViewInfo, ids: string[]) {
93✔
32
    const { tableId, view } = shareInfo;
2✔
33
    if (!view) {
2✔
NEW
34
      throw new BadRequestException('view id is required');
×
NEW
35
    }
×
36

2✔
37
    if (ids.length > 1 || ids[0] !== view.id) {
2✔
38
      throw new ForbiddenException('View permission not allowed: read');
×
39
    }
×
40
    return this.viewService.getSnapshotBulk(tableId, [view.id]);
2✔
41
  }
2✔
42

93✔
43
  getFieldDocIdsByQuery(shareInfo: IShareViewInfo, query: IGetFieldsQuery = {}) {
93✔
44
    const { tableId, view } = shareInfo;
4✔
45
    const filterHidden = !view?.shareMeta?.includeHiddenField;
4✔
46
    return this.fieldService.getDocIdsByQuery(tableId, {
4✔
47
      ...query,
4✔
48
      viewId: view?.id,
4✔
49
      filterHidden,
4✔
50
    });
4✔
51
  }
4✔
52

93✔
53
  async getFieldSnapshotBulk(shareInfo: IShareViewInfo, ids: string[]) {
93✔
54
    const { tableId } = shareInfo;
2✔
55
    const { ids: fieldIds } = await this.getFieldDocIdsByQuery(shareInfo);
2✔
56
    const unPermissionIds = difference(ids, fieldIds);
2✔
57
    if (unPermissionIds.length) {
2✔
58
      throw new ForbiddenException(
×
59
        `Field(${unPermissionIds.join(',')}) permission not allowed: read`
×
60
      );
×
61
    }
×
62
    return this.fieldService.getSnapshotBulk(tableId, ids);
2✔
63
  }
2✔
64

93✔
65
  getRecordDocIdsByQuery(shareInfo: IShareViewInfo, query: IGetRecordsRo) {
93✔
66
    const { tableId, view } = shareInfo;
×
NEW
67
    return this.recordService.getDocIdsByQuery(tableId, { ...query, viewId: view?.id });
×
68
  }
×
69

93✔
70
  async getRecordSnapshotBulk(shareInfo: IShareViewInfo, ids: string[]) {
93✔
71
    const { tableId, view } = shareInfo;
×
NEW
72
    const diff = await this.recordService.getDiffIdsByIdAndFilter(tableId, ids, view?.filter);
×
73
    if (diff.length) {
×
74
      throw new ForbiddenException(`Record(${diff.join(',')}) permission not allowed: read`);
×
75
    }
×
76
    return this.recordService.getSnapshotBulk(tableId, ids);
×
77
  }
×
78
}
93✔
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