-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-5237] Clients, Self Hosted: Login - Hide "Create account" when re…
…gistration 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 <[email protected]>
- Loading branch information
1 parent
1afb2f7
commit f5e6fc8
Showing
12 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
libs/common/src/platform/models/domain/server-settings.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ServerSettings } from "./server-settings"; | ||
|
||
describe("ServerSettings", () => { | ||
describe("disableUserRegistration", () => { | ||
it("defaults disableUserRegistration to false", () => { | ||
const settings = new ServerSettings(); | ||
expect(settings.disableUserRegistration).toBe(false); | ||
}); | ||
|
||
it("sets disableUserRegistration to true when provided", () => { | ||
const settings = new ServerSettings({ disableUserRegistration: true }); | ||
expect(settings.disableUserRegistration).toBe(true); | ||
}); | ||
|
||
it("sets disableUserRegistration to false when provided", () => { | ||
const settings = new ServerSettings({ disableUserRegistration: false }); | ||
expect(settings.disableUserRegistration).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class ServerSettings { | ||
disableUserRegistration: boolean; | ||
|
||
constructor(data?: ServerSettings) { | ||
this.disableUserRegistration = data?.disableUserRegistration ?? false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
libs/common/src/platform/services/default-server-settings.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
libs/common/src/platform/services/default-server-settings.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
); | ||
} | ||
} |