From dae57389c6917cc451a0c2d8864f21fb1f1e8bb1 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Mon, 27 Jan 2025 12:04:05 -0500 Subject: [PATCH] feat: restart the API when an SSO user is added --- api/src/unraid-api/cli/sso/add-sso-user.command.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/src/unraid-api/cli/sso/add-sso-user.command.ts b/api/src/unraid-api/cli/sso/add-sso-user.command.ts index 3aa3d0a12..10e955db5 100644 --- a/api/src/unraid-api/cli/sso/add-sso-user.command.ts +++ b/api/src/unraid-api/cli/sso/add-sso-user.command.ts @@ -1,13 +1,14 @@ import { Injectable } from '@nestjs/common'; import { CommandRunner, InquirerService, Option, SubCommand } from 'nest-commander'; +import { v4 } from 'uuid'; import { store } from '@app/store/index'; import { addSsoUser, loadConfigFile } from '@app/store/modules/config'; import { writeConfigSync } from '@app/store/sync/config-disk-sync'; import { LogService } from '@app/unraid-api/cli/log.service'; +import { RestartCommand } from '@app/unraid-api/cli/restart.command'; import { AddSSOUserQuestionSet } from '@app/unraid-api/cli/sso/add-sso-user.questions'; -import { v4 } from 'uuid'; interface AddSSOUserCommandOptions { disclaimer: string; @@ -23,7 +24,8 @@ interface AddSSOUserCommandOptions { export class AddSSOUserCommand extends CommandRunner { constructor( private readonly logger: LogService, - private readonly inquirerService: InquirerService + private readonly inquirerService: InquirerService, + private readonly restartCommand: RestartCommand ) { super(); } @@ -33,9 +35,14 @@ export class AddSSOUserCommand extends CommandRunner { options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options); if (options.disclaimer === 'y' && options.username) { await store.dispatch(loadConfigFile()); + const shouldRestart = store.getState().config.remote.ssoSubIds.length === 0; store.dispatch(addSsoUser(options.username)); writeConfigSync('flash'); - this.logger.info('User added ' + options.username); + this.logger.info(`User added ${options.username}`); + if (shouldRestart) { + this.logger.info('Restarting the Unraid API to enable to SSO button'); + await this.restartCommand.run([]); + } } } catch (e: unknown) { if (e instanceof Error) {