Support user and team preferences (#4081)
* feat: support user preferences * feat: support team preferences * fix: update snapshots * feat: update last visited url by user * fix: update snapshots * fix: use path instead of complete url * fix: do not expose preferences to other users with the exception of admin * feat: support defaultDocumentStatus as a team preference * feat: allow edit even when collaborative editing is enabled * Revert "feat: allow edit even when collaborative editing is enabled" This reverts commit a22a02a406d01eb418dab32249b8b846bf77c59b. * Revert "feat: support defaultDocumentStatus as a team preference" This reverts commit 4928cffe5c682952b1e469a3e50a1a34d05dcc58. * fix: keep preference as a boolean
This commit is contained in:
@@ -54,6 +54,12 @@ export enum UserRole {
|
||||
Viewer = "viewer",
|
||||
}
|
||||
|
||||
export enum UserPreference {
|
||||
RememberLastPath = "rememberLastPath",
|
||||
}
|
||||
|
||||
export type UserPreferences = { [key in UserPreference]?: boolean };
|
||||
|
||||
@Scopes(() => ({
|
||||
withAuthentications: {
|
||||
include: [
|
||||
@@ -152,6 +158,10 @@ class User extends ParanoidModel {
|
||||
@Column(DataType.JSONB)
|
||||
flags: { [key in UserFlag]?: number } | null;
|
||||
|
||||
@AllowNull
|
||||
@Column(DataType.JSONB)
|
||||
preferences: UserPreferences | null;
|
||||
|
||||
@Default(env.DEFAULT_LANGUAGE)
|
||||
@IsIn([languages])
|
||||
@Column
|
||||
@@ -290,6 +300,35 @@ class User extends ParanoidModel {
|
||||
return this.flags;
|
||||
};
|
||||
|
||||
/**
|
||||
* Preferences set by the user that decide application behavior and ui.
|
||||
*
|
||||
* @param preference The user preference to set
|
||||
* @param value Sets the preference value
|
||||
* @returns The current user preferences
|
||||
*/
|
||||
public setPreference = (preference: UserPreference, value: boolean) => {
|
||||
if (!this.preferences) {
|
||||
this.preferences = {};
|
||||
}
|
||||
this.preferences[preference] = value;
|
||||
this.changed("preferences", true);
|
||||
|
||||
return this.preferences;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the passed preference value
|
||||
*
|
||||
* @param preference The user preference to retrieve
|
||||
* @returns The preference value if set, else undefined
|
||||
*/
|
||||
public getPreference = (preference: UserPreference) => {
|
||||
return !!this.preferences && this.preferences[preference]
|
||||
? this.preferences[preference]
|
||||
: undefined;
|
||||
};
|
||||
|
||||
collectionIds = async (options = {}) => {
|
||||
const collectionStubs = await Collection.scope({
|
||||
method: ["withMembership", this.id],
|
||||
@@ -575,7 +614,7 @@ class User extends ParanoidModel {
|
||||
|
||||
static getCounts = async function (teamId: string) {
|
||||
const countSql = `
|
||||
SELECT
|
||||
SELECT
|
||||
COUNT(CASE WHEN "suspendedAt" IS NOT NULL THEN 1 END) as "suspendedCount",
|
||||
COUNT(CASE WHEN "isAdmin" = true THEN 1 END) as "adminCount",
|
||||
COUNT(CASE WHEN "isViewer" = true THEN 1 END) as "viewerCount",
|
||||
|
||||
Reference in New Issue
Block a user