mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
fix(core): Banner dismissal should also work for users migrating to v1 (no-changelog) (#6700)
This commit is contained in:
parent
cc29c4da74
commit
8bb7243c2d
|
@ -1,5 +1,6 @@
|
|||
import { Service } from 'typedi';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
||||
import { Settings } from '../entities/Settings';
|
||||
import config from '@/config';
|
||||
|
||||
|
@ -10,32 +11,24 @@ export class SettingsRepository extends Repository<Settings> {
|
|||
}
|
||||
|
||||
async dismissBanner({ bannerName }: { bannerName: string }): Promise<{ success: boolean }> {
|
||||
const dismissedBannersSetting = await this.findOneBy({ key: 'ui.banners.dismissed' });
|
||||
|
||||
if (dismissedBannersSetting) {
|
||||
try {
|
||||
const key = 'ui.banners.dismissed';
|
||||
const dismissedBannersSetting = await this.findOneBy({ key });
|
||||
try {
|
||||
let value: string;
|
||||
if (dismissedBannersSetting) {
|
||||
const dismissedBanners = JSON.parse(dismissedBannersSetting.value) as string[];
|
||||
await this.saveSetting(
|
||||
'ui.banners.dismissed',
|
||||
JSON.stringify([...dismissedBanners, bannerName]),
|
||||
);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false };
|
||||
const updatedValue = [...new Set([...dismissedBanners, bannerName].sort())];
|
||||
value = JSON.stringify(updatedValue);
|
||||
await this.update({ key }, { value, loadOnStartup: true });
|
||||
} else {
|
||||
value = JSON.stringify([bannerName]);
|
||||
await this.save({ key, value, loadOnStartup: true });
|
||||
}
|
||||
config.set(key, value);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
ErrorReporter.error(error);
|
||||
}
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
async saveSetting(key: string, value: string, loadOnStartup = true) {
|
||||
const setting = await this.findOneBy({ key });
|
||||
|
||||
if (setting) {
|
||||
await this.update({ key }, { value, loadOnStartup });
|
||||
} else {
|
||||
await this.save({ key, value, loadOnStartup });
|
||||
}
|
||||
|
||||
if (loadOnStartup) config.set('ui.banners.dismissed', value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue