mirror of
https://github.com/bitwarden/browser
synced 2026-01-06 10:33:57 +00:00
[PM-5237] Clients, Self Hosted: Login - Hide "Create account" when registration disabled (#11811)
* Add server settings model and service. * Inject ServerSettingsService into the login-secondary-content component. * Fix merge conflict * Add server settings to old views * Remove server settings from desktop/mobile * Cleanup unused code * Remove changes to default config * Conditionally show/hide HR element * Add tests * PM-5237 - Move ServerSettingsService to jslib-services.module so it is the same across all clients and to solve NullInjectorErrors on desktop & browser extension * Remove change to v1 components * Rename ServerSettingsService to DefaultServerSettingsService * Remove unnecessary map call * Remove server interface in favor of using ServerSettings class * Add back HR element --------- Co-authored-by: Jared Snider <jsnider@bitwarden.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import { Environment, EnvironmentService, Region } from "../../abstractions/envi
|
||||
import { LogService } from "../../abstractions/log.service";
|
||||
import { devFlagEnabled, devFlagValue } from "../../misc/flags";
|
||||
import { ServerConfigData } from "../../models/data/server-config.data";
|
||||
import { ServerSettings } from "../../models/domain/server-settings";
|
||||
import { CONFIG_DISK, KeyDefinition, StateProvider, UserKeyDefinition } from "../../state";
|
||||
|
||||
export const RETRIEVAL_INTERVAL = devFlagEnabled("configRetrievalIntervalMs")
|
||||
@@ -57,6 +58,8 @@ export class DefaultConfigService implements ConfigService {
|
||||
|
||||
serverConfig$: Observable<ServerConfig>;
|
||||
|
||||
serverSettings$: Observable<ServerSettings>;
|
||||
|
||||
cloudRegion$: Observable<Region>;
|
||||
|
||||
constructor(
|
||||
@@ -111,6 +114,10 @@ export class DefaultConfigService implements ConfigService {
|
||||
this.cloudRegion$ = this.serverConfig$.pipe(
|
||||
map((config) => config?.environment?.cloudRegion ?? Region.US),
|
||||
);
|
||||
|
||||
this.serverSettings$ = this.serverConfig$.pipe(
|
||||
map((config) => config?.settings ?? new ServerSettings()),
|
||||
);
|
||||
}
|
||||
|
||||
getFeatureFlag$<Flag extends FeatureFlag>(key: Flag) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { of } from "rxjs";
|
||||
|
||||
import { ConfigService } from "../abstractions/config/config.service";
|
||||
import { ServerSettings } from "../models/domain/server-settings";
|
||||
|
||||
import { DefaultServerSettingsService } from "./default-server-settings.service";
|
||||
|
||||
describe("DefaultServerSettingsService", () => {
|
||||
let service: DefaultServerSettingsService;
|
||||
let configServiceMock: { serverSettings$: any };
|
||||
|
||||
beforeEach(() => {
|
||||
configServiceMock = { serverSettings$: of() };
|
||||
service = new DefaultServerSettingsService(configServiceMock as ConfigService);
|
||||
});
|
||||
|
||||
describe("getSettings$", () => {
|
||||
it("returns server settings", () => {
|
||||
const mockSettings = new ServerSettings({ disableUserRegistration: true });
|
||||
configServiceMock.serverSettings$ = of(mockSettings);
|
||||
|
||||
service.getSettings$().subscribe((settings) => {
|
||||
expect(settings).toEqual(mockSettings);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("isUserRegistrationDisabled$", () => {
|
||||
it("returns true when user registration is disabled", () => {
|
||||
const mockSettings = new ServerSettings({ disableUserRegistration: true });
|
||||
configServiceMock.serverSettings$ = of(mockSettings);
|
||||
|
||||
service.isUserRegistrationDisabled$.subscribe((isDisabled: boolean) => {
|
||||
expect(isDisabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns false when user registration is enabled", () => {
|
||||
const mockSettings = new ServerSettings({ disableUserRegistration: false });
|
||||
configServiceMock.serverSettings$ = of(mockSettings);
|
||||
|
||||
service.isUserRegistrationDisabled$.subscribe((isDisabled: boolean) => {
|
||||
expect(isDisabled).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
import { ConfigService } from "../abstractions/config/config.service";
|
||||
import { ServerSettings } from "../models/domain/server-settings";
|
||||
|
||||
export class DefaultServerSettingsService {
|
||||
constructor(private configService: ConfigService) {}
|
||||
|
||||
getSettings$(): Observable<ServerSettings> {
|
||||
return this.configService.serverSettings$;
|
||||
}
|
||||
|
||||
get isUserRegistrationDisabled$(): Observable<boolean> {
|
||||
return this.getSettings$().pipe(
|
||||
map((settings: ServerSettings) => settings.disableUserRegistration),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user