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

bpatrik / pigallery2 / 17685697493

12 Sep 2025 08:48PM UTC coverage: 65.828% (+1.7%) from 64.102%
17685697493

push

github

web-flow
Merge pull request #1030 from bpatrik/db-projection

Implement projected (scoped/filtered) gallery. Fixes #1015

1305 of 2243 branches covered (58.18%)

Branch coverage included in aggregate %.

706 of 873 new or added lines in 54 files covered. (80.87%)

16 existing lines in 10 files now uncovered.

4794 of 7022 relevant lines covered (68.27%)

4355.01 hits per line

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

27.69
/src/backend/model/database/UserManager.ts
1
import {UserDTO, UserRoles} from '../../../common/entities/UserDTO';
2
import {UserEntity} from './enitites/UserEntity';
1✔
3
import {SQLConnection} from './SQLConnection';
1✔
4
import {PasswordHelper} from '../PasswordHelper';
1✔
5
import {FindOptionsWhere} from 'typeorm';
6
import {UserSettingsDTO} from '../../../common/entities/UserSettingsDTO';
7
import {SearchQueryUtils} from '../../../common/SearchQueryUtils';
1✔
8

9
export class UserManager {
1✔
10

11

12
  public async findOne(filter: FindOptionsWhere<UserEntity>): Promise<UserEntity> {
13
    const connection = await SQLConnection.getConnection();
3✔
14
    const pass = filter.password as string;
3✔
15
    delete filter.password;
3✔
16
    const user = await connection.getRepository(UserEntity).findOneBy(filter);
3✔
17

18
    if (pass && !PasswordHelper.comparePassword(pass, user.password)) {
3!
19
      throw new Error('No entry found');
×
20
    }
21
    return user;
3✔
22
  }
23

24
  public async find(filter: FindOptionsWhere<UserDTO>): Promise<UserEntity[]> {
25
    const connection = await SQLConnection.getConnection();
×
26
    return await connection.getRepository(UserEntity).findBy(filter);
×
27
  }
28

29
  public async createUser(user: UserDTO): Promise<UserEntity> {
30
    const connection = await SQLConnection.getConnection();
16✔
31
    // Validate search queries if provided
32
    if (user.allowQuery) {
16!
NEW
33
      SearchQueryUtils.validateSearchQuery(user.allowQuery, 'User allowQuery');
×
34
    }
35
    if (user.blockQuery) {
16!
NEW
36
      SearchQueryUtils.validateSearchQuery(user.blockQuery, 'User blockQuery');
×
37
    }
38
    user.password = PasswordHelper.cryptPassword(user.password);
16✔
39
    return connection.getRepository(UserEntity).save(user);
16✔
40
  }
41

42
  public async deleteUser(id: number): Promise<UserEntity> {
43
    const connection = await SQLConnection.getConnection();
×
44
    const user = await connection.getRepository(UserEntity).findOneBy({id});
×
45
    return await connection.getRepository(UserEntity).remove(user);
×
46
  }
47

48
  public async changeRole(id: number, newRole: UserRoles): Promise<UserEntity> {
49
    const connection = await SQLConnection.getConnection();
×
50
    const userRepository = connection.getRepository(UserEntity);
×
51
    const user = await userRepository.findOneBy({id});
×
52
    user.role = newRole;
×
53
    return userRepository.save(user);
×
54
  }
55

56
  public async updateSettings(id: number, settings: UserSettingsDTO): Promise<UserEntity> {
NEW
57
    const connection = await SQLConnection.getConnection();
×
NEW
58
    const userRepository = connection.getRepository(UserEntity);
×
NEW
59
    const user = await userRepository.findOneBy({id});
×
60

NEW
61
    if (!user) {
×
NEW
62
      throw new Error('User not found');
×
63
    }
64

NEW
65
    if (typeof settings.overrideAllowBlockList !== 'undefined') {
×
NEW
66
      user.overrideAllowBlockList = settings.overrideAllowBlockList;
×
67
    }
68

NEW
69
    if (typeof settings.allowQuery !== 'undefined') {
×
NEW
70
      if (settings.allowQuery) {
×
NEW
71
        SearchQueryUtils.validateSearchQuery(settings.allowQuery, 'User allowQuery');
×
72
      }
NEW
73
      user.allowQuery = settings.allowQuery ?? null;
×
74
    }
75

NEW
76
    if (typeof settings.blockQuery !== 'undefined') {
×
NEW
77
      if (settings.blockQuery) {
×
NEW
78
        SearchQueryUtils.validateSearchQuery(settings.blockQuery, 'User blockQuery');
×
79
      }
NEW
80
      user.blockQuery = settings.blockQuery ?? null;
×
81
    }
82

NEW
83
    if (settings.newPassword && settings.newPassword.length > 0) {
×
NEW
84
      user.password = PasswordHelper.cryptPassword(settings.newPassword);
×
85
    }
86

NEW
87
    return userRepository.save(user);
×
88
  }
89

90
}
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