Browse Source

fix: add missing delete user logic

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/1168/head
Wing-Kam Wong 3 years ago
parent
commit
9517820c38
  1. 53
      packages/nc-gui/components/auth/userManagement.vue
  2. 5
      packages/nocodb/src/lib/noco/meta/NcMetaIO.ts
  3. 9
      packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts
  4. 18
      packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts

53
packages/nc-gui/components/auth/userManagement.vue

@ -155,23 +155,32 @@
>
mdi-pencil-outline
</x-icon>
<x-icon
v-if="!item.project_id"
tooltip="Add user to project"
color="primary"
small
@click="inviteUser(item.email)"
>
mdi-plus
</x-icon>
<span v-if="!item.project_id">
<x-icon
tooltip="Add user to project"
color="primary"
small
@click="inviteUser(item.email)"
>
mdi-plus
</x-icon>
<x-icon
tooltip="Delete user from NocoDB"
class="ml-2"
color="error"
small
@click.prevent.stop="deleteId = item.id; deleteItem = item.id;showConfirmDlg = true;deleteUserType='DELETE_FROM_NOCODB'"
>
mdi-delete-forever-outline
</x-icon>
</span>
<x-icon
v-else
tooltip="Remove user from project"
class="ml-2"
color="error"
small
@click.prevent.stop="deleteId = item.id; deleteItem = item.id;showConfirmDlg = true"
@click.prevent.stop="deleteId = item.id; deleteItem = item.id;showConfirmDlg = true;deleteUserType='DELETE_FROM_PROJECT'"
>
mdi-delete-outline
</x-icon>
@ -296,7 +305,7 @@
<dlg-label-submit-cancel
type="primary"
:actions-mtd="confirmDelete"
heading="Do you want to remove the user from project?"
:heading="dialogMessage"
:dialog-show="showConfirmDlg"
/>
@ -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 <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

5
packages/nocodb/src/lib/noco/meta/NcMetaIO.ts

@ -168,11 +168,15 @@ export default abstract class NcMetaIO {
roles: string
): Promise<any>;
// Remove user in project level
public abstract projectRemoveUser(
projectId: string,
userId: any
): Promise<any>;
// Remove user globally
public abstract removeXcUser(userId: any): Promise<any>;
public abstract projectStatusUpdate(
projectId: string,
status: string
@ -235,6 +239,7 @@ export { META_TABLES };
*
* @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

9
packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts

@ -573,6 +573,14 @@ export default class NcMetaIOImpl extends NcMetaIO {
.delete();
}
public removeXcUser(userId: any): Promise<any> {
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 <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

18
packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts

@ -1355,7 +1355,7 @@ export default class RestAuthCtrl {
protected async deleteAdmin(req, res, next): Promise<any> {
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 <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

Loading…
Cancel
Save