|
|
@ -3,7 +3,12 @@ import { NcError } from '~/helpers/catchError'; |
|
|
|
import Noco from '~/Noco'; |
|
|
|
import Noco from '~/Noco'; |
|
|
|
import { extractProps } from '~/helpers/extractProps'; |
|
|
|
import { extractProps } from '~/helpers/extractProps'; |
|
|
|
import NocoCache from '~/cache/NocoCache'; |
|
|
|
import NocoCache from '~/cache/NocoCache'; |
|
|
|
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; |
|
|
|
import { |
|
|
|
|
|
|
|
CacheDelDirection, |
|
|
|
|
|
|
|
CacheGetType, |
|
|
|
|
|
|
|
CacheScope, |
|
|
|
|
|
|
|
MetaTable, |
|
|
|
|
|
|
|
} from '~/utils/globals'; |
|
|
|
import { BaseUser } from '~/models'; |
|
|
|
import { BaseUser } from '~/models'; |
|
|
|
import { sanitiseUserObj } from '~/utils'; |
|
|
|
import { sanitiseUserObj } from '~/utils'; |
|
|
|
|
|
|
|
|
|
|
@ -106,22 +111,12 @@ export default class User implements UserType { |
|
|
|
// delete the email-based cache to avoid unexpected behaviour since we can update email as well
|
|
|
|
// delete the email-based cache to avoid unexpected behaviour since we can update email as well
|
|
|
|
await NocoCache.del(`${CacheScope.USER}:${existingUser.email}`); |
|
|
|
await NocoCache.del(`${CacheScope.USER}:${existingUser.email}`); |
|
|
|
|
|
|
|
|
|
|
|
// get existing cache
|
|
|
|
await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id); |
|
|
|
const keys = [ |
|
|
|
|
|
|
|
// update user:<id>
|
|
|
|
|
|
|
|
`${CacheScope.USER}:${id}`, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
for (const key of keys) { |
|
|
|
|
|
|
|
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
|
|
|
|
if (o) { |
|
|
|
|
|
|
|
o = { ...o, ...updateObj }; |
|
|
|
|
|
|
|
// set cache
|
|
|
|
|
|
|
|
await NocoCache.set(key, o); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set meta
|
|
|
|
// clear all user related cache
|
|
|
|
return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id); |
|
|
|
await this.clearCache(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.get(id, ncMeta); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static async getByEmail(_email: string, ncMeta = Noco.ncMeta) { |
|
|
|
public static async getByEmail(_email: string, ncMeta = Noco.ncMeta) { |
|
|
@ -237,8 +232,7 @@ export default class User implements UserType { |
|
|
|
if (!user) NcError.badRequest('User not found'); |
|
|
|
if (!user) NcError.badRequest('User not found'); |
|
|
|
|
|
|
|
|
|
|
|
// clear all user related cache
|
|
|
|
// clear all user related cache
|
|
|
|
await NocoCache.del(`${CacheScope.USER}:${userId}`); |
|
|
|
await this.clearCache(userId); |
|
|
|
await NocoCache.del(`${CacheScope.USER}:${user.email}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await ncMeta.metaDelete(null, null, MetaTable.USERS, userId); |
|
|
|
return await ncMeta.metaDelete(null, null, MetaTable.USERS, userId); |
|
|
|
} |
|
|
|
} |
|
|
@ -278,4 +272,23 @@ export default class User implements UserType { |
|
|
|
base_roles: baseRoles ? baseRoles : null, |
|
|
|
base_roles: baseRoles ? baseRoles : null, |
|
|
|
} as any; |
|
|
|
} as any; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static async clearCache(userId: string) { |
|
|
|
|
|
|
|
const user = await this.get(userId); |
|
|
|
|
|
|
|
if (!user) NcError.badRequest('User not found'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const bases = await BaseUser.getProjectsList(userId, {}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const base of bases) { |
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
|
|
|
|
CacheScope.BASE_USER, |
|
|
|
|
|
|
|
`${CacheScope.BASE_USER}:${base.id}:list`, |
|
|
|
|
|
|
|
CacheDelDirection.PARENT_TO_CHILD, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear all user related cache
|
|
|
|
|
|
|
|
await NocoCache.del(`${CacheScope.USER}:${userId}`); |
|
|
|
|
|
|
|
await NocoCache.del(`${CacheScope.USER}:${user.email}`); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|