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

bpatrik / pigallery2 / 17476969769

04 Sep 2025 09:18PM UTC coverage: 64.943% (-0.007%) from 64.95%
17476969769

push

github

bpatrik
Make confirm password field

1238 of 2174 branches covered (56.95%)

Branch coverage included in aggregate %.

2 of 3 new or added lines in 1 file covered. (66.67%)

4627 of 6857 relevant lines covered (67.48%)

4443.66 hits per line

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

84.13
/src/backend/model/database/SessionManager.ts
1
import * as crypto from 'crypto';
1✔
2
import {ContextUser, SessionContext} from '../SessionContext';
1✔
3
import {SearchQueryUtils} from '../../../common/SearchQueryUtils';
1✔
4
import {Config} from '../../../common/config/private/Config';
1✔
5
import {ANDSearchQuery, SearchQueryDTO, SearchQueryTypes} from '../../../common/entities/SearchQueryDTO';
1✔
6
import {SharingEntity} from './enitites/SharingEntity';
7
import {ObjectManagers} from '../ObjectManagers';
1✔
8
import {Logger} from '../../Logger';
1✔
9

10
const LOG_TAG = '[SessionManager]';
1✔
11

12
export class SessionManager {
1✔
13

14
  public static readonly NO_PROJECTION_KEY = 'pr:' + crypto.createHash('md5').update('No Key').digest('hex');
1✔
15

16
  private getQueryForUser(user: ContextUser) {
17
    let blockQuery = user.overrideAllowBlockList ? user.blockQuery : Config.Users.blockQuery;
312✔
18
    const allowQuery = user.overrideAllowBlockList ? user.allowQuery : Config.Users.allowQuery;
312✔
19

20
    if (!SearchQueryUtils.isQueryEmpty(allowQuery) && !SearchQueryUtils.isQueryEmpty(blockQuery)) {
312✔
21
      return null;
277✔
22
    }
23

24
    if (SearchQueryUtils.isQueryEmpty(blockQuery)) {
35✔
25
      blockQuery = SearchQueryUtils.negate(blockQuery);
6✔
26
    }
27
    let query = SearchQueryUtils.isQueryEmpty(allowQuery) ? allowQuery : blockQuery;
35✔
28
    if (SearchQueryUtils.isQueryEmpty(allowQuery) && SearchQueryUtils.isQueryEmpty(blockQuery)) {
35✔
29
      query = {
4✔
30
        type: SearchQueryTypes.AND,
31
        list: [
32
          allowQuery,
33
          blockQuery
34
        ]
35
      } as ANDSearchQuery;
36
    }
37
    return query;
35✔
38

39
  }
40

41
  public buildAllowListForSharing(sharing: SharingEntity): SearchQueryDTO {
42
    const creatorQuery = this.getQueryForUser(sharing.creator);
16✔
43
    let finalQuery = sharing.searchQuery;
16✔
44
    if (creatorQuery) {
16✔
45
      finalQuery = {
4✔
46
        type: SearchQueryTypes.AND,
47
        list: [
48
          creatorQuery,
49
          sharing.searchQuery
50
        ]
51
      } as ANDSearchQuery;
52
    }
53
    return finalQuery;
16✔
54
  }
55

56
  public createProjectionKey(q: SearchQueryDTO) {
57
    const canonical = SearchQueryUtils.stringifyForComparison(q);
36✔
58
    return 'pr:' + crypto.createHash('md5').update(canonical).digest('hex');
36✔
59
  }
60

61
  public async buildContext(user: ContextUser): Promise<SessionContext> {
62
    const context = new SessionContext();
296✔
63
    context.user = user;
296✔
64
    context.user.projectionKey = SessionManager.NO_PROJECTION_KEY;
296✔
65
    let finalQuery = this.getQueryForUser(user);
296✔
66

67
    if (finalQuery) {
296✔
68
      // Build the Brackets-based query
69
      context.projectionQuery = await ObjectManagers.getInstance().SearchManager.prepareAndBuildWhereQuery(finalQuery);
31✔
70
      context.user.projectionKey = this.createProjectionKey(finalQuery);
31✔
71
      if (SearchQueryUtils.isQueryEmpty(finalQuery)) {
31!
72
        Logger.silly(LOG_TAG, 'Empty Projection query.');
31✔
73
      } else {
NEW
74
        Logger.silly(LOG_TAG, 'Projection query: ' + JSON.stringify(finalQuery));
×
75
      }
76
    }
77
    return context;
296✔
78
  }
79

80
  async getAvailableUserSessions(): Promise<SessionContext[]> {
81
    // List all users and build a session context for each
82
    const users = await ObjectManagers.getInstance().UserManager.find({} as any);
×
83
    const sessions: SessionContext[] = [];
×
84
    for (const u of users as unknown as ContextUser[]) {
×
85
      try {
×
86
        const ctx = await this.buildContext(u);
×
87
        sessions.push(ctx);
×
88
      } catch (e) {
89
        // Log and continue on individual user context build failure to ensure we return other sessions
90
        Logger.warn(LOG_TAG, 'Failed to build session context for user id=' + (u as any)?.id + ': ' + (e as Error)?.message);
×
91
      }
92
    }
93
    return sessions;
×
94
  }
95
}
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

© 2026 Coveralls, Inc