mirror of
https://github.com/unraid/api.git
synced 2026-01-01 14:10:10 -06:00
feat: restart the API when an SSO user is added
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { CommandRunner, InquirerService, Option, SubCommand } from 'nest-commander';
|
import { CommandRunner, InquirerService, Option, SubCommand } from 'nest-commander';
|
||||||
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { store } from '@app/store/index';
|
import { store } from '@app/store/index';
|
||||||
import { addSsoUser, loadConfigFile } from '@app/store/modules/config';
|
import { addSsoUser, loadConfigFile } from '@app/store/modules/config';
|
||||||
import { writeConfigSync } from '@app/store/sync/config-disk-sync';
|
import { writeConfigSync } from '@app/store/sync/config-disk-sync';
|
||||||
import { LogService } from '@app/unraid-api/cli/log.service';
|
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 { AddSSOUserQuestionSet } from '@app/unraid-api/cli/sso/add-sso-user.questions';
|
||||||
import { v4 } from 'uuid';
|
|
||||||
|
|
||||||
interface AddSSOUserCommandOptions {
|
interface AddSSOUserCommandOptions {
|
||||||
disclaimer: string;
|
disclaimer: string;
|
||||||
@@ -23,7 +24,8 @@ interface AddSSOUserCommandOptions {
|
|||||||
export class AddSSOUserCommand extends CommandRunner {
|
export class AddSSOUserCommand extends CommandRunner {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly logger: LogService,
|
private readonly logger: LogService,
|
||||||
private readonly inquirerService: InquirerService
|
private readonly inquirerService: InquirerService,
|
||||||
|
private readonly restartCommand: RestartCommand
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -33,9 +35,14 @@ export class AddSSOUserCommand extends CommandRunner {
|
|||||||
options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options);
|
options = await this.inquirerService.prompt(AddSSOUserQuestionSet.name, options);
|
||||||
if (options.disclaimer === 'y' && options.username) {
|
if (options.disclaimer === 'y' && options.username) {
|
||||||
await store.dispatch(loadConfigFile());
|
await store.dispatch(loadConfigFile());
|
||||||
|
const shouldRestart = store.getState().config.remote.ssoSubIds.length === 0;
|
||||||
store.dispatch(addSsoUser(options.username));
|
store.dispatch(addSsoUser(options.username));
|
||||||
writeConfigSync('flash');
|
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) {
|
} catch (e: unknown) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user