Passed
Push — trunk ( 1572c3...2f9940 )
by Christian
15:38 queued 17s
created

src/Administration/Resources/app/administration/src/app/service/rule-condition.service.ts   F

Complexity

Total Complexity 196
Complexity/F 3.06

Size

Lines of Code 751
Function Count 64

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 519
dl 0
loc 751
rs 2
c 0
b 0
f 0
wmc 196
mnd 132
bc 132
fnc 64
bpm 2.0625
cpm 3.0625
noi 0

32 Functions

Rating   Name   Duplication   Size   Complexity  
A RuleConditionService.getOperatorOptionsByIdentifiers 0 21 4
A RuleConditionService.addModuleType 0 3 1
A RuleConditionService.addAwarenessConfiguration 0 4 3
B RuleConditionService.getRestrictionsByAssociation 0 64 8
A RuleConditionService.getAwarenessConfigurationByAssignmentName 0 5 1
A RuleConditionService.getModuleTypes 0 3 1
A RuleConditionService.getRestrictedAssociations 0 35 2
A RuleConditionService.getRestrictionsByGroup 0 9 2
A RuleConditionService.getAndContainerData 0 3 1
A RuleConditionService.addCondition 0 5 3
A RuleConditionService.getOrContainerData 0 3 1
A RuleConditionService.isAndContainer 0 3 1
A RuleConditionService.getConditions 0 11 2
A RuleConditionService.getGroups 0 3 1
A RuleConditionService.getByGroup 0 12 2
D RuleConditionService.getRestrictedConditions 0 60 12
B RuleConditionService.getComponentByCondition 0 25 6
B RuleConditionService.getRestrictedRules 0 31 5
A RuleConditionService.upsertGroup 0 3 1
B RuleConditionService.addScriptConditions 0 12 6
A RuleConditionService.isRuleRestricted 0 18 2
B RuleConditionService.getAwarenessKeysWithEqualsAnyConfig 0 10 6
A RuleConditionService.removeGroup 0 3 1
B RuleConditionService.getRestrictedRuleTooltipConfig 0 55 7
A RuleConditionService.getOperatorSet 0 3 1
A RuleConditionService.isAllLineItemsContainer 0 3 1
A RuleConditionService.getTranslatedConditionViolationList 0 24 4
A RuleConditionService.isOrContainer 0 3 1
B RuleConditionService.getOperatorSetByComponent 0 22 6
A RuleConditionService.getPlaceholderData 0 3 1
A RuleConditionService.addEmptyOperatorToOperatorSet 0 3 1
A RuleConditionService.getByType 0 17 4

How to fix   Complexity   

Complexity

Complex classes like src/Administration/Resources/app/administration/src/app/service/rule-condition.service.ts often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import type EntityCollection from '@shopware-ag/admin-extension-sdk/es/data/_internals/EntityCollection';
2
3
const { Criteria } = Shopware.Data;
4
5
type appScriptCondition = {
6
    id: string,
7
    config: unknown
8
}
9
10
type condition = {
11
    type: string,
12
    component: string,
13
    label: string,
14
    scopes: string[],
15
    group: string,
16
    scriptId: string,
17
    appScriptCondition: appScriptCondition,
18
}
19
20
type script = {
21
    id: string,
22
    name?: string,
23
    translated?: {
24
        name?: string,
25
    },
26
    group: string,
27
    config: unknown,
28
}
29
30
type operatorSetIdentifier =
31
    'defaultSet' |
32
    'singleStore' |
33
    'multiStore' |
34
    'string' |
35
    'bool' |
36
    'number' |
37
    'date' |
38
    'isNet' |
39
    'empty' |
40
    'zipCode';
41
42
type component = {
43
    type: string,
44
    config: {
45
        componentName: string,
46
    },
47
}
48
49
type moduleType = {
50
    id: string,
51
    name: string,
52
}
53
54
type group = {
55
    id: string,
56
    name: string,
57
}
58
59
type awarenessConfiguration = {
60
    notEquals?: Array<string>,
61
    equalsAny?: Array<string>,
62
    snippet?: string,
63
}
64
65
/**
66
 * @module app/service/rule-condition
67
 */
68
69
/**
70
 * @private
71
 * @package business-ops
72
 * @memberOf module:app/service/rule-condition
73
 * @constructor
74
 * @method createConditionService
75
 * @returns {Object}
76
 */
