feat: Allow users to override team setting for seamless editing (#5772)

This commit is contained in:
Tom Moor
2023-09-04 19:19:43 -04:00
committed by GitHub
parent c376dc1011
commit 74860ed961
10 changed files with 97 additions and 61 deletions

View File

@@ -5,6 +5,7 @@ import { UserPreferenceDefaults } from "@shared/constants";
import {
NotificationEventDefaults,
NotificationEventType,
TeamPreference,
UserPreference,
UserPreferences,
UserRole,
@@ -85,6 +86,20 @@ class User extends ParanoidModel {
}
}
/**
* Returns whether this user is using a separate editing mode behind an "Edit"
* button rather than seamless always-editing.
*
* @returns True if editing mode is seamless (no button)
*/
@computed
get separateEditMode(): boolean {
return !this.getPreference(
UserPreference.SeamlessEdit,
this.store.rootStore.auth.team.getPreference(TeamPreference.SeamlessEdit)
);
}
/**
* Returns the current preference for the given notification event type taking
* into account the default system value.
@@ -130,8 +145,10 @@ class User extends ParanoidModel {
* @param key The UserPreference key to retrieve
* @returns The value
*/
getPreference(key: UserPreference): boolean {
return this.preferences?.[key] ?? UserPreferenceDefaults[key] ?? false;
getPreference(key: UserPreference, defaultValue = false): boolean {
return (
this.preferences?.[key] ?? UserPreferenceDefaults[key] ?? defaultValue
);
}
/**