mirror of
https://github.com/bitwarden/browser
synced 2026-02-10 05:30:01 +00:00
update getManagedEnvironment so it can be used in all clients
This commit is contained in:
@@ -35,7 +35,7 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService {
|
||||
return false;
|
||||
}
|
||||
|
||||
const managedEnv = await this.getManagedEnvironment();
|
||||
const managedEnv = await this.getManagedEnvironment<GroupPolicyEnvironment>();
|
||||
const env = await firstValueFrom(this.environment$);
|
||||
const urls = env.getUrls();
|
||||
|
||||
@@ -50,9 +50,9 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService {
|
||||
);
|
||||
}
|
||||
|
||||
getManagedEnvironment(): Promise<GroupPolicyEnvironment> {
|
||||
getManagedEnvironment<T = GroupPolicyEnvironment>(): Promise<T | null> {
|
||||
return devFlagEnabled("managedEnvironment")
|
||||
? new Promise((resolve) => resolve(devFlagValue("managedEnvironment")))
|
||||
? new Promise((resolve) => resolve(devFlagValue("managedEnvironment") as T))
|
||||
: new Promise((resolve, reject) => {
|
||||
if (chrome.storage.managed == null) {
|
||||
return resolve(null);
|
||||
@@ -63,13 +63,13 @@ export class BrowserEnvironmentService extends DefaultEnvironmentService {
|
||||
return reject(chrome.runtime.lastError);
|
||||
}
|
||||
|
||||
resolve(result.environment);
|
||||
resolve(result.environment as T);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async setUrlsToManagedEnvironment() {
|
||||
const env = await this.getManagedEnvironment();
|
||||
const env = await this.getManagedEnvironment<GroupPolicyEnvironment>();
|
||||
await this.setEnvironment(Region.SelfHosted, {
|
||||
base: env.base,
|
||||
webVault: env.webVault,
|
||||
|
||||
@@ -100,6 +100,13 @@ export class WebEnvironmentService extends DefaultEnvironmentService {
|
||||
// This return shouldn't matter as we are about to leave the current window
|
||||
return chosenRegionConfig.urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op for web environment service.
|
||||
*/
|
||||
async getManagedEnvironment(): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export class WebCloudEnvironment extends CloudEnvironment {
|
||||
|
||||
@@ -134,4 +134,11 @@ export abstract class EnvironmentService {
|
||||
* @deprecated Use {@link getEnvironment$} instead.
|
||||
*/
|
||||
abstract getEnvironment(userId?: string): Promise<Environment | undefined>;
|
||||
|
||||
/**
|
||||
* Get the managed environment configuration if one exists.
|
||||
* @typeParam T - The type of the managed environment configuration.
|
||||
* @returns A promise that resolves to the managed environment configuration or null if it doesn't exist.
|
||||
*/
|
||||
abstract getManagedEnvironment<T = unknown>(): Promise<T | null>;
|
||||
}
|
||||
|
||||
@@ -293,6 +293,13 @@ export class DefaultEnvironmentService implements EnvironmentService {
|
||||
const global = await firstValueFrom(this.globalState.state$);
|
||||
await this.stateProvider.getUser(userId, USER_ENVIRONMENT_KEY).update(() => global);
|
||||
}
|
||||
|
||||
/**
|
||||
* No-op for default environment service.
|
||||
*/
|
||||
async getManagedEnvironment<T = unknown>(): Promise<T | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function formatUrl(url: string): string {
|
||||
|
||||
Reference in New Issue
Block a user