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:
@@ -58,10 +58,17 @@ export function getSessionProfiles(session: SessionObj): UserProfile[] {
|
||||
* found specific to that org.
|
||||
*
|
||||
*/
|
||||
export function getSessionUser(session: SessionObj, org: string): SessionUserObj|null {
|
||||
export function getSessionUser(session: SessionObj, org: string,
|
||||
userSelector: string): SessionUserObj|null {
|
||||
if (!session.users) { return null; }
|
||||
if (!session.users.length) { return null; }
|
||||
|
||||
if (userSelector) {
|
||||
for (const user of session.users) {
|
||||
if (user.profile?.email.toLowerCase() === userSelector.toLowerCase()) { return user; }
|
||||
}
|
||||
}
|
||||
|
||||
if (session.orgToUser && session.orgToUser[org] !== undefined &&
|
||||
session.users.length > session.orgToUser[org]) {
|
||||
return session.users[session.orgToUser[org]] || null;
|
||||
@@ -109,7 +116,8 @@ export class ScopedSession {
|
||||
*/
|
||||
constructor(private _sessionId: string,
|
||||
private _sessionStore: SessionStore,
|
||||
private _org: string) {
|
||||
private _org: string,
|
||||
private _userSelector: string) {
|
||||
// Assume we need to skip cache in a hosted environment. GRIST_HOST is always set there.
|
||||
// TODO: find a cleaner way to configure this flag.
|
||||
this._live = Boolean(process.env.GRIST_HOST || process.env.GRIST_HOSTED);
|
||||
@@ -122,7 +130,7 @@ export class ScopedSession {
|
||||
*/
|
||||
public async getScopedSession(prev?: SessionObj): Promise<SessionUserObj> {
|
||||
const session = prev || await this._getSession();
|
||||
return getSessionUser(session, this._org) || {};
|
||||
return getSessionUser(session, this._org, this._userSelector) || {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user