Skip to content

Commit 8d8834b

Browse files
committed
fix: fail if config.json not loaded
and clean up bootstrap process and only use environment, removing duplicate AppSettings class closes #2474
1 parent 1818e7f commit 8d8834b

21 files changed

+123
-143
lines changed

build/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ server {
3939
root /usr/share/nginx/html;
4040
}
4141

42-
# The proxy path should be the same as in AppSettings.DB_PROXY_PREFIX
42+
# The proxy path should be the same as in environment.DB_PROXY_PREFIX
4343
location ^~ /db {
4444
rewrite /db/(.*) /$1 break;
4545
proxy_pass ${COUCHDB_URL};

doc/compodoc_sources/how-to-guides/generate-demo-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This Guide walks you through the steps to add data to this demo mode for your ow
1515
In the AppModule (or wherever you import the DemoDataModule) add your service provider:
1616
_ e.g. `DemoDataModule.forRoot([{ provide: DemoUserGeneratorService, useClass: DemoUserGeneratorService }])`
1717
_ When the DemoDataModule is loaded your generator is then also triggered.
18-
1. Change your `config.json` and set `database.useTemporaryDatabase: true` to start the app with in demo mode
18+
1. Change your `config.json` and set `demo_mode: true` to start the app with in demo mode
1919
and get your data generated on startup.
2020

2121
## Creating realistic, random data

src/app/core/analytics/analytics.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import md5 from "md5";
1111
/**
1212
* Track usage analytics data and report it to a backend server like Matomo.
1313
*
14-
* This is automatically disabled if the config.json does not specify "usage_analytics" settings.
14+
* This is automatically disabled if the config doc does not specify "usage_analytics" settings.
1515
*/
1616
@Injectable({
1717
providedIn: "root",

src/app/core/app-settings.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/app/core/database/pouch-database.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { PerformanceAnalysisLogging } from "../../utils/performance-analysis-log
2323
import { Injectable } from "@angular/core";
2424
import { firstValueFrom, Observable, Subject } from "rxjs";
2525
import { filter } from "rxjs/operators";
26-
import { AppSettings } from "../app-settings";
2726
import { HttpStatusCode } from "@angular/common/http";
27+
import { environment } from "../../../environments/environment";
2828

2929
/**
3030
* Wrapper for a PouchDB instance to decouple the code from
@@ -104,7 +104,7 @@ export class PouchDatabase extends Database {
104104
* @param fetch a overwrite for the default fetch handler
105105
*/
106106
initRemoteDB(
107-
dbName = `${AppSettings.DB_PROXY_PREFIX}/${AppSettings.DB_NAME}`,
107+
dbName = `${environment.DB_PROXY_PREFIX}/${environment.DB_NAME}`,
108108
fetch = this.defaultFetch,
109109
): PouchDatabase {
110110
const options = {
@@ -123,7 +123,7 @@ export class PouchDatabase extends Database {
123123
}
124124

125125
const remoteUrl =
126-
AppSettings.DB_PROXY_PREFIX + url.split(AppSettings.DB_PROXY_PREFIX)[1];
126+
environment.DB_PROXY_PREFIX + url.split(environment.DB_PROXY_PREFIX)[1];
127127
return PouchDB.fetch(remoteUrl, opts);
128128
}
129129

src/app/core/database/sync.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Injectable } from "@angular/core";
22
import { Database } from "./database";
33
import { PouchDatabase } from "./pouch-database";
44
import { Logging } from "../logging/logging.service";
5-
import { AppSettings } from "../app-settings";
65
import { HttpStatusCode } from "@angular/common/http";
76
import PouchDB from "pouchdb-browser";
87
import { SyncState } from "../session/session-states/sync-state.enum";
@@ -12,6 +11,7 @@ import { KeycloakAuthService } from "../session/auth/keycloak/keycloak-auth.serv
1211
import { Config } from "../config/config";
1312
import { Entity } from "../entity/model/entity";
1413
import { from, of } from "rxjs";
14+
import { environment } from "../../../environments/environment";
1515

1616
/**
1717
* This service initializes the remote DB and manages the sync between the local and remote DB.
@@ -71,7 +71,7 @@ export class SyncService {
7171
*/
7272
private initDatabases() {
7373
this.remoteDatabase.initRemoteDB(
74-
`${AppSettings.DB_PROXY_PREFIX}/${AppSettings.DB_NAME}`,
74+
`${environment.DB_PROXY_PREFIX}/${environment.DB_NAME}`,
7575
this.fetch.bind(this),
7676
);
7777
this.remoteDB = this.remoteDatabase.getPouchDB();
@@ -88,7 +88,7 @@ export class SyncService {
8888
}
8989

9090
const remoteUrl =
91-
AppSettings.DB_PROXY_PREFIX + url.split(AppSettings.DB_PROXY_PREFIX)[1];
91+
environment.DB_PROXY_PREFIX + url.split(environment.DB_PROXY_PREFIX)[1];
9292
const initialRes = await this.sendRequest(remoteUrl, opts);
9393

9494
// retry login if request failed with unauthorized

src/app/core/demo-data/demo-data-initializer.service.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { SessionInfo, SessionSubject } from "../session/auth/session-info";
1111
import { LocalAuthService } from "../session/auth/local/local-auth.service";
1212
import { SessionManagerService } from "../session/session-service/session-manager.service";
1313
import { PouchDatabase } from "../database/pouch-database";
14-
import { AppSettings } from "../app-settings";
1514
import { Database } from "../database/database";
1615
import { LoginState } from "../session/session-states/login-state.enum";
1716

@@ -36,8 +35,8 @@ describe("DemoDataInitializerService", () => {
3635

3736
beforeEach(() => {
3837
environment.session_type = SessionType.mock;
39-
demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
40-
adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${AppSettings.DB_NAME}`;
38+
demoUserDBName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${environment.DB_NAME}`;
39+
adminDBName = `${DemoUserGeneratorService.ADMIN_USERNAME}-${environment.DB_NAME}`;
4140
mockDemoDataService = jasmine.createSpyObj(["publishDemoData"]);
4241
mockDemoDataService.publishDemoData.and.resolveTo();
4342
mockDialog = jasmine.createSpyObj(["open"]);

src/app/core/demo-data/demo-data-initializer.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Database } from "../database/database";
1111
import { PouchDatabase } from "../database/pouch-database";
1212
import { environment } from "../../../environments/environment";
1313
import { LoginState } from "../session/session-states/login-state.enum";
14-
import { AppSettings } from "../app-settings";
1514
import { LoginStateSubject, SessionType } from "../session/session-type";
1615
import memory from "pouchdb-adapter-memory";
1716
import PouchDB from "pouchdb-browser";
@@ -87,7 +86,7 @@ export class DemoDataInitializerService {
8786
}
8887

8988
private async syncWithDemoUserDB() {
90-
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${AppSettings.DB_NAME}`;
89+
const dbName = `${DemoUserGeneratorService.DEFAULT_USERNAME}-${environment.DB_NAME}`;
9190
let demoUserDB: PouchDB.Database;
9291
if (environment.session_type === SessionType.mock) {
9392
PouchDB.plugin(memory);

src/app/core/session/session-service/session-manager.service.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { SyncService } from "../../database/sync.service";
3131
import { KeycloakAuthService } from "../auth/keycloak/keycloak-auth.service";
3232
import { Database } from "../../database/database";
3333
import { Router } from "@angular/router";
34-
import { AppSettings } from "../../app-settings";
3534
import { NAVIGATOR_TOKEN } from "../../../utils/di-tokens";
3635
import { CurrentUserSubject } from "../current-user-subject";
3736
import { EntityMapperService } from "../../entity/entity-mapper/entity-mapper.service";
@@ -48,8 +47,8 @@ describe("SessionManagerService", () => {
4847
let mockKeycloak: jasmine.SpyObj<KeycloakAuthService>;
4948
let mockNavigator: { onLine: boolean };
5049
let dbUser: SessionInfo;
51-
const userDBName = `${TEST_USER}-${AppSettings.DB_NAME}`;
52-
const deprecatedDBName = AppSettings.DB_NAME;
50+
const userDBName = `${TEST_USER}-${environment.DB_NAME}`;
51+
const deprecatedDBName = environment.DB_NAME;
5352
let initInMemorySpy: jasmine.Spy;
5453
let initIndexedSpy: jasmine.Spy;
5554

@@ -242,11 +241,11 @@ describe("SessionManagerService", () => {
242241
await service.remoteLogin();
243242

244243
expect(initInMemorySpy).toHaveBeenCalledWith(
245-
TEST_USER + "-" + AppSettings.DB_NAME,
244+
TEST_USER + "-" + environment.DB_NAME,
246245
);
247246
});
248247

249-
it("should create the database according to the session type in the AppSettings", async () => {
248+
it("should create the database according to the session type in the environment", async () => {
250249
async function testDatabaseCreation(
251250
sessionType: SessionType,
252251
expectedDB: "inMemory" | "indexed",

src/app/core/session/session-service/session-manager.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { LoginState } from "../session-states/login-state.enum";
2424
import { Router } from "@angular/router";
2525
import { KeycloakAuthService } from "../auth/keycloak/keycloak-auth.service";
2626
import { LocalAuthService } from "../auth/local/local-auth.service";
27-
import { AppSettings } from "../../app-settings";
2827
import { PouchDatabase } from "../../database/pouch-database";
2928
import { environment } from "../../../../environments/environment";
3029
import { Database } from "../../database/database";
@@ -174,7 +173,7 @@ export class SessionManagerService {
174173
}
175174

176175
private async initializeDatabaseForCurrentUser(user: SessionInfo) {
177-
const userDBName = `${user.name}-${AppSettings.DB_NAME}`;
176+
const userDBName = `${user.name}-${environment.DB_NAME}`;
178177
// Work on a temporary database before initializing the real one
179178
const tmpDB = new PouchDatabase();
180179
this.initDatabase(userDBName, tmpDB);
@@ -184,13 +183,13 @@ export class SessionManagerService {
184183
return;
185184
}
186185

187-
this.initDatabase(AppSettings.DB_NAME, tmpDB);
186+
this.initDatabase(environment.DB_NAME, tmpDB);
188187
const dbFallback = window.localStorage.getItem(this.DEPRECATED_DB_KEY);
189188
const dbAvailable = !dbFallback || dbFallback === user.name;
190189
if (dbAvailable && !(await tmpDB.isEmpty())) {
191190
// Old database is available and can be used by the current user
192191
window.localStorage.setItem(this.DEPRECATED_DB_KEY, user.name);
193-
this.initDatabase(AppSettings.DB_NAME);
192+
this.initDatabase(environment.DB_NAME);
194193
return;
195194
}
196195

0 commit comments

Comments
 (0)