mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-14 00:19:16 +01:00
fix: patch constraint schema to always default values to empty array
This commit is contained in:
parent
957ec1c16d
commit
99d2bbdb73
@ -10,8 +10,13 @@ export const nameSchema = joi
|
||||
export const constraintSchema = joi.object().keys({
|
||||
contextName: joi.string(),
|
||||
operator: joi.string().valid(...ALL_OPERATORS),
|
||||
values: joi.array().items(joi.string().min(1).max(100)).min(1).optional(),
|
||||
value: joi.optional(),
|
||||
values: joi
|
||||
.array()
|
||||
.items(joi.string().min(1).max(100))
|
||||
.min(0)
|
||||
.default([])
|
||||
.optional(),
|
||||
value: joi.optional().default(''),
|
||||
caseInsensitive: joi.boolean().optional(),
|
||||
inverted: joi.boolean().optional(),
|
||||
});
|
||||
|
@ -165,17 +165,19 @@ class FeatureToggleService {
|
||||
}
|
||||
}
|
||||
|
||||
async validateConstraints(constraints: IConstraint[]): Promise<void> {
|
||||
async validateConstraints(
|
||||
constraints: IConstraint[],
|
||||
): Promise<IConstraint[]> {
|
||||
const validations = constraints.map((constraint) => {
|
||||
return this.validateConstraint(constraint);
|
||||
});
|
||||
|
||||
await Promise.all(validations);
|
||||
return Promise.all(validations);
|
||||
}
|
||||
|
||||
async validateConstraint(constraint: IConstraint): Promise<void> {
|
||||
async validateConstraint(constraint: IConstraint): Promise<IConstraint> {
|
||||
const { operator } = constraint;
|
||||
await constraintSchema.validateAsync(constraint);
|
||||
const scrubbedSchema = await constraintSchema.validateAsync(constraint);
|
||||
const contextDefinition = await this.contextFieldStore.get(
|
||||
constraint.contextName,
|
||||
);
|
||||
@ -218,6 +220,7 @@ class FeatureToggleService {
|
||||
);
|
||||
}
|
||||
}
|
||||
return scrubbedSchema;
|
||||
}
|
||||
|
||||
async patchFeature(
|
||||
@ -282,7 +285,9 @@ class FeatureToggleService {
|
||||
await this.validateFeatureContext(context);
|
||||
|
||||
if (strategyConfig.constraints?.length > 0) {
|
||||
await this.validateConstraints(strategyConfig.constraints);
|
||||
strategyConfig.constraints = await this.validateConstraints(
|
||||
strategyConfig.constraints,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -342,15 +347,18 @@ class FeatureToggleService {
|
||||
this.validateFeatureStrategyContext(existingStrategy, context);
|
||||
|
||||
if (existingStrategy.id === id) {
|
||||
if (updates.constraints?.length > 0) {
|
||||
const scrubbedConstraints = await this.validateConstraints(
|
||||
updates.constraints,
|
||||
);
|
||||
updates.constraints = scrubbedConstraints;
|
||||
}
|
||||
|
||||
const strategy = await this.featureStrategiesStore.updateStrategy(
|
||||
id,
|
||||
updates,
|
||||
);
|
||||
|
||||
if (updates.constraints?.length > 0) {
|
||||
await this.validateConstraints(updates.constraints);
|
||||
}
|
||||
|
||||
// Store event!
|
||||
const tags = await this.tagStore.getAllTagsForFeature(featureName);
|
||||
const data = this.featureStrategyToPublic(strategy);
|
||||
|
Loading…
Reference in New Issue
Block a user