From 15933af44342a5a611539e24cd8dfebef29dd24b Mon Sep 17 00:00:00 2001 From: Pranav C Balan Date: Thu, 17 Jun 2021 20:38:01 +0530 Subject: [PATCH] fix: Add project name and correct role in invite related #287 Signed-off-by: Pranav C Balan --- .../nc-gui/components/auth/userManagement.vue | 19 +++++++++++++++---- .../nocodb/src/lib/noco/rest/RestAuthCtrl.ts | 18 ++++++++++-------- .../lib/noco/rest/ui/emailTemplates/invite.ts | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/nc-gui/components/auth/userManagement.vue b/packages/nc-gui/components/auth/userManagement.vue index ed7630c549..191b5f7679 100644 --- a/packages/nc-gui/components/auth/userManagement.vue +++ b/packages/nc-gui/components/auth/userManagement.vue @@ -536,9 +536,14 @@ export default { }, async rensendInvite(id) { try { - await this.$axios.post('/admin/resendInvite/' + id, null, { + await this.$axios.post('/admin/resendInvite/' + id, { + projectName: this.$store.getters['project/GtrProjectName'], + }, { headers: { 'xc-auth': this.$store.state.users.token + }, + params: { + project_id: this.$route.params.project_id } }); this.$toast.success('Invite email sent successfully').goAway(3000); @@ -620,7 +625,11 @@ export default { }, async inviteUser(email) { try { - await this.$axios.post('/admin', {email, project_id: this.$route.params.project_id}, { + await this.$axios.post('/admin', { + email, + project_id: this.$route.params.project_id, + projectName: this.$store.getters['project/GtrProjectName'] + }, { headers: { 'xc-auth': this.$store.state.users.token } @@ -646,7 +655,8 @@ export default { await this.$axios.put('/admin/' + this.selectedUser.id, { roles: this.selectedUser.roles, email: this.selectedUser.email, - project_id: this.$route.params.project_id + project_id: this.$route.params.project_id, + projectName: this.$store.getters['project/GtrProjectName'] }, { headers: { 'xc-auth': this.$store.state.users.token @@ -655,7 +665,8 @@ export default { } else { data = await this.$axios.post('/admin', { ...this.selectedUser, - project_id: this.$route.params.project_id + project_id: this.$route.params.project_id, + projectName: this.$store.getters['project/GtrProjectName'] }, { headers: { 'xc-auth': this.$store.state.users.token diff --git a/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts b/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts index 557f4757c0..7c6a018425 100644 --- a/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts +++ b/packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts @@ -541,12 +541,13 @@ export default class RestAuthCtrl { res.json({ token: jwt.sign({ - email: user.email, - firstname: user.firstname, - lastname: user.lastname, - id: user.id, - roles: user.roles - }, this.config.auth.jwt.secret, this.config.auth.jwt.options) + email: user.email, + firstname: user.firstname, + lastname: user.lastname, + id: user.id, + roles: user.roles + }, this.config.auth.jwt.secret, + this.config.auth.jwt.options) } as any); } catch (e) { console.log(e); @@ -1168,6 +1169,7 @@ export default class RestAuthCtrl { return next(new Error(`User with id '${req.params.id}' not found`)); } + req.body.roles = user.roles; const invite_token = uuidv4(); await this.users.update({ @@ -1197,13 +1199,13 @@ export default class RestAuthCtrl { const template = (await import('./ui/emailTemplates/invite')).default; if (this.emailClient) { - await this.emailClient.mailSend({ to: email, subject: "Verify email", html: ejs.render(template, { signupLink: `${req.ncSiteUrl}${this.config?.dashboardPath}#/user/authentication/signup/${token}`, - projectName: req.body.projectName, + projectName: req.body?.projectName, + roles: (req.body?.roles || '').split(',').map(r => r.replace(/^./, m => m.toUpperCase())).join(', '), adminEmail: req.session?.passport?.user?.email }) }) diff --git a/packages/nocodb/src/lib/noco/rest/ui/emailTemplates/invite.ts b/packages/nocodb/src/lib/noco/rest/ui/emailTemplates/invite.ts index 00bebdfe10..3a4b5a3ead 100644 --- a/packages/nocodb/src/lib/noco/rest/ui/emailTemplates/invite.ts +++ b/packages/nocodb/src/lib/noco/rest/ui/emailTemplates/invite.ts @@ -132,7 +132,7 @@ export default `

Hi,

- I invited you to be an Admin of the NocoDB project <%- projectName %>". + I invited you to be "<%- roles -%>" of the NocoDB project "<%- projectName %>". Click the button below to to accept my invitation.