Merge pull request #4732 from tsiegleauq/load-valid-filters-only

Check if the loaded filter definition has the valid format
This commit is contained in:
Sean 2019-05-22 12:49:24 +02:00 committed by GitHub
commit f52ca7d941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,7 +122,7 @@ export abstract class BaseFilterListService<V extends BaseViewModel> {
public async initFilters(inputData: Observable<V[]>): Promise<void> {
const storedFilter = await this.store.get<OsFilter[]>('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<V extends BaseViewModel> {
});
}
/**
* 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
*/