77
export default class RuleConditionService {
78
    $store: { [key: string]: condition} = {};
79
80
    awarenessConfiguration: { [key: string]: awarenessConfiguration} = {};
81
82
    operators = {
83
        lowerThanEquals: {
84
            identifier: '<=',
85
            label: 'global.sw-condition.operator.lowerThanEquals',
86
        },
87
        equals: {
88
            identifier: '=',
89
            label: 'global.sw-condition.operator.equals',
90
        },
91
        greaterThanEquals: {
92
            identifier: '>=',
93
            label: 'global.sw-condition.operator.greaterThanEquals',
94
        },
95
        notEquals: {
96
            identifier: '!=',
97
            label: 'global.sw-condition.operator.notEquals',
98
        },
99
        greaterThan: {
100
            identifier: '>',
101
            label: 'global.sw-condition.operator.greaterThan',
102
        },
103
        lowerThan: {
104
            identifier: '<',
105
            label: 'global.sw-condition.operator.lowerThan',
106
        },
107
        isOneOf: {
108
            identifier: '=',
109
            label: 'global.sw-condition.operator.isOneOf',
110
        },
111
        isNoneOf: {
112
            identifier: '!=',
113
            label: 'global.sw-condition.operator.isNoneOf',
114
        },
115
        gross: {
116
            identifier: false,
117
            label: 'global.sw-condition.operator.gross',
118
        },
119
        net: {
120
            identifier: true,
121
            label: 'global.sw-condition.operator.net',
122
        },
123
        empty: {
124
            identifier: 'empty',
125
            label: 'global.sw-condition.operator.empty',
126
        },
127
    };
128
129
    operatorSets = {
130
        defaultSet: [
131
            this.operators.equals,
132
            this.operators.notEquals,
133
            this.operators.greaterThanEquals,
134
            this.operators.lowerThanEquals,
135
        ],
136
        singleStore: [
137
            this.operators.equals,
138
            this.operators.notEquals,
139
        ],
140
        multiStore: [
141
            this.operators.isOneOf,
142
            this.operators.isNoneOf,
143
        ],
144
        string: [
145
            this.operators.equals,
146
            this.operators.notEquals,
147
        ],
148
        bool: [
149
            this.operators.equals,
150
        ],
151
        number: [
152
            this.operators.equals,
153
            this.operators.greaterThan,
154
            this.operators.greaterThanEquals,
155
            this.operators.lowerThan,
156
            this.operators.lowerThanEquals,
157
            this.operators.notEquals,
158
        ],
159
        date: [
160
            this.operators.equals,
161
            this.operators.greaterThan,
162
            this.operators.greaterThanEquals,
163
            this.operators.lowerThan,
164
            this.operators.lowerThanEquals,
165
            this.operators.notEquals,
166
        ],
167
        isNet: [
168
            this.operators.gross,
169
            this.operators.net,
170
        ],
171
        empty: [
172
            this.operators.empty,
173
        ],
174
        zipCode: [
175
            this.operators.greaterThan,
176
            this.operators.greaterThanEquals,
177
            this.operators.lowerThan,
178
            this.operators.lowerThanEquals,
179
        ],
180
    };
181
182
    moduleTypes: { [key: string]: moduleType } = {
183
        shipping: {
184
            id: 'shipping',
185
            name: 'sw-settings-rule.detail.types.shipping',
186
        },
187
        payment: {
188
            id: 'payment',
189
            name: 'sw-settings-rule.detail.types.payment',
190
        },
191
        price: {
192
            id: 'price',
193
            name: 'sw-settings-rule.detail.types.price',
194
        },
195
        flow: {
196
            id: 'flow',
197
            name: 'sw-settings-rule.detail.types.flowBuilder',
198
        },
199
    };
200
201
    groups: { [key: string]: group} = {
202
        general: {
203
            id: 'general',
204
            name: 'sw-settings-rule.detail.groups.general',
205
        },
206
        cart: {
207
            id: 'cart',
208
            name: 'sw-settings-rule.detail.groups.cart',
209
        },
210
        items: {
211
            id: 'item',
212
            name: 'sw-settings-rule.detail.groups.items',
213
        },
214
        customers: {
215
            id: 'customer',
216
            name: 'sw-settings-rule.detail.groups.customers',
217
        },
218
        promotions: {
219
            id: 'promotion',
220
            name: 'sw-settings-rule.detail.groups.promotions',
221
        },
222
        flow: {
223
            id: 'flow',
224
            name: 'sw-settings-rule.detail.groups.flow',
225
        },
226
        misc: {
227
            id: 'misc',
228
            name: 'sw-settings-rule.detail.groups.misc',
229
        },
230
    };
231
232
    getByType(type: string): condition {
233
        if (!type) {
234
            return this.getByType('placeholder');
235
        }
236
237
        if (type === 'scriptRule') {
238
            const scriptRule = this.getConditions().filter((condition) => {
239
                return condition.type === 'scriptRule';
240
            }).shift();
241
242
            if (scriptRule) {
243
                return scriptRule;
244
            }
245
        }
246
247
        return this.$store[type];
248
    }
249
250
    addCondition(type: string, condition: Partial<Omit<condition, 'type'>>) {
251
        (condition as condition).type = type;
252
253
        this.$store[condition.scriptId ?? type] = condition as condition;
254
    }
255
256
    addScriptConditions(scripts: script[]) {
257
        scripts.forEach((script) => {
258
            this.addCondition('scriptRule', {
259
                component: 'sw-condition-script',
260
                label: (script?.translated?.name || script.name) ?? '',
261
                scopes: script.group === 'item' ? ['global', 'lineItem'] : ['global'],
262
                group: script.group,
263
                scriptId: script.id,
264
                appScriptCondition: {
265
                    id: script.id,
266
                    config: script.config,
267
                },
268
            });
269
        });
270
    }
271
272
    getOperatorSet(operatorSetName: operatorSetIdentifier) {
273
        return this.operatorSets[operatorSetName];
274
    }
275
276
    addEmptyOperatorToOperatorSet(operatorSet: Array<unknown>) {
277
        return operatorSet.concat(this.operatorSets.empty);
278
    }
279
280
    getOperatorSetByComponent(component: component) {
281
        const componentName = component.config.componentName;
282
        const type = component.type;
283
284
        if (componentName === 'sw-single-select') {
285
            return this.operatorSets.singleStore;
286
        }
287
        if (componentName === 'sw-multi-select') {
288
            return this.operatorSets.multiStore;
289
        }
290
        if (type === 'bool') {
291
            return this.operatorSets.bool;
292
        }
293
        if (type === 'text') {
294
            return this.operatorSets.string;
295
        }
296
        if (type === 'int') {
297
            return this.operatorSets.number;
298
        }
299
300
        return this.operatorSets.defaultSet;
301
    }
302
303
    getOperatorOptionsByIdentifiers(identifiers: Array<string>, isMatchAny = false) {
304
        return identifiers.map((identifier) => {
305
            const option = Object.entries(this.operators).find(([name, operator]) => {
306
                if (isMatchAny && ['equals', 'notEquals'].includes(name)) {
307
                    return false;
308
                }
309
                if (!isMatchAny && ['isOneOf', 'isNoneOf'].includes(name)) {
310
                    return false;
311
                }
312
313
                return identifier === operator.identifier;
314
            });
315
316
            if (option) {
317
                return option.pop();
318
            }
319
320
            return {
321
                identifier,
322
                label: `global.sw-condition.operator.${identifier}`,
323
            };
324
        });
325
    }
326
327
    addModuleType(type: moduleType) {
328
        this.moduleTypes[type.id] = type;
329
    }
330
331
    getModuleTypes() {
332
        return Object.values(this.moduleTypes);
333
    }
334
335
    getByGroup(group: string) {
336
        const values = Object.values(this.$store);
337
        const conditions: Array<condition> = [];
338
339
        values.forEach(condition => {
340
            if (condition.group === group) {
341
                conditions.push(condition);
342
            }
343
        });
344
345
        return conditions;
346
    }
347
348
    getGroups() {
349
        return this.groups;
350
    }
351
352
    upsertGroup(groupName: string, groupData: group) {
353
        this.groups[groupName] = { ...this.groups[groupName], ...groupData };
354
    }
355
356
    removeGroup(groupName: string) {
357
        delete this.groups[groupName];
358
    }
359
360
    getConditions(allowedScopes: Array<string>|null = null): condition[] {
361
        let values = Object.values(this.$store);
362
363
        if (allowedScopes !== null) {
364
            values = values.filter(condition => {
365
                return allowedScopes.some(scope => condition.scopes.indexOf(scope) !== -1);
366
            });
367
        }
368
369
        return values;
370
    }
371
372
    getAndContainerData() {
373
        return { type: 'andContainer', value: {} };
374
    }
375
376
    isAndContainer(condition: condition) {
377
        return condition.type === 'andContainer';
378
    }
379
380
    getOrContainerData() {
381
        return { type: 'orContainer', value: {} };
382
    }
383
384
    isOrContainer(condition: condition) {
385
        return condition.type === 'orContainer';
386
    }
387
388
    getPlaceholderData() {
389
        return { type: null, value: {} };
390
    }
391
392
    isAllLineItemsContainer(condition: condition) {
393
        return condition.type === 'allLineItemsContainer';
394
    }
395
396
    getComponentByCondition(condition: condition) {
397
        if (this.isAndContainer(condition)) {
398
            return 'sw-condition-and-container';
399
        }
400
401
        if (this.isOrContainer(condition)) {
402
            return 'sw-condition-or-container';
403
        }
404
405
        if (this.isAllLineItemsContainer(condition)) {
406
            return 'sw-condition-all-line-items-container';
407
        }
408
409
        if (!condition.type) {
410
            return 'sw-condition-base';
411
        }
412
413
        const conditionType = this.getByType(condition.type);
414
415
        if (typeof conditionType === 'undefined' || !conditionType.component) {
416
            return 'sw-condition-not-found';
417
        }
418
419
        return conditionType.component;
420
    }
421
422
    addAwarenessConfiguration(assignmentName: string, configuration: awarenessConfiguration) {
423
        this.awarenessConfiguration[assignmentName] = configuration;
424
        configuration.equalsAny = configuration.equalsAny?.filter(value => !configuration.notEquals?.includes(value));
425
    }
426
427
    getAwarenessConfigurationByAssignmentName(assignmentName: string) {
428
        const config = this.awarenessConfiguration[assignmentName];
429
430
        return config || null;
431
    }
432
433
    getAwarenessKeysWithEqualsAnyConfig() {
434
        const equalsAnyConfigurations: Array<string> = [];
435
        Object.entries(this.awarenessConfiguration).forEach(([key, value]) => {
436
            if (value?.equalsAny?.length && value?.equalsAny?.length > 0) {
437
                equalsAnyConfigurations.push(key);
438
            }
439
        });
440
441
        return equalsAnyConfigurations;
442
    }
443
444
    /**
445
     * @param {Entity} r
446
     * @returns {Object}
447
     * {
448
     *     conditionName: [
449
     *         { associationName: "association", snippet: "sw.snippet.association"},
450
     *         { associationName: "otherAssociation", snippet: "sw.snippet.otherAssociation"},
451
     *     ]
452
     * }
453
     */
454
    getRestrictedConditions(r: EntitySchema.rule) {
455
        if (!r) {
456
            return {};
457
        }
458
459
        const keys = Object.keys(this.awarenessConfiguration);
460
461
        const conditions: { [key: string]: Array<unknown> } = {};
462
        keys.forEach(key => {
463
            const association = r[key as keyof EntitySchema.rule] as Array<unknown>;
464
            const currentEntry = this.awarenessConfiguration[key];
465
466
            if (association && association.length > 0 && currentEntry.notEquals) {
467
                currentEntry.notEquals.forEach(condition => {
468
                    if (!conditions[condition]) {
469
                        conditions[condition] = [];
470
                    }
471
                    conditions[condition].push({
472
                        associationName: key,
473
                        snippet: currentEntry.snippet,
474
                    });
475
                });
476
            }
477
        });
478
479
        if (!r.flowSequences || r.flowSequences?.length <= 0) {
480
            return conditions;
481
        }
482
483
        (r.flowSequences as EntityCollection<'flow_sequence'>).forEach(sequence => {
484
            const eventName = `flowTrigger.${sequence.flow?.eventName ?? ''}`;
485
            const currentEntry = this.awarenessConfiguration[eventName];
486
487
            if (!currentEntry?.notEquals) {
488
                return;
489
            }
490
491
            currentEntry.notEquals.forEach(condition => {
492
                if (!conditions[condition]) {
493
                    conditions[condition] = [];
494
                }
495
                conditions[condition].push({
496
                    associationName: eventName,
497
                    snippet: currentEntry.snippet,
498
                });
499
            });
500
        });
501
502
        return conditions;
503
    }
504
505
    getRestrictedRules(entityName: string) {
506
        const configuration = this.getAwarenessConfigurationByAssignmentName(entityName);
507
508
        if (!configuration) {
509
            return Promise.resolve([]);
510
        }
511
512
        const { notEquals, equalsAny } = configuration;
513
        const restrictions = [];
514
515
        if (notEquals) {
516
            restrictions.push(Criteria.equalsAny('conditions.type', notEquals));
517
        }
518
519
        if (equalsAny) {
520
            restrictions.push(Criteria.not('AND', [Criteria.equalsAny('conditions.type', equalsAny)]));
521
        }
522
523
        if (restrictions.length === 0) {
524
            return Promise.resolve([]);
525
        }
526
527
        const ruleRepository = Shopware.Service('repositoryFactory').create('rule');
528
        const criteria = new Criteria(1, 25);
529
        criteria.addFilter(Criteria.multi(
530
            'OR',
531
            restrictions,
532
        ));
533
534
        return ruleRepository.searchIds(criteria).then(result => result.data);
535
    }
536
537
    /**
538
     * Checks the conditions with the current awareness configuration for the assignment name
539
     * and returns the result.
540
     * @param {EntityCollection} conditions
541
     * @param {String} assignmentName
542
     * @returns {object}
543
     * Example return: {
544
     *      assignmentName: assignmentName,
545
     *      notEqualsViolations: [{}, {}],
546
     *      equalsAnyMatched: [{}, {}],
547
     *      equalsAnyNotMatched: [{}, {}],
548
     *      isRestricted: false
549
     * }
550
     */
551
    getRestrictionsByAssociation(conditions: EntityCollection<'rule_condition'>, assignmentName: string) {
552
        const awarenessEntry = this.getAwarenessConfigurationByAssignmentName(assignmentName);
553
        const restrictionConfig: {
554
            notEqualsViolations: Array<{ label: string }>,
555
            equalsAnyNotMatched: Array<{ label: string }>,
556
            isRestricted: boolean,
557
            assignmentName: string,
558
            equalsAnyMatched: condition[],
559
            assignmentSnippet?: string,
560
        } = {
561
            assignmentName: assignmentName,
562
            notEqualsViolations: [],
563
            equalsAnyMatched: [],
564
            equalsAnyNotMatched: [],
565
            isRestricted: false,
566
        };
567
        if (!awarenessEntry) {
568
            return restrictionConfig;
569
        }
570
571
        restrictionConfig.assignmentSnippet = awarenessEntry.snippet;
572
573
        if (awarenessEntry.notEquals) {
574
            conditions.forEach(condition => {
575
                if (awarenessEntry.notEquals?.includes(condition.type)) {
576
                    restrictionConfig.notEqualsViolations.push(this.getByType(condition.type));
577
                    restrictionConfig.isRestricted = true;
578
                }
579
            });
580
        }
581
582
        if (awarenessEntry.equalsAny) {
583
            awarenessEntry.equalsAny.forEach(type => {
584
                const matchedCondition = conditions.find(condition => {
585
                    return condition.type === type;
586
                });
587
                if (matchedCondition) {
588
                    restrictionConfig.equalsAnyMatched.push(this.getByType(type));
589
                } else {
590
                    restrictionConfig.equalsAnyNotMatched.push(this.getByType(type));
591
                }
592
            });
593
594
            if (restrictionConfig.equalsAnyMatched.length === 0) {
595
                restrictionConfig.isRestricted = true;
596
            }
597
        }
598
599
        return restrictionConfig;
600
    }
601
602
    /**
603
     * Checks the conditions with the current awareness configuration and returns the result for
604
     * every assignment name.
605
     * @param {EntityCollection} conditions
606
     * @returns {object}
607
     * Example return: {
608
     *     associationName: {
609
     *         assignmentName: assignmentName,
610
     *         notEqualsViolations: [{}, {}],
611
     *         equalsAnyMatched: [{}, {}],
612
     *         equalsAnyNotMatched: [{}, {}],
613
     *         isRestricted: false
614
     *     },
615
     *     secondAssociationName: {
616
     *         assignmentName: assignmentName,
617
     *         notEqualsViolations: [{}, {}],
618
     *         equalsAnyMatched: [{}, {}],
619
     *         equalsAnyNotMatched: [{}, {}],
620
     *         isRestricted: false
621
     *     },
622
     * }
623
     */
624
    getRestrictedAssociations(conditions: EntityCollection<'rule_condition'>) {
625
        if (!conditions) {
626
            return {};
627
        }
628
        const keys = Object.keys(this.awarenessConfiguration);
629
        const restrictedAssociations: { [key: string]: unknown} = {};
630
631
        keys.forEach(key => {
632
            restrictedAssociations[key] = this.getRestrictionsByAssociation(conditions, key);
633
        });
634
635
        return restrictedAssociations;
636
    }
637
638
    /**
639
     * Translates a list of violations and return the translated text
640
     * @param {array} violations
641
     * @param {string} connectionSnippetPath
642
     * @returns {string}
643
     */
644
    getTranslatedConditionViolationList(violations: Array<{ label: string }>, connectionSnippetPath: string) {
645
        const app = Shopware.Application.getApplicationRoot();
646
        if (!app) {
647
            return '';
648
        }
649
650
        let text = '';
651
        violations.forEach((violation, index, allViolations) => {
652
            text += `"${app.$tc(violation.label, 1)}"`;
653
            if (index + 2 === allViolations.length) {
654
                text += ` ${app.$tc(connectionSnippetPath)} `;
655
            } else if (index + 1 < allViolations.length) {
656
                text += ', ';
657
            }
658
        });
659
660
        return text;
661
    }
662
663
    /**
664
     *
665
     * @param {EntityCollection} ruleConditions
666
     * @param {string|null} ruleAwareGroupKey
667
     * @returns {object}
668
     */
669
    getRestrictedRuleTooltipConfig(ruleConditions: EntityCollection<'rule_condition'>, ruleAwareGroupKey: string|null) {
670
        const app = Shopware.Application.getApplicationRoot();
671
672
        if (!app || !ruleAwareGroupKey) {
673
            return { message: '', disabled: true };
674
        }
675
676
        const restrictionConfig = this.getRestrictionsByAssociation(
677
            // @ts-expect-error
678
            ruleConditions as Array<condition>,
679
            ruleAwareGroupKey,
680
        );
681
682
        if (!restrictionConfig.isRestricted) {
683
            return { message: '', disabled: true };
684
        }
685
686
        if (restrictionConfig.notEqualsViolations?.length > 0) {
687
            return {
688
                showOnDisabledElements: true,
689
                disabled: false,
690
                message: app.$tc(
691
                    'sw-restricted-rules.restrictedAssignment.notEqualsViolationTooltip',
692
                    undefined,
693
                    {
694
                        conditions: this.getTranslatedConditionViolationList(
695
                            restrictionConfig.notEqualsViolations,
696
                            'sw-restricted-rules.and',
697
                        ),
698
                        entityLabel: app.$tc(restrictionConfig.assignmentSnippet as string, 2),
699
                    },
700
                ),
701
            };
702
        }
703
704
        return {
705
            showOnDisabledElements: true,
706
            disabled: false,
707
            width: 400,
708
            message: app.$tc(
709
                'sw-restricted-rules.restrictedAssignment.equalsAnyViolationTooltip',
710
                0,
711
                {
712
                    conditions: this.getTranslatedConditionViolationList(
713
                        restrictionConfig.equalsAnyNotMatched,
714
                        'sw-restricted-rules.or',
715
                    ),
716
                    entityLabel: app.$tc(restrictionConfig.assignmentSnippet ?? '', 2),
717
                },
718
            ),
719
        };
720
    }
721
722
    /**
723
     *
724
     * @param {EntityCollection} ruleConditions
725
     * @param {string|null} ruleAwareGroupKey
726
     * @returns {boolean}
727
     */
728
    isRuleRestricted(ruleConditions: EntityCollection<'rule_condition'>, ruleAwareGroupKey: string|null) {
729
        if (!ruleAwareGroupKey) {
730
            return false;
731
        }
732
733
        const restrictionConfig = this.getRestrictionsByAssociation(
734
            ruleConditions,
735
            ruleAwareGroupKey,
736
        );
737
738
        return restrictionConfig.isRestricted;
739
    }
740
741
    getRestrictionsByGroup(...wantedGroups: Array<string>) {
742
        const entries = Object.entries(this.$store);
743
744
        return entries.reduce((acc, [restrictionName, condition]) => {
745
            const inGroup = wantedGroups.includes(condition.group);
746
747
            return inGroup ? [...acc, restrictionName] : acc;
748
        }, [] as Array<string>);
749
    }
750
}
751