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

alkem-io / server / #9189

29 Jan 2025 03:28PM UTC coverage: 14.341%. First build
#9189

Pull #4884

travis-ci

Pull Request #4884: Platform, VC settings

84 of 4982 branches covered (1.69%)

Branch coverage included in aggregate %.

5 of 23 new or added lines in 4 files covered. (21.74%)

2304 of 11670 relevant lines covered (19.74%)

7.21 hits per line

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

0.0
/src/platform/platform-settings/platform.settings.service.ts
NEW
1
import { Inject, Injectable, LoggerService } from '@nestjs/common';
×
NEW
2
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
×
3
import { IPlatformSettings } from './platform.settings.interface';
4
import { UpdatePlatformSettingsInput } from './dto/platform.settings.dto.update';
5
import { EntityNotInitializedException } from '@common/exceptions';
6
import { LogContext } from '@common/enums';
NEW
7

×
8
@Injectable()
NEW
9
export class PlatformSettingsService {
×
10
  constructor(
11
    @Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
12
  ) {}
13

14
  public updateSettings(
15
    settings: IPlatformSettings,
NEW
16
    updateData: UpdatePlatformSettingsInput
×
NEW
17
  ): IPlatformSettings {
×
NEW
18
    const updatedSettings = {
×
19
      ...settings,
20
      integration: {
21
        ...settings.integration,
NEW
22
        // Initialize notificationEmailBlacklist to empty array if missing
×
23
        notificationEmailBlacklist:
24
          settings.integration?.notificationEmailBlacklist || [],
25
      },
26
    };
27
    if (updateData.integration) {
28
      if (updateData.integration.iframeAllowedUrls !== undefined) {
29
        updatedSettings.integration.iframeAllowedUrls =
30
          updateData.integration.iframeAllowedUrls;
31
      }
32
      if (updateData.integration.notificationEmailBlacklist !== undefined) {
33
        updatedSettings.integration.notificationEmailBlacklist =
34
          updateData.integration.notificationEmailBlacklist;
35
      }
36
    }
37
    return updatedSettings;
38
  }
39

40
  public addIframeAllowedURLOrFail(
41
    settings: IPlatformSettings,
42
    iframeAllowedURL: string
43
  ): string[] | never {
44
    if (!settings.integration)
45
      throw new EntityNotInitializedException(
46
        'Settings  not initialized',
47
        LogContext.PLATFORM
48
      );
49
    const currentUrls = settings.integration?.iframeAllowedUrls;
50

51
    // Only add if not already present
52
    if (!currentUrls.includes(iframeAllowedURL)) {
53
      currentUrls.push(iframeAllowedURL);
54
    }
55

56
    return currentUrls;
57
  }
58

59
  public removeIframeAllowedURLOrFail(
60
    settings: IPlatformSettings,
61
    iframeAllowedURL: string
62
  ): string[] | never {
63
    if (!settings.integration)
64
      throw new EntityNotInitializedException(
65
        'Settings  not initialized',
66
        LogContext.PLATFORM
67
      );
68
    const currentUrls = settings.integration?.iframeAllowedUrls;
69

70
    const updatedUrls = currentUrls.filter(url => url !== iframeAllowedURL);
71

72
    return updatedUrls;
73
  }
74

75
  public addNotificationEmailToBlacklistOrFail(
76
    settings: IPlatformSettings,
77
    email: string
78
  ): string[] | never {
79
    if (!settings.integration)
80
      throw new EntityNotInitializedException(
81
        'Settings not initialized',
82
        LogContext.PLATFORM
83
      );
84

85
    // Initialize blacklist if not present
86
    const currentEmails = settings.integration.notificationEmailBlacklist || [];
87

88
    // Reject wildcard characters
89
    if (email.includes('*') || email.includes('?')) {
90
      throw new Error('Wildcard characters are not allowed in email addresses');
91
    }
92

93
    // Lowercase for canonical storage and comparison
94
    const canonicalEmail = email.toLowerCase();
95

96
    // Check for duplicates (case-insensitive)
97
    if (currentEmails.some(e => e.toLowerCase() === canonicalEmail)) {
98
      throw new Error(`Email ${canonicalEmail} is already in the blacklist`);
99
    }
100

101
    // Enforce 250 entry limit
102
    if (currentEmails.length >= 250) {
103
      throw new Error(
104
        'Blacklist limit of 250 entries reached. Remove entries before adding new ones.'
105
      );
106
    }
107

108
    // Add email to blacklist
109
    currentEmails.push(canonicalEmail);
110

111
    return currentEmails;
112
  }
113

114
  public removeNotificationEmailFromBlacklistOrFail(
115
    settings: IPlatformSettings,
116
    email: string
117
  ): string[] | never {
118
    if (!settings.integration)
119
      throw new EntityNotInitializedException(
120
        'Settings not initialized',
121
        LogContext.PLATFORM
122
      );
123

124
    const currentEmails = settings.integration.notificationEmailBlacklist || [];
125

126
    // Lowercase for canonical comparison
127
    const canonicalEmail = email.toLowerCase();
128

129
    // Check if email exists
130
    if (!currentEmails.some(e => e.toLowerCase() === canonicalEmail)) {
131
      throw new Error(`Email ${canonicalEmail} not found in blacklist`);
132
    }
133

134
    // Remove email from blacklist (case-insensitive)
135
    const updatedEmails = currentEmails.filter(
136
      e => e.toLowerCase() !== canonicalEmail
137
    );
138

139
    return updatedEmails;
140
  }
141
}
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