1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-18 02:41:15 +02:00

Moving the config command and adding the error for server config when logged in (#9347)

This commit is contained in:
Tom 2024-06-17 11:00:19 -04:00 committed by GitHub
parent 95554af9e2
commit c26669cf60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View File

@ -1,17 +1,21 @@
import { OptionValues } from "commander";
import { firstValueFrom } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import {
EnvironmentService,
Region,
} from "@bitwarden/common/platform/abstractions/environment.service";
import { Response } from "../models/response";
import { MessageResponse } from "../models/response/message.response";
import { StringResponse } from "../models/response/string.response";
import { Response } from "../../models/response";
import { MessageResponse } from "../../models/response/message.response";
import { StringResponse } from "../../models/response/string.response";
export class ConfigCommand {
constructor(private environmentService: EnvironmentService) {}
constructor(
private environmentService: EnvironmentService,
private accountService: AccountService,
) {}
async run(setting: string, value: string, options: OptionValues): Promise<Response> {
setting = setting.toLowerCase();
@ -40,6 +44,12 @@ export class ConfigCommand {
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;
await this.environmentService.setEnvironment(Region.SelfHosted, {
base: url,

View File

@ -10,12 +10,12 @@ import { LogoutCommand } from "./auth/commands/logout.command";
import { UnlockCommand } from "./auth/commands/unlock.command";
import { BaseProgram } from "./base-program";
import { CompletionCommand } from "./commands/completion.command";
import { ConfigCommand } from "./commands/config.command";
import { EncodeCommand } from "./commands/encode.command";
import { StatusCommand } from "./commands/status.command";
import { UpdateCommand } from "./commands/update.command";
import { Response } from "./models/response";
import { MessageResponse } from "./models/response/message.response";
import { ConfigCommand } from "./platform/commands/config.command";
import { GenerateCommand } from "./tools/generate.command";
import { CliUtils } from "./utils";
import { SyncCommand } from "./vault/sync.command";
@ -403,7 +403,10 @@ export class Program extends BaseProgram {
writeLn("", true);
})
.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);
this.processResponse(response);
});