mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
Moving the config command and adding the error for server config when logged in (#9347)
This commit is contained in:
@@ -1,17 +1,21 @@
|
|||||||
import { OptionValues } from "commander";
|
import { OptionValues } from "commander";
|
||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import {
|
import {
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
Region,
|
Region,
|
||||||
} from "@bitwarden/common/platform/abstractions/environment.service";
|
} from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
|
|
||||||
import { Response } from "../models/response";
|
import { Response } from "../../models/response";
|
||||||
import { MessageResponse } from "../models/response/message.response";
|
import { MessageResponse } from "../../models/response/message.response";
|
||||||
import { StringResponse } from "../models/response/string.response";
|
import { StringResponse } from "../../models/response/string.response";
|
||||||
|
|
||||||
export class ConfigCommand {
|
export class ConfigCommand {
|
||||||
constructor(private environmentService: EnvironmentService) {}
|
constructor(
|
||||||
|
private environmentService: EnvironmentService,
|
||||||
|
private accountService: AccountService,
|
||||||
|
) {}
|
||||||
|
|
||||||
async run(setting: string, value: string, options: OptionValues): Promise<Response> {
|
async run(setting: string, value: string, options: OptionValues): Promise<Response> {
|
||||||
setting = setting.toLowerCase();
|
setting = setting.toLowerCase();
|
||||||
@@ -40,6 +44,12 @@ export class ConfigCommand {
|
|||||||
return Response.success(stringRes);
|
return Response.success(stringRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The server config cannot be updated while a user is actively logged in to the current server
|
||||||
|
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
if (activeAccount) {
|
||||||
|
return Response.error("Logout required before server config update.");
|
||||||
|
}
|
||||||
|
|
||||||
url = url === "null" || url === "bitwarden.com" || url === "https://bitwarden.com" ? null : url;
|
url = url === "null" || url === "bitwarden.com" || url === "https://bitwarden.com" ? null : url;
|
||||||
await this.environmentService.setEnvironment(Region.SelfHosted, {
|
await this.environmentService.setEnvironment(Region.SelfHosted, {
|
||||||
base: url,
|
base: url,
|
||||||
@@ -10,12 +10,12 @@ import { LogoutCommand } from "./auth/commands/logout.command";
|
|||||||
import { UnlockCommand } from "./auth/commands/unlock.command";
|
import { UnlockCommand } from "./auth/commands/unlock.command";
|
||||||
import { BaseProgram } from "./base-program";
|
import { BaseProgram } from "./base-program";
|
||||||
import { CompletionCommand } from "./commands/completion.command";
|
import { CompletionCommand } from "./commands/completion.command";
|
||||||
import { ConfigCommand } from "./commands/config.command";
|
|
||||||
import { EncodeCommand } from "./commands/encode.command";
|
import { EncodeCommand } from "./commands/encode.command";
|
||||||
import { StatusCommand } from "./commands/status.command";
|
import { StatusCommand } from "./commands/status.command";
|
||||||
import { UpdateCommand } from "./commands/update.command";
|
import { UpdateCommand } from "./commands/update.command";
|
||||||
import { Response } from "./models/response";
|
import { Response } from "./models/response";
|
||||||
import { MessageResponse } from "./models/response/message.response";
|
import { MessageResponse } from "./models/response/message.response";
|
||||||
|
import { ConfigCommand } from "./platform/commands/config.command";
|
||||||
import { GenerateCommand } from "./tools/generate.command";
|
import { GenerateCommand } from "./tools/generate.command";
|
||||||
import { CliUtils } from "./utils";
|
import { CliUtils } from "./utils";
|
||||||
import { SyncCommand } from "./vault/sync.command";
|
import { SyncCommand } from "./vault/sync.command";
|
||||||
@@ -403,7 +403,10 @@ export class Program extends BaseProgram {
|
|||||||
writeLn("", true);
|
writeLn("", true);
|
||||||
})
|
})
|
||||||
.action(async (setting, value, options) => {
|
.action(async (setting, value, options) => {
|
||||||
const command = new ConfigCommand(this.serviceContainer.environmentService);
|
const command = new ConfigCommand(
|
||||||
|
this.serviceContainer.environmentService,
|
||||||
|
this.serviceContainer.accountService,
|
||||||
|
);
|
||||||
const response = await command.run(setting, value, options);
|
const response = await command.run(setting, value, options);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user