Skip to content

Commit

Permalink
Merge pull request #7904 from nocodb/nc-fix/7902-base-permission-cache
Browse files Browse the repository at this point in the history
fix: Always store full version data of base-users in cache
  • Loading branch information
pranavxc committed Mar 19, 2024
2 parents b2d13ee + 2ad17f1 commit 6b76127
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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

0 comments on commit 6b76127

Please sign in to comment.