2023-08-25 01:33:46 -07:00
|
|
|
import { EXTERNAL_SECRETS_DB_KEY } from '@/ExternalSecrets/constants';
|
2023-04-12 01:59:14 -07:00
|
|
|
import { Service } from 'typedi';
|
|
|
|
import { DataSource, Repository } from 'typeorm';
|
2023-07-19 06:59:49 -07:00
|
|
|
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
2023-04-12 01:59:14 -07:00
|
|
|
import { Settings } from '../entities/Settings';
|
2023-06-19 07:23:57 -07:00
|
|
|
import config from '@/config';
|
2023-04-12 01:59:14 -07:00
|
|
|
|
|
|
|
@Service()
|
|
|
|
export class SettingsRepository extends Repository<Settings> {
|
|
|
|
constructor(dataSource: DataSource) {
|
|
|
|
super(Settings, dataSource.manager);
|
|
|
|
}
|
2023-06-19 07:23:57 -07:00
|
|
|
|
2023-08-25 01:33:46 -07:00
|
|
|
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'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-14 06:36:17 -07:00
|
|
|
async dismissBanner({ bannerName }: { bannerName: string }): Promise<{ success: boolean }> {
|
2023-07-19 06:59:49 -07:00
|
|
|
const key = 'ui.banners.dismissed';
|
|
|
|
const dismissedBannersSetting = await this.findOneBy({ key });
|
|
|
|
try {
|
|
|
|
let value: string;
|
|
|
|
if (dismissedBannersSetting) {
|
2023-07-14 06:36:17 -07:00
|
|
|
const dismissedBanners = JSON.parse(dismissedBannersSetting.value) as string[];
|
2023-07-19 06:59:49 -07:00
|
|
|
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 });
|
2023-07-14 06:36:17 -07:00
|
|
|
}
|
2023-07-19 06:59:49 -07:00
|
|
|
config.set(key, value);
|
|
|
|
return { success: true };
|
|
|
|
} catch (error) {
|
|
|
|
ErrorReporter.error(error);
|
2023-07-14 06:36:17 -07:00
|
|
|
}
|
|
|
|
return { success: false };
|
|
|
|
}
|
2023-04-12 01:59:14 -07:00
|
|
|
}
|