mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) revamp user attribute handling
Summary: This changes how user attributes are loaded. They are now loaded directly from sqlite, with per-session caching. Optimizations considered but not addressed yet are (1) adding indexes to user attribute tables and (2) swapping in a thinner sqlite wrapper. The main benefit of this diff is that changes to user attribute tables now work. Clients whose user attributes are not changed see no effect; clients whose user attributes have changed have their document reloaded. For the purposes of testing, the diff includes a tweak to GristWSConnection to be "sticky" to a specific user when reloading (and support machinery on the server side to honor that). Until now, if a GristWSConnection reloads, it uses whatever the current default user is in the cookie-based session, which can change. This was complicating a test where multiple users were accessing the same document via different clients with occasional document reloads. Code for updating when schema or rule changes happen is moved around but not improved in any meaningful way in this diff. Test Plan: existing tests pass; extended test Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2685
This commit is contained in:
@@ -50,6 +50,10 @@ export interface GristWSSettings {
|
||||
// Get an id associated with the client, null for "no id set yet".
|
||||
getClientId(assignmentId: string|null): string|null;
|
||||
|
||||
// Get selector for user, so if cookie auth allows multiple the correct one will be picked.
|
||||
// Selector is currently just the email address.
|
||||
getUserSelector(): string;
|
||||
|
||||
// Update the id associated with the client. Future calls to getClientId should return this.
|
||||
updateClientId(assignmentId: string|null, clentId: string): void;
|
||||
|
||||
@@ -74,6 +78,10 @@ export class GristWSSettingsBrowser implements GristWSSettings {
|
||||
public getClientId(assignmentId: string|null) {
|
||||
return window.sessionStorage.getItem(`clientId_${assignmentId}`) || null;
|
||||
}
|
||||
public getUserSelector(): string {
|
||||
// TODO: find/create a more official way to get the user.
|
||||
return (window as any).gristDocPageModel?.appModel.currentUser?.email || '';
|
||||
}
|
||||
public updateClientId(assignmentId: string|null, id: string) {
|
||||
window.sessionStorage.setItem(`clientId_${assignmentId}`, id);
|
||||
}
|
||||
@@ -335,6 +343,7 @@ export class GristWSConnection extends Disposable {
|
||||
url.searchParams.append('counter', this._clientCounter);
|
||||
url.searchParams.append('newClient', String(isReconnecting ? 0 : 1));
|
||||
url.searchParams.append('browserSettings', JSON.stringify({timezone}));
|
||||
url.searchParams.append('user', this._settings.getUserSelector());
|
||||
return url.href;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user