From bd4da53255e5bb5b98e048b03367f45447e6ed8e Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Wed, 22 May 2019 12:06:59 +0200 Subject: [PATCH] Check if the loaded filter definition has the valid format Fixes an issue where malformated or old filter-definition where considered to be valid filters which could cause some issues --- .../ui-services/base-filter-list.service.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/src/app/core/ui-services/base-filter-list.service.ts b/client/src/app/core/ui-services/base-filter-list.service.ts index 441263023..2fec27228 100644 --- a/client/src/app/core/ui-services/base-filter-list.service.ts +++ b/client/src/app/core/ui-services/base-filter-list.service.ts @@ -122,7 +122,7 @@ export abstract class BaseFilterListService { public async initFilters(inputData: Observable): Promise { const storedFilter = await this.store.get('filter_' + this.name); - if (storedFilter) { + if (storedFilter && this.isOsFilter(storedFilter)) { this.filterDefinitions = storedFilter; } else { this.filterDefinitions = this.getFilterDefinitions(); @@ -139,6 +139,29 @@ export abstract class BaseFilterListService { }); } + /** + * Checks if the (stored) filter list matches the current definition of OsFilter + * + * @param storedFilter + * @returns boolean + */ + private isOsFilter(storedFilter: OsFilter[]): boolean { + if (Array.isArray(storedFilter) && storedFilter.length) { + return storedFilter.every(filter => { + // Interfaces do not exist at runtime. Manually check if the + // Required information of the interface are present + return ( + filter.hasOwnProperty('options') && + filter.hasOwnProperty('property') && + filter.options.length && + !!filter.property + ); + }); + } else { + return false; + } + } + /** * Enforce children implement a method that returns actual filter definitions */