Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always store full version data of base-users in cache #7904

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 25 additions & 9 deletions packages/nocodb/src/models/BaseUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,27 @@ export default class BaseUser {
const cachedList = await NocoCache.getList(CacheScope.BASE_USER, [base_id]);
let { list: baseUsers } = cachedList;
const { isNoneList } = cachedList;

const fullVersionCols = [
'invite_token',
'main_roles',
'created_at',
'base_id',
'roles',
];

if (!isNoneList && !baseUsers.length) {
const queryBuilder = ncMeta
.knex(MetaTable.USERS)
.select(
`${MetaTable.USERS}.id`,
`${MetaTable.USERS}.email`,
`${MetaTable.USERS}.display_name`,
...(mode === 'full'
? [
`${MetaTable.USERS}.invite_token`,
`${MetaTable.USERS}.roles as main_roles`,
`${MetaTable.USERS}.created_at as created_at`,
`${MetaTable.PROJECT_USERS}.base_id`,
`${MetaTable.PROJECT_USERS}.roles as roles`,
]
: []),
`${MetaTable.USERS}.invite_token`,
`${MetaTable.USERS}.roles as main_roles`,
`${MetaTable.USERS}.created_at as created_at`,
`${MetaTable.PROJECT_USERS}.base_id`,
`${MetaTable.PROJECT_USERS}.roles as roles`,
);

queryBuilder.leftJoin(MetaTable.PROJECT_USERS, function () {
Expand Down Expand Up @@ -206,6 +211,17 @@ export default class BaseUser {
]);
}

if (mode === 'full') {
return baseUsers;
}

// remove full version props if viewer
for (const user of baseUsers) {
for (const prop of fullVersionCols) {
delete user[prop];
}
}

return baseUsers;
}

Expand Down
1 change: 1 addition & 0 deletions packages/nocodb/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export default class User implements UserType {
const user = await this.get(userId, ncMeta);
if (!user) NcError.badRequest('User not found');

// todo: skip base user cache delete based on flag
const bases = await BaseUser.getProjectsList(userId, {}, ncMeta);

for (const base of bases) {
Expand Down