diff --git a/packages/nc-gui/components/org-user/index.vue b/packages/nc-gui/components/org-user/index.vue index 39eb22be9a..80afe34ef6 100644 --- a/packages/nc-gui/components/org-user/index.vue +++ b/packages/nc-gui/components/org-user/index.vue @@ -1,70 +1,200 @@ diff --git a/packages/nc-gui/plugins/tele.ts b/packages/nc-gui/plugins/tele.ts index cd9c0b1ca1..4c21654c36 100644 --- a/packages/nc-gui/plugins/tele.ts +++ b/packages/nc-gui/plugins/tele.ts @@ -37,6 +37,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { socket.emit('page', { path: to.matched[0].path + (to.query && to.query.type ? `?type=${to.query.type}` : ''), + pid: route?.params?.projectId, }) }) @@ -48,6 +49,7 @@ export default defineNuxtPlugin(async (nuxtApp) => { event: evt, ...(data || {}), path: route?.matched?.[0]?.path, + pid: route?.params?.projectId, }) } }, diff --git a/packages/nocodb/src/lib/meta/api/orgUserApis.ts b/packages/nocodb/src/lib/meta/api/orgUserApis.ts index bd00e1005a..18dd4c08d9 100644 --- a/packages/nocodb/src/lib/meta/api/orgUserApis.ts +++ b/packages/nocodb/src/lib/meta/api/orgUserApis.ts @@ -22,7 +22,7 @@ async function userUpdate(req, res) { const user = await User.get(req.params.userId); if (user.roles.includes(OrgUserRoles.SUPER)) { - throw new Error('Cannot update super admin roles'); + NcError.badRequest('Cannot update super admin roles'); } res.json(await User.update(req.params.userId, updteBody)); @@ -32,7 +32,7 @@ async function userDelete(req, res) { const user = await User.get(req.params.userId); if (user.roles.includes(OrgUserRoles.SUPER)) { - throw new Error('Cannot delete super admin'); + NcError.badRequest('Cannot delete super admin'); } res.json(await User.delete(req.params.userId)); @@ -49,17 +49,17 @@ router.get( ncMetaAclMw(userList, 'userList', [OrgUserRoles.SUPER]) ); router.patch( - '/api/v1/db/meta/users/:userId', + '/api/v1/users/:userId', metaApiMetrics, ncMetaAclMw(userUpdate, 'userUpdate', [OrgUserRoles.SUPER]) ); router.delete( - '/api/v1/db/meta/users/:userId', + '/api/v1/users/:userId', metaApiMetrics, ncMetaAclMw(userAdd, 'userAdd', [OrgUserRoles.SUPER]) ); router.post( - '/api/v1/db/meta/users/:userId', + '/api/v1/users/:userId', metaApiMetrics, ncMetaAclMw(userDelete, 'userDelete', [OrgUserRoles.SUPER]) ); diff --git a/packages/nocodb/src/lib/models/User.ts b/packages/nocodb/src/lib/models/User.ts index 670dda2523..fcd5c8ac82 100644 --- a/packages/nocodb/src/lib/models/User.ts +++ b/packages/nocodb/src/lib/models/User.ts @@ -6,28 +6,28 @@ import { extractProps } from '../meta/helpers/extractProps'; import NocoCache from '../cache/NocoCache'; import { NcError } from '../meta/helpers/catchError'; export default class User implements UserType { - id: string; + id: string /** @format email */ - email: string; - - password?: string; - salt?: string; - firstname: string; - lastname: string; - username?: string; - refresh_token?: string; - invite_token?: string; - invite_token_expires?: number | Date; - reset_password_expires?: number | Date; - reset_password_token?: string; - email_verification_token?: string; - email_verified: boolean; - roles?: string; - token_version?: string; + email: string + + password?: string + salt?: string + firstname: string + lastname: string + username?: string + refresh_token?: string + invite_token?: string + invite_token_expires?: number | Date + reset_password_expires?: number | Date + reset_password_token?: string + email_verification_token?: string + email_verified: boolean + roles?: string + token_version?: string constructor(data: User) { - Object.assign(this, data); + Object.assign(this, data) } public static async insert(user: Partial, ncMeta = Noco.ncMeta) { @@ -48,22 +48,22 @@ export default class User implements UserType { 'email_verified', 'roles', 'token_version', - ]); + ]) if (insertObj.email) { - insertObj.email = insertObj.email.toLowerCase(); + insertObj.email = insertObj.email.toLowerCase() } const { id } = await ncMeta.metaInsert2( null, null, MetaTable.USERS, - insertObj - ); + insertObj, + ) - await NocoCache.del(CacheScope.INSTANCE_META); + await NocoCache.del(CacheScope.INSTANCE_META) - return this.get(id, ncMeta); + return this.get(id, ncMeta) } public static async update(id, user: Partial, ncMeta = Noco.ncMeta) { const updateObj = extractProps(user, [ @@ -82,13 +82,13 @@ export default class User implements UserType { 'email_verified', 'roles', 'token_version', - ]); + ]) if (updateObj.email) { - updateObj.email = updateObj.email.toLowerCase(); + updateObj.email = updateObj.email.toLowerCase() } else { // set email prop to avoid generation of invalid cache key - updateObj.email = (await this.get(id, ncMeta))?.email?.toLowerCase(); + updateObj.email = (await this.get(id, ncMeta))?.email?.toLowerCase() } // get existing cache const keys = [ @@ -96,43 +96,43 @@ export default class User implements UserType { `${CacheScope.USER}:${id}`, // update user: `${CacheScope.USER}:${user.email}`, - ]; + ] for (const key of keys) { - let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT) if (o) { - o = { ...o, ...updateObj }; + o = { ...o, ...updateObj } // set cache - await NocoCache.set(key, o); + await NocoCache.set(key, o) } } // as is unknown, delete user:___ in cache - await NocoCache.delAll(CacheScope.USER, `${user.email}___*`); + await NocoCache.delAll(CacheScope.USER, `${user.email}___*`) // set meta - return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id); + return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id) } public static async getByEmail(_email: string, ncMeta = Noco.ncMeta) { - const email = _email?.toLowerCase(); + const email = _email?.toLowerCase() let user = email && (await NocoCache.get( `${CacheScope.USER}:${email}`, - CacheGetType.TYPE_OBJECT - )); + CacheGetType.TYPE_OBJECT, + )) if (!user) { user = await ncMeta.metaGet2(null, null, MetaTable.USERS, { email, - }); - await NocoCache.set(`${CacheScope.USER}:${email}`, user); + }) + await NocoCache.set(`${CacheScope.USER}:${email}`, user) } - return user; + return user } static async isFirst(ncMeta = Noco.ncMeta) { - const isFirst = !(await NocoCache.getAll(`${CacheScope.USER}:*`))?.length; + const isFirst = !(await NocoCache.getAll(`${CacheScope.USER}:*`))?.length if (isFirst) - return !(await ncMeta.metaGet2(null, null, MetaTable.USERS, {})); - return false; + return !(await ncMeta.metaGet2(null, null, MetaTable.USERS, {})) + return false } public static async count( @@ -141,15 +141,15 @@ export default class User implements UserType { }: { query?: string; } = {}, - ncMeta = Noco.ncMeta + ncMeta = Noco.ncMeta, ): Promise { - const qb = ncMeta.knex(MetaTable.USERS); + const qb = ncMeta.knex(MetaTable.USERS) if (query) { - qb.where('email', 'like', `%${query.toLowerCase?.()}%`); + qb.where('email', 'like', `%${query.toLowerCase?.()}%`) } - return (await qb.count('id', { as: 'count' }).first()).count; + return (await qb.count('id', { as: 'count' }).first()).count } static async get(userId, ncMeta = Noco.ncMeta): Promise { @@ -157,20 +157,20 @@ export default class User implements UserType { userId && (await NocoCache.get( `${CacheScope.USER}:${userId}`, - CacheGetType.TYPE_OBJECT - )); + CacheGetType.TYPE_OBJECT, + )) if (!user) { - user = await ncMeta.metaGet2(null, null, MetaTable.USERS, userId); - await NocoCache.set(`${CacheScope.USER}:${userId}`, user); + user = await ncMeta.metaGet2(null, null, MetaTable.USERS, userId) + await NocoCache.set(`${CacheScope.USER}:${userId}`, user) } - return user; + return user } static async getByRefreshToken(refresh_token, ncMeta = Noco.ncMeta) { const user = await ncMeta.metaGet2(null, null, MetaTable.USERS, { refresh_token, - }); - return user; + }) + return user } public static async list( @@ -183,7 +183,7 @@ export default class User implements UserType { offset?: number | undefined; query?: string; } = {}, - ncMeta = Noco.ncMeta + ncMeta = Noco.ncMeta, ) { let queryBuilder = ncMeta.knex(MetaTable.USERS); @@ -214,7 +214,7 @@ export default class User implements UserType { .as('projectsCount') ); if (query) { - queryBuilder.where('email', 'like', `%${query.toLowerCase?.()}%`); + queryBuilder.where('email', 'like', `%${query.toLowerCase?.()}%`) } return queryBuilder; @@ -226,8 +226,4 @@ export default class User implements UserType { await NocoCache.del(`${CacheScope.USER}:${userId}`); await ncMeta.metaDelete(null, null, MetaTable.USERS, userId); } - - static async delete(_userId: string) { - NcError.notImplemented(); - } } diff --git a/scripts/sdk/swagger.json b/scripts/sdk/swagger.json index 7bed803086..09e6ce23a1 100644 --- a/scripts/sdk/swagger.json +++ b/scripts/sdk/swagger.json @@ -6407,8 +6407,7 @@ "format": "email" }, "roles": { - "type": "string", - "format": "email" + "type": "string" }, "date_of_birth": { "type": "string",