Browse Source

fix: include full version data or base users in cache

pull/7904/head
Pranav C 8 months ago
parent
commit
2ad17f1e86
  1. 34
      packages/nocodb/src/models/BaseUser.ts
  2. 1
      packages/nocodb/src/models/User.ts

34
packages/nocodb/src/models/BaseUser.ts

@ -163,6 +163,15 @@ 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)
@ -170,15 +179,11 @@ export default class BaseUser {
`${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 () {
@ -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;
}

1
packages/nocodb/src/models/User.ts

@ -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) {

Loading…
Cancel
Save