diff --git a/packages/nc-gui/components/auth/userManagement.vue b/packages/nc-gui/components/auth/userManagement.vue index 14429f2304..e692dfeaf8 100644 --- a/packages/nc-gui/components/auth/userManagement.vue +++ b/packages/nc-gui/components/auth/userManagement.vue @@ -155,23 +155,32 @@ > mdi-pencil-outline - - - mdi-plus - + + + mdi-plus + + + mdi-delete-forever-outline + + mdi-delete-outline @@ -296,7 +305,7 @@ @@ -497,7 +506,8 @@ export default { } ], userList: [], - roleDescriptions: {} + roleDescriptions: {}, + deleteUserType: '' // [DELETE_FROM_PROJECT, DELETE_FROM_NOCODB] }), computed: { roleNames() { @@ -530,6 +540,12 @@ export default { set(i) { this.selectedUser = this.users[i] } + }, + dialogMessage() { + let msg = 'Do you want to remove the user' + if (this.deleteUserType === 'DELETE_FROM_PROJECT') { msg += ' from Project' } else if (this.deleteUserType === 'DELETE_FROM_NOCODB') { msg += ' from NocoDB' } + msg += '?' + return msg } }, watch: { @@ -669,30 +685,30 @@ export default { console.log(e) } }, - async deleteUser(id) { + async deleteUser(id, type) { try { await this.$axios.delete('/admin/' + id, { params: { project_id: this.$route.params.project_id, - email: this.deleteItem.email + email: this.deleteItem.email, + type }, headers: { 'xc-auth': this.$store.state.users.token } }) - this.$toast.success('Successfully removed the user from project').goAway(3000) + this.$toast.success(`Successfully removed the user from ${type === 'DELETE_FROM_PROJECT' ? 'project' : 'NocoDB'}`).goAway(3000) await this.loadUsers() } catch (e) { this.$toast.error(e.response.data.msg).goAway(3000) } }, - async confirmDelete(hideDialog) { if (hideDialog) { this.showConfirmDlg = false return } - await this.deleteUser(this.deleteId) + await this.deleteUser(this.deleteId, this.deleteUserType) this.showConfirmDlg = false }, addUser() { @@ -832,6 +848,7 @@ export default { * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version * diff --git a/packages/nocodb/src/lib/noco/meta/NcMetaIO.ts b/packages/nocodb/src/lib/noco/meta/NcMetaIO.ts index 3d5d6534bc..3f132a6a72 100644 --- a/packages/nocodb/src/lib/noco/meta/NcMetaIO.ts +++ b/packages/nocodb/src/lib/noco/meta/NcMetaIO.ts @@ -168,11 +168,15 @@ export default abstract class NcMetaIO { roles: string ): Promise; + // Remove user in project level public abstract projectRemoveUser( projectId: string, userId: any ): Promise; + // Remove user globally + public abstract removeXcUser(userId: any): Promise; + public abstract projectStatusUpdate( projectId: string, status: string @@ -235,6 +239,7 @@ export { META_TABLES }; * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version * diff --git a/packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts b/packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts index 9276f515dd..83cd198ab0 100644 --- a/packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts +++ b/packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts @@ -573,6 +573,14 @@ export default class NcMetaIOImpl extends NcMetaIO { .delete(); } + public removeXcUser(userId: any): Promise { + return this.knexConnection('xc_users') + .where({ + id: userId + }) + .delete(); + } + get isRest(): boolean { return this.config?.envs?.[this.config.workingEnv]?.db?.some( db => db?.meta?.api?.type === 'rest' @@ -616,6 +624,7 @@ export default class NcMetaIOImpl extends NcMetaIO { * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version * diff --git a/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts b/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts index 645a9e2b7b..dccf6bee61 100644 --- a/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts +++ b/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts @@ -1355,7 +1355,7 @@ export default class RestAuthCtrl { protected async deleteAdmin(req, res, next): Promise { try { - const { project_id } = req.query; + const { project_id, type } = req.query; if (req.session?.passport?.user?.id === +req.params.id) { return next(new Error("Admin can't delete themselves!")); @@ -1372,11 +1372,16 @@ export default class RestAuthCtrl { ); } } - - XcCache.del(`${req?.query?.email}___${req?.req?.project_id}`); - - // await this.users.where('id', req.params.id).del(); - await this.xcMeta.projectRemoveUser(project_id, req.params.id); + if (type === 'DELETE_FROM_PROJECT') { + // remove user from Project + XcCache.del(`${req?.query?.email}___${req?.req?.project_id}`); + await this.xcMeta.projectRemoveUser(project_id, req.params.id); + } else if (type === 'DELETE_FROM_NOCODB') { + // remove user from NocoDB + await this.xcMeta.removeXcUser(req.params.id); + } else { + new Error('Invalid type is provided.'); + } } catch (e) { return next(e); } @@ -1748,6 +1753,7 @@ export default class RestAuthCtrl { * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version *