mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-31 23:47:28 -08:00
ed927d34b2
Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Romain Minaud <romain.minaud@gmail.com> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Csaba Tuncsik <csaba@n8n.io> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { EXTERNAL_SECRETS_DB_KEY } from '@/ExternalSecrets/constants';
|
|
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';
|
|
|
|
@Service()
|
|
export class SettingsRepository extends Repository<Settings> {
|
|
constructor(dataSource: DataSource) {
|
|
super(Settings, dataSource.manager);
|
|
}
|
|
|
|
async getEncryptedSecretsProviderSettings(): Promise<string | null> {
|
|
return (await this.findOne({ where: { key: EXTERNAL_SECRETS_DB_KEY } }))?.value ?? null;
|
|
}
|
|
|
|
async saveEncryptedSecretsProviderSettings(data: string): Promise<void> {
|
|
await this.upsert(
|
|
{
|
|
key: EXTERNAL_SECRETS_DB_KEY,
|
|
value: data,
|
|
loadOnStartup: false,
|
|
},
|
|
['key'],
|
|
);
|
|
}
|
|
|
|
async dismissBanner({ bannerName }: { bannerName: string }): Promise<{ success: boolean }> {
|
|
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[];
|
|
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 };
|
|
}
|
|
}
|