Skip to content

Commit

Permalink
119602: Make AccessibilitySettings cookie expiration configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
AAwouters committed Nov 6, 2024
1 parent 82fd953 commit 37455a8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,8 @@ liveRegion:
messageTimeOutDurationMs: 30000
# The visibility of the live region. Setting this to true is only useful for debugging purposes.
isVisible: false

# Configuration for storing accessibility settings, used by the AccessibilitySettingsService
accessibility:
# The duration in days after which the accessibility settings cookie expires
cookieExpirationDuration: 7
11 changes: 11 additions & 0 deletions src/app/accessibility/accessibility-settings.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Config } from '../../config/config.interface';

/**
* Configuration interface used by the AccessibilitySettingsService
*/
export class AccessibilitySettingsConfig implements Config {
/**
* The duration in days after which the accessibility settings cookie expires
*/
cookieExpirationDuration: number;
}
8 changes: 2 additions & 6 deletions src/app/accessibility/accessibility-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EPerson } from '../core/eperson/models/eperson.model';
import { EPersonDataService } from '../core/eperson/eperson-data.service';
import { getFirstCompletedRemoteData } from '../core/shared/operators';
import cloneDeep from 'lodash/cloneDeep';
import { environment } from '../../environments/environment';

/**
* Name of the cookie used to store the settings locally
Expand All @@ -19,11 +20,6 @@ export const ACCESSIBILITY_COOKIE = 'dsAccessibilityCookie';
*/
export const ACCESSIBILITY_SETTINGS_METADATA_KEY = 'dspace.accessibility.settings';

/**
* The duration in days after which the accessibility settings cookie expires
*/
export const ACCESSIBILITY_SETTINGS_COOKIE_STORAGE_DURATION = 7;

/**
* Enum containing all possible accessibility settings.
* When adding new settings, the {@link AccessibilitySettingsService#getInputType} method and the i18n keys for the
Expand Down Expand Up @@ -208,7 +204,7 @@ export class AccessibilitySettingsService {
*/
setSettingsInCookie(settings: AccessibilitySettings) {
if (isNotEmpty(settings)) {
this.cookieService.set(ACCESSIBILITY_COOKIE, settings, { expires: ACCESSIBILITY_SETTINGS_COOKIE_STORAGE_DURATION });
this.cookieService.set(ACCESSIBILITY_COOKIE, settings, { expires: environment.accessibility.cookieExpirationDuration });
} else {
this.cookieService.remove(ACCESSIBILITY_COOKIE);
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/app-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MarkdownConfig } from './markdown-config.interface';
import { FilterVocabularyConfig } from './filter-vocabulary-config';
import { DiscoverySortConfig } from './discovery-sort.config';
import { LiveRegionConfig } from '../app/shared/live-region/live-region.config';
import { AccessibilitySettingsConfig } from '../app/accessibility/accessibility-settings.config';

interface AppConfig extends Config {
ui: UIServerConfig;
Expand Down Expand Up @@ -50,6 +51,7 @@ interface AppConfig extends Config {
vocabularies: FilterVocabularyConfig[];
comcolSelectionSort: DiscoverySortConfig;
liveRegion: LiveRegionConfig;
accessibility: AccessibilitySettingsConfig;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/config/default-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { MarkdownConfig } from './markdown-config.interface';
import { FilterVocabularyConfig } from './filter-vocabulary-config';
import { DiscoverySortConfig } from './discovery-sort.config';
import { LiveRegionConfig } from '../app/shared/live-region/live-region.config';
import { AccessibilitySettingsConfig } from '../app/accessibility/accessibility-settings.config';

export class DefaultAppConfig implements AppConfig {
production = false;
Expand Down Expand Up @@ -439,4 +440,9 @@ export class DefaultAppConfig implements AppConfig {
messageTimeOutDurationMs: 30000,
isVisible: false,
};

// Accessibility settings configuration, used by the AccessibilitySettingsService
accessibility: AccessibilitySettingsConfig = {
cookieExpirationDuration: 7,
};
}
4 changes: 4 additions & 0 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,8 @@ export const environment: BuildConfig = {
messageTimeOutDurationMs: 30000,
isVisible: false,
},

accessibility: {
cookieExpirationDuration: 7,
},
};

0 comments on commit 37455a8

Please sign in to comment.