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 mdi-pencil-outline
</x-icon> </x-icon>
<span v-if="!item.project_id">
<x-icon <x-icon
v-if="!item.project_id" tooltip="Add user to project"
tooltip="Add user to project" color="primary"
color="primary" small
small @click="inviteUser(item.email)"
@click="inviteUser(item.email)" >
> mdi-plus
mdi-plus </x-icon>
</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 <x-icon
v-else v-else
tooltip="Remove user from project" tooltip="Remove user from project"
class="ml-2" class="ml-2"
color="error" color="error"
small 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 mdi-delete-outline
</x-icon> </x-icon>
@ -296,7 +305,7 @@
<dlg-label-submit-cancel <dlg-label-submit-cancel
type="primary" type="primary"
:actions-mtd="confirmDelete" :actions-mtd="confirmDelete"
heading="Do you want to remove the user from project?" :heading="dialogMessage"
:dialog-show="showConfirmDlg" :dialog-show="showConfirmDlg"
/> />
@ -497,7 +506,8 @@ export default {
} }
], ],
userList: [], userList: [],
roleDescriptions: {} roleDescriptions: {},
deleteUserType: '' // [DELETE_FROM_PROJECT, DELETE_FROM_NOCODB]
}), }),
computed: { computed: {
roleNames() { roleNames() {
@ -530,6 +540,12 @@ export default {
set(i) { set(i) {
this.selectedUser = this.users[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: { watch: {
@ -669,30 +685,30 @@ export default {
console.log(e) console.log(e)
} }
}, },
async deleteUser(id) { async deleteUser(id, type) {
try { try {
await this.$axios.delete('/admin/' + id, { await this.$axios.delete('/admin/' + id, {
params: { params: {
project_id: this.$route.params.project_id, project_id: this.$route.params.project_id,
email: this.deleteItem.email email: this.deleteItem.email,
type
}, },
headers: { headers: {
'xc-auth': this.$store.state.users.token '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() await this.loadUsers()
} catch (e) { } catch (e) {
this.$toast.error(e.response.data.msg).goAway(3000) this.$toast.error(e.response.data.msg).goAway(3000)
} }
}, },
async confirmDelete(hideDialog) { async confirmDelete(hideDialog) {
if (hideDialog) { if (hideDialog) {
this.showConfirmDlg = false this.showConfirmDlg = false
return return
} }
await this.deleteUser(this.deleteId) await this.deleteUser(this.deleteId, this.deleteUserType)
this.showConfirmDlg = false this.showConfirmDlg = false
}, },
addUser() { addUser() {
@ -832,6 +848,7 @@ export default {
* *
* @author Naveen MR <oof1lab@gmail.com> * @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@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 * @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 roles: string
): Promise<any>; ): Promise<any>;
// Remove user in project level
public abstract projectRemoveUser( public abstract projectRemoveUser(
projectId: string, projectId: string,
userId: any userId: any
): Promise<any>; ): Promise<any>;
// Remove user globally
public abstract removeXcUser(userId: any): Promise<any>;
public abstract projectStatusUpdate( public abstract projectStatusUpdate(
projectId: string, projectId: string,
status: string status: string
@ -235,6 +239,7 @@ export { META_TABLES };
* *
* @author Naveen MR <oof1lab@gmail.com> * @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@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 * @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(); .delete();
} }
public removeXcUser(userId: any): Promise<any> {
return this.knexConnection('xc_users')
.where({
id: userId
})
.delete();
}
get isRest(): boolean { get isRest(): boolean {
return this.config?.envs?.[this.config.workingEnv]?.db?.some( return this.config?.envs?.[this.config.workingEnv]?.db?.some(
db => db?.meta?.api?.type === 'rest' db => db?.meta?.api?.type === 'rest'
@ -616,6 +624,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
* *
* @author Naveen MR <oof1lab@gmail.com> * @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@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 * @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> { protected async deleteAdmin(req, res, next): Promise<any> {
try { try {
const { project_id } = req.query; const { project_id, type } = req.query;
if (req.session?.passport?.user?.id === +req.params.id) { if (req.session?.passport?.user?.id === +req.params.id) {
return next(new Error("Admin can't delete themselves!")); return next(new Error("Admin can't delete themselves!"));
@ -1372,11 +1372,16 @@ export default class RestAuthCtrl {
); );
} }
} }
if (type === 'DELETE_FROM_PROJECT') {
XcCache.del(`${req?.query?.email}___${req?.req?.project_id}`); // remove user from Project
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);
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) { } catch (e) {
return next(e); return next(e);
} }
@ -1748,6 +1753,7 @@ export default class RestAuthCtrl {
* *
* @author Naveen MR <oof1lab@gmail.com> * @author Naveen MR <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@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 * @license GNU AGPL version 3 or any later version
* *

Loading…
Cancel
Save