fix: allowedAuthProviders and enableAndDisableSSO
This commit is contained in:
@@ -25,9 +25,10 @@ import { GqlAdmin } from './decorators/gql-admin.decorator';
|
|||||||
import { ShortcodeWithUserEmail } from 'src/shortcode/shortcode.model';
|
import { ShortcodeWithUserEmail } from 'src/shortcode/shortcode.model';
|
||||||
import { InfraConfig } from 'src/infra-config/infra-config.model';
|
import { InfraConfig } from 'src/infra-config/infra-config.model';
|
||||||
import { InfraConfigService } from 'src/infra-config/infra-config.service';
|
import { InfraConfigService } from 'src/infra-config/infra-config.service';
|
||||||
import { InfraConfigArgs } from 'src/infra-config/input-args';
|
import {
|
||||||
import { AuthProvider } from 'src/auth/helper';
|
EnableAndDisableSSOArgs,
|
||||||
import { AuthProviderStatus } from 'src/infra-config/helper';
|
InfraConfigArgs,
|
||||||
|
} from 'src/infra-config/input-args';
|
||||||
import { InfraConfigEnumForClient } from 'src/types/InfraConfig';
|
import { InfraConfigEnumForClient } from 'src/types/InfraConfig';
|
||||||
|
|
||||||
@UseGuards(GqlThrottlerGuard)
|
@UseGuards(GqlThrottlerGuard)
|
||||||
@@ -251,7 +252,6 @@ export class InfraResolver {
|
|||||||
})
|
})
|
||||||
names: InfraConfigEnumForClient[],
|
names: InfraConfigEnumForClient[],
|
||||||
) {
|
) {
|
||||||
console.log(names);
|
|
||||||
const infraConfigs = await this.infraConfigService.getMany(names);
|
const infraConfigs = await this.infraConfigService.getMany(names);
|
||||||
if (E.isLeft(infraConfigs)) throwErr(infraConfigs.left);
|
if (E.isLeft(infraConfigs)) throwErr(infraConfigs.left);
|
||||||
return infraConfigs.right;
|
return infraConfigs.right;
|
||||||
@@ -260,7 +260,6 @@ export class InfraResolver {
|
|||||||
@Query(() => [String], {
|
@Query(() => [String], {
|
||||||
description: 'Allowed Auth Provider list',
|
description: 'Allowed Auth Provider list',
|
||||||
})
|
})
|
||||||
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
|
||||||
allowedAuthProviders() {
|
allowedAuthProviders() {
|
||||||
return this.infraConfigService.getAllowedAuthProviders();
|
return this.infraConfigService.getAllowedAuthProviders();
|
||||||
}
|
}
|
||||||
@@ -300,22 +299,13 @@ export class InfraResolver {
|
|||||||
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
@UseGuards(GqlAuthGuard, GqlAdminGuard)
|
||||||
async enableAndDisableSSO(
|
async enableAndDisableSSO(
|
||||||
@Args({
|
@Args({
|
||||||
name: 'provider',
|
name: 'data',
|
||||||
type: () => AuthProvider,
|
type: () => [EnableAndDisableSSOArgs],
|
||||||
description: 'Auth Provider to enable or disable',
|
description: 'SSO provider and status',
|
||||||
})
|
})
|
||||||
provider: AuthProvider,
|
data: EnableAndDisableSSOArgs[],
|
||||||
@Args({
|
|
||||||
name: 'status',
|
|
||||||
type: () => AuthProviderStatus,
|
|
||||||
description: 'Status to enable or disable',
|
|
||||||
})
|
|
||||||
status: AuthProviderStatus,
|
|
||||||
) {
|
) {
|
||||||
const isUpdated = await this.infraConfigService.enableAndDisableSSO(
|
const isUpdated = await this.infraConfigService.enableAndDisableSSO(data);
|
||||||
provider,
|
|
||||||
status,
|
|
||||||
);
|
|
||||||
if (E.isLeft(isUpdated)) throwErr(isUpdated.left);
|
if (E.isLeft(isUpdated)) throwErr(isUpdated.left);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ import {
|
|||||||
import { throwErr, validateUrl } from 'src/utils';
|
import { throwErr, validateUrl } from 'src/utils';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { AuthProviderStatus, stopApp } from './helper';
|
import { AuthProviderStatus, stopApp } from './helper';
|
||||||
import { InfraConfigArgs } from './input-args';
|
import { EnableAndDisableSSOArgs, InfraConfigArgs } from './input-args';
|
||||||
import { AuthProvider } from 'src/auth/helper';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InfraConfigService implements OnModuleInit {
|
export class InfraConfigService implements OnModuleInit {
|
||||||
@@ -197,25 +196,27 @@ 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(
|
async enableAndDisableSSO(statusList: EnableAndDisableSSOArgs[]) {
|
||||||
provider: AuthProvider,
|
|
||||||
status: AuthProviderStatus,
|
|
||||||
) {
|
|
||||||
const enabledAuthProviders = this.configService
|
const enabledAuthProviders = this.configService
|
||||||
.get('INFRA.VITE_ALLOWED_AUTH_PROVIDERS')
|
.get('INFRA.VITE_ALLOWED_AUTH_PROVIDERS')
|
||||||
.split(',');
|
.split(',');
|
||||||
const isProviderEnabled = enabledAuthProviders.includes(provider);
|
|
||||||
|
|
||||||
let newEnabledAuthProviders = enabledAuthProviders;
|
let newEnabledAuthProviders = enabledAuthProviders;
|
||||||
if (status === AuthProviderStatus.ENABLE && !isProviderEnabled) {
|
|
||||||
newEnabledAuthProviders = [...enabledAuthProviders, provider];
|
statusList.forEach(({ provider, status }) => {
|
||||||
} else if (status === AuthProviderStatus.DISABLE && isProviderEnabled) {
|
if (status === AuthProviderStatus.ENABLE) {
|
||||||
newEnabledAuthProviders = enabledAuthProviders.filter(
|
newEnabledAuthProviders = [...newEnabledAuthProviders, provider];
|
||||||
(p) => p !== provider,
|
} else if (status === AuthProviderStatus.DISABLE) {
|
||||||
);
|
newEnabledAuthProviders = newEnabledAuthProviders.filter(
|
||||||
if (newEnabledAuthProviders.length === 0) {
|
(p) => p !== provider,
|
||||||
return E.left(AUTH_PROVIDER_NOT_SPECIFIED);
|
);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
newEnabledAuthProviders = [...new Set(newEnabledAuthProviders)];
|
||||||
|
|
||||||
|
if (newEnabledAuthProviders.length === 0) {
|
||||||
|
return E.left(AUTH_PROVIDER_NOT_SPECIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUpdated = await this.update(
|
const isUpdated = await this.update(
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Field, InputType } from '@nestjs/graphql';
|
import { Field, InputType } from '@nestjs/graphql';
|
||||||
import { InfraConfigEnumForClient } from 'src/types/InfraConfig';
|
import { InfraConfigEnumForClient } from 'src/types/InfraConfig';
|
||||||
|
import { AuthProviderStatus } from './helper';
|
||||||
|
import { AuthProvider } from 'src/auth/helper';
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
export class InfraConfigArgs {
|
export class InfraConfigArgs {
|
||||||
@@ -13,3 +15,16 @@ export class InfraConfigArgs {
|
|||||||
})
|
})
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InputType()
|
||||||
|
export class EnableAndDisableSSOArgs {
|
||||||
|
@Field(() => AuthProvider, {
|
||||||
|
description: 'Auth Provider',
|
||||||
|
})
|
||||||
|
provider: AuthProvider;
|
||||||
|
|
||||||
|
@Field(() => AuthProviderStatus, {
|
||||||
|
description: 'Auth Provider Status',
|
||||||
|
})
|
||||||
|
status: AuthProviderStatus;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user