|
|
@ -3,7 +3,6 @@ import type { BaseType } from 'nocodb-sdk'; |
|
|
|
import User from '~/models/User'; |
|
|
|
import User from '~/models/User'; |
|
|
|
import Base from '~/models/Base'; |
|
|
|
import Base from '~/models/Base'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
CacheDelDirection, |
|
|
|
|
|
|
|
// CacheDelDirection,
|
|
|
|
// CacheDelDirection,
|
|
|
|
CacheGetType, |
|
|
|
CacheGetType, |
|
|
|
CacheScope, |
|
|
|
CacheScope, |
|
|
@ -67,27 +66,37 @@ export default class BaseUser { |
|
|
|
`${CacheScope.BASE_USER}:${baseId}:${userId}`, |
|
|
|
`${CacheScope.BASE_USER}:${baseId}:${userId}`, |
|
|
|
CacheGetType.TYPE_OBJECT, |
|
|
|
CacheGetType.TYPE_OBJECT, |
|
|
|
)); |
|
|
|
)); |
|
|
|
if (!baseUser) { |
|
|
|
if (!baseUser || !baseUser.roles) { |
|
|
|
baseUser = await ncMeta.metaGet2(null, null, MetaTable.PROJECT_USERS, { |
|
|
|
const queryBuilder = ncMeta |
|
|
|
fk_user_id: userId, |
|
|
|
.knex(MetaTable.USERS) |
|
|
|
base_id: baseId, |
|
|
|
.select( |
|
|
|
|
|
|
|
`${MetaTable.USERS}.id`, |
|
|
|
|
|
|
|
`${MetaTable.USERS}.email`, |
|
|
|
|
|
|
|
`${MetaTable.USERS}.display_name`, |
|
|
|
|
|
|
|
`${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 () { |
|
|
|
|
|
|
|
this.on( |
|
|
|
|
|
|
|
`${MetaTable.PROJECT_USERS}.fk_user_id`, |
|
|
|
|
|
|
|
'=', |
|
|
|
|
|
|
|
`${MetaTable.USERS}.id`, |
|
|
|
|
|
|
|
).andOn( |
|
|
|
|
|
|
|
`${MetaTable.PROJECT_USERS}.base_id`, |
|
|
|
|
|
|
|
'=', |
|
|
|
|
|
|
|
ncMeta.knex.raw('?', [baseId]), |
|
|
|
|
|
|
|
); |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (baseUser) { |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
id, |
|
|
|
|
|
|
|
email, |
|
|
|
|
|
|
|
invite_token, |
|
|
|
|
|
|
|
roles: main_roles, |
|
|
|
|
|
|
|
} = await User.get(userId, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseUser = { |
|
|
|
|
|
|
|
...baseUser, |
|
|
|
|
|
|
|
id, |
|
|
|
|
|
|
|
email, |
|
|
|
|
|
|
|
invite_token, |
|
|
|
|
|
|
|
main_roles, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queryBuilder.where(`${MetaTable.USERS}.id`, userId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseUser = await queryBuilder.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (baseUser) { |
|
|
|
await NocoCache.set( |
|
|
|
await NocoCache.set( |
|
|
|
`${CacheScope.BASE_USER}:${baseId}:${userId}`, |
|
|
|
`${CacheScope.BASE_USER}:${baseId}:${userId}`, |
|
|
|
baseUser, |
|
|
|
baseUser, |
|
|
@ -100,13 +109,9 @@ export default class BaseUser { |
|
|
|
public static async getUsersList( |
|
|
|
public static async getUsersList( |
|
|
|
{ |
|
|
|
{ |
|
|
|
base_id, |
|
|
|
base_id, |
|
|
|
limit = 25, |
|
|
|
|
|
|
|
offset = 0, |
|
|
|
|
|
|
|
query, |
|
|
|
query, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
base_id: string; |
|
|
|
base_id: string; |
|
|
|
limit?: number; |
|
|
|
|
|
|
|
offset?: number; |
|
|
|
|
|
|
|
query?: string; |
|
|
|
query?: string; |
|
|
|
}, |
|
|
|
}, |
|
|
|
ncMeta = Noco.ncMeta, |
|
|
|
ncMeta = Noco.ncMeta, |
|
|
@ -120,6 +125,7 @@ export default class BaseUser { |
|
|
|
.select( |
|
|
|
.select( |
|
|
|
`${MetaTable.USERS}.id`, |
|
|
|
`${MetaTable.USERS}.id`, |
|
|
|
`${MetaTable.USERS}.email`, |
|
|
|
`${MetaTable.USERS}.email`, |
|
|
|
|
|
|
|
`${MetaTable.USERS}.display_name`, |
|
|
|
`${MetaTable.USERS}.invite_token`, |
|
|
|
`${MetaTable.USERS}.invite_token`, |
|
|
|
`${MetaTable.USERS}.roles as main_roles`, |
|
|
|
`${MetaTable.USERS}.roles as main_roles`, |
|
|
|
`${MetaTable.USERS}.created_at as created_at`, |
|
|
|
`${MetaTable.USERS}.created_at as created_at`, |
|
|
@ -127,10 +133,6 @@ export default class BaseUser { |
|
|
|
`${MetaTable.PROJECT_USERS}.roles as roles`, |
|
|
|
`${MetaTable.PROJECT_USERS}.roles as roles`, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (limit) { |
|
|
|
|
|
|
|
queryBuilder.offset(offset).limit(limit); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (query) { |
|
|
|
if (query) { |
|
|
|
queryBuilder.where('email', 'like', `%${query.toLowerCase?.()}%`); |
|
|
|
queryBuilder.where('email', 'like', `%${query.toLowerCase?.()}%`); |
|
|
|
} |
|
|
|
} |
|
|
@ -259,12 +261,9 @@ export default class BaseUser { |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// delete cache
|
|
|
|
// delete list cache to refresh list
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.del(`${CacheScope.BASE_USER}:${baseId}:${userId}`); |
|
|
|
CacheScope.BASE_USER, |
|
|
|
await NocoCache.del(`${CacheScope.BASE_USER}:${baseId}:list`); |
|
|
|
`${CacheScope.BASE_USER}:${baseId}:${userId}`, |
|
|
|
|
|
|
|
CacheDelDirection.CHILD_TO_PARENT, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response; |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|