feat: feedback resolve
This commit is contained in:
@@ -241,14 +241,14 @@ export class InfraResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => [InfraConfig], {
|
@Query(() => [InfraConfig], {
|
||||||
description: 'Fetch infra configs',
|
description: 'Retrieve configuration details for the instance',
|
||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
||||||
async infraConfigs(
|
async infraConfigs(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'names',
|
name: 'configNames',
|
||||||
type: () => [InfraConfigEnumForClient],
|
type: () => [InfraConfigEnumForClient],
|
||||||
description: 'Names of the InfraConfigs',
|
description: 'Configs to fetch',
|
||||||
})
|
})
|
||||||
names: InfraConfigEnumForClient[],
|
names: InfraConfigEnumForClient[],
|
||||||
) {
|
) {
|
||||||
@@ -300,13 +300,13 @@ export class InfraResolver {
|
|||||||
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
||||||
async enableAndDisableSSO(
|
async enableAndDisableSSO(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'data',
|
name: 'providerInfo',
|
||||||
type: () => [EnableAndDisableSSOArgs],
|
type: () => [EnableAndDisableSSOArgs],
|
||||||
description: 'SSO provider and status',
|
description: 'SSO provider and status',
|
||||||
})
|
})
|
||||||
data: EnableAndDisableSSOArgs[],
|
providerInfo: EnableAndDisableSSOArgs[],
|
||||||
) {
|
) {
|
||||||
const isUpdated = await this.infraConfigService.enableAndDisableSSO(data);
|
const isUpdated = await this.infraConfigService.enableAndDisableSSO(providerInfo);
|
||||||
if (E.isLeft(isUpdated)) throwErr(isUpdated.left);
|
if (E.isLeft(isUpdated)) throwErr(isUpdated.left);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -671,7 +671,7 @@ export const INFRA_CONFIG_NOT_LISTED =
|
|||||||
export const INFRA_CONFIG_RESET_FAILED = 'infra_config/reset_failed' as const;
|
export const INFRA_CONFIG_RESET_FAILED = 'infra_config/reset_failed' as const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Infra Config reset failed
|
* Infra Config invalid input for Config variable
|
||||||
* (InfraConfigService)
|
* (InfraConfigService)
|
||||||
*/
|
*/
|
||||||
export const INFRA_CONFIG_INVALID_INPUT = 'infra_config/invalid_input' as const;
|
export const INFRA_CONFIG_INVALID_INPUT = 'infra_config/invalid_input' as const;
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ export class InfraConfigService implements OnModuleInit {
|
|||||||
*/
|
*/
|
||||||
async initializeInfraConfigTable() {
|
async initializeInfraConfigTable() {
|
||||||
try {
|
try {
|
||||||
// Get all the 'names' for 'infra_config' table
|
// Get all the 'names' of the properties to be saved in the 'infra_config' table
|
||||||
const enumValues = Object.values(InfraConfigEnum);
|
const enumValues = Object.values(InfraConfigEnum);
|
||||||
|
|
||||||
// Prepare rows for 'infra_config' table with default values for each 'name'
|
// Fetch the default values (value in .env) for configs to be saved in 'infra_config' table
|
||||||
const infraConfigDefaultObjs = this.getDefaultInfraConfigs();
|
const infraConfigDefaultObjs = this.getDefaultInfraConfigs();
|
||||||
|
|
||||||
// Check if all the 'names' are listed in the default values
|
// Check if all the 'names' are listed in the default values
|
||||||
@@ -166,19 +166,11 @@ export class InfraConfigService implements OnModuleInit {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await this.prisma.$transaction(async (tx) => {
|
await this.prisma.$transaction(async (tx) => {
|
||||||
const deleteCount = await tx.infraConfig.deleteMany({
|
for (let i = 0; i < infraConfigs.length; i++) {
|
||||||
where: { name: { in: infraConfigs.map((p) => p.name) } },
|
await tx.infraConfig.update({
|
||||||
|
where: { name: infraConfigs[i].name },
|
||||||
|
data: { value: infraConfigs[i].value },
|
||||||
});
|
});
|
||||||
|
|
||||||
const createCount = await tx.infraConfig.createMany({
|
|
||||||
data: infraConfigs.map((p) => ({
|
|
||||||
name: p.name,
|
|
||||||
value: p.value,
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (deleteCount.count !== createCount.count) {
|
|
||||||
return E.left(INFRA_CONFIG_UPDATE_FAILED);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -196,32 +188,32 @@ export class InfraConfigService implements OnModuleInit {
|
|||||||
* @param status Status to enable or disable
|
* @param status Status to enable or disable
|
||||||
* @returns Either true or an error
|
* @returns Either true or an error
|
||||||
*/
|
*/
|
||||||
async enableAndDisableSSO(statusList: EnableAndDisableSSOArgs[]) {
|
async enableAndDisableSSO(providerInfo: EnableAndDisableSSOArgs[]) {
|
||||||
const enabledAuthProviders = this.configService
|
const allowedAuthProviders = this.configService
|
||||||
.get('INFRA.VITE_ALLOWED_AUTH_PROVIDERS')
|
.get<string>('INFRA.VITE_ALLOWED_AUTH_PROVIDERS')
|
||||||
.split(',');
|
.split(',');
|
||||||
|
|
||||||
let newEnabledAuthProviders = enabledAuthProviders;
|
let updatedAuthProviders = allowedAuthProviders;
|
||||||
|
|
||||||
statusList.forEach(({ provider, status }) => {
|
providerInfo.forEach(({ provider, status }) => {
|
||||||
if (status === AuthProviderStatus.ENABLE) {
|
if (status === AuthProviderStatus.ENABLE) {
|
||||||
newEnabledAuthProviders = [...newEnabledAuthProviders, provider];
|
updatedAuthProviders.push(provider);
|
||||||
} else if (status === AuthProviderStatus.DISABLE) {
|
} else if (status === AuthProviderStatus.DISABLE) {
|
||||||
newEnabledAuthProviders = newEnabledAuthProviders.filter(
|
updatedAuthProviders = updatedAuthProviders.filter(
|
||||||
(p) => p !== provider,
|
(p) => p !== provider,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
newEnabledAuthProviders = [...new Set(newEnabledAuthProviders)];
|
updatedAuthProviders = [...new Set(updatedAuthProviders)];
|
||||||
|
|
||||||
if (newEnabledAuthProviders.length === 0) {
|
if (updatedAuthProviders.length === 0) {
|
||||||
return E.left(AUTH_PROVIDER_NOT_SPECIFIED);
|
return E.left(AUTH_PROVIDER_NOT_SPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUpdated = await this.update(
|
const isUpdated = await this.update(
|
||||||
InfraConfigEnum.VITE_ALLOWED_AUTH_PROVIDERS,
|
InfraConfigEnum.VITE_ALLOWED_AUTH_PROVIDERS,
|
||||||
newEnabledAuthProviders.join(','),
|
updatedAuthProviders.join(','),
|
||||||
);
|
);
|
||||||
if (E.isLeft(isUpdated)) return E.left(isUpdated.left);
|
if (E.isLeft(isUpdated)) return E.left(isUpdated.left);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user