Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
<section class="maintenance-overlay font-bold text-xl flex flex-column align-items-center justify-content-center">
<p>{{ 'maintenance.title' | translate }}</p>
<p>{{ 'maintenance.message' | translate }}</p>
<p>
{{ 'maintenance.details' | translate }}
<a href="https://status.cos.io/" target="_blank" rel="noopener noreferrer">https://status.cos.io/</a>
</p>
</section>
}
2 changes: 1 addition & 1 deletion src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.maintenance-overlay {
position: fixed;
inset: 0;
z-index: 2000;
z-index: 3100;
background: var(--white);
}
27 changes: 27 additions & 0 deletions src/app/core/services/maintenance-mode.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TestBed } from '@angular/core/testing';

import { BYPASS_ERROR_INTERCEPTOR } from '@core/interceptors/error-interceptor.tokens';
import { MaintenanceResponse } from '@core/models/maintenance-response.model';
import { ENVIRONMENT } from '@core/provider/environment.provider';

import { provideOSFCore, provideOSFHttp } from '@testing/osf.testing.provider';

Expand Down Expand Up @@ -116,4 +117,30 @@ describe('MaintenanceModeService', () => {
vi.advanceTimersByTime(pollIntervalMs);
httpMock.expectNone(apiUrl);
});

describe('when maintenance is forced by config', () => {
beforeEach(() => {
TestBed.inject(ENVIRONMENT).maintenance = true;
});

it('should activate on checkOnce without requesting /v2/', () => {
service.checkOnce();
httpMock.expectNone(apiUrl);
expect(service.isActive()).toBe(true);
});

it('should not start polling on activate', () => {
vi.useFakeTimers();
service.activate();
vi.advanceTimersByTime(pollIntervalMs);
httpMock.expectNone(apiUrl);
expect(service.isActive()).toBe(true);
});

it('should stay active on deactivate', () => {
service.checkOnce();
service.deactivate();
expect(service.isActive()).toBe(true);
});
});
});
15 changes: 14 additions & 1 deletion src/app/core/services/maintenance-mode.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ export class MaintenanceModeService implements OnDestroy {

readonly isActive = this._isActive.asReadonly();

private get isForcedByConfig(): boolean {
return this.environment.maintenance === true;
}

/**
* Check for maintenance mode upon application startup.
* If the application is in maintenance mode, activate the service and start polling for when maintenance mode ends.
*/
checkOnce(): void {
if (this.isForcedByConfig) {
this._isActive.set(true);
return;
}

this.checkMaintenanceStatus().subscribe((status) => {
if (status === MaintenanceStatus.Active) {
this.activate();
Expand All @@ -38,13 +47,17 @@ export class MaintenanceModeService implements OnDestroy {

activate(): void {
this._isActive.set(true);
if (this.pollingSubscription) {
if (this.isForcedByConfig || this.pollingSubscription) {
return;
}
this.startPolling();
}

deactivate(): void {
if (this.isForcedByConfig) {
return;
}

this._isActive.set(false);
this.stopPolling();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/models/environment.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export interface EnvironmentModel {
*/
googleFilePickerAppId: number;
throttleToken: string;
maintenance?: boolean;
}
3 changes: 2 additions & 1 deletion src/assets/config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"newRelicLoaderConfigTrustKey": "",
"newRelicLoaderConfigAgentID": "",
"newRelicLoaderConfigLicenseKey": "",
"newRelicLoaderConfigApplicationID": ""
"newRelicLoaderConfigApplicationID": "",
"maintenance": false
}
1 change: 1 addition & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2901,6 +2901,7 @@
}
},
"maintenance": {
"details": "For more details, please visit",
"message": "Please come back later.",
"title": "The OSF is currently down for scheduled maintenance."
},
Expand Down
Loading