Browse Source

feat: public user registration

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/636/head
Pranav C 3 years ago
parent
commit
de6fabbae3
  1. 23
      packages/nc-gui/pages/projects/index.vue
  2. 23
      packages/nocodb/src/lib/noco/meta/NcMetaIOImpl.ts
  3. 10
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  4. 9
      packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts
  5. 5
      packages/nocodb/src/lib/noco/rest/RestAuthCtrlEE.ts
  6. 3
      packages/nocodb/src/lib/utils/projectAcl.ts

23
packages/nc-gui/pages/projects/index.vue

@ -235,11 +235,13 @@
x-small
class="mr-2"
:color="
props.item.status === 'started'
? 'green'
: props.item.status === 'stopped'
? 'orange'
: 'orange'
!props.item.allowed ? 'blue' :(
props.item.status === 'started'
? 'green'
: props.item.status === 'stopped'
? 'orange'
: 'orange'
)
"
>
mdi-moon-full
@ -266,13 +268,15 @@
}}
</x-icon>
<span class="title font-weight-regular">{{
<span
class="title font-weight-regular"
>{{
props.item.title
}}</span>
</td>
<td>
<div
v-if="_isUIAllowed('projectActions',true)"
v-if="props.item.allowed && _isUIAllowed('projectActions',true)"
:class="{
'action-icons': !(
projectStatusUpdating &&
@ -999,6 +1003,11 @@ export default {
this.loaded = true
},
projectRouteHandler(project) {
if (!project.allowed) {
this.$toast.info(`Contact following owner email to get project access : ${project.owner}`).goAway(5000)
return
}
if (project.status !== 'started') {
this.$toast
.info(

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

@ -350,10 +350,27 @@ export default class NcMetaIOImpl extends NcMetaIO {
}
public async userProjectList(userId: any): Promise<any[]> {
return (await this.knexConnection('nc_projects')
.innerJoin('nc_projects_users', 'nc_projects_users.project_id', 'nc_projects.id')
.select('nc_projects.*')
.where(`nc_projects_users.user_id`, userId)).map(p => {
.leftJoin(this.knexConnection('nc_projects_users')
.where(`nc_projects_users.user_id`, userId).as('user'), 'user.project_id', 'nc_projects.id')
.select('nc_projects.*')
.select('user.user_id')
//(SELECT `xc_users`.`email`
// FROM `xc_users`
// INNER JOIN `nc_projects_users`
// ON `nc_projects_users`.`user_id` =
// `xc_users`.`id` and `nc_projects_users`.project_id=`nc_projects`.id where `nc_projects_users`.`roles` like '%owner%' limit 1)
.select(this.knexConnection('xc_users')
.select('xc_users.email')
.innerJoin('nc_projects_users', 'nc_projects_users.user_id', '=', 'xc_users.id')
.where('nc_projects_users.roles', 'like', '%owner%')
.first()
.as('owner')
)
).map(p => {
p.allowed = p.user_id === userId;
p.config = CryptoJS.AES.decrypt(p.config, this.config?.auth?.jwt?.secret).toString(CryptoJS.enc.Utf8)
return p;
});

10
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -144,10 +144,12 @@ export default class NcMetaMgr {
// auth to admin
if (this.config.auth) {
if (this.config.auth.jwt) {
if (!(req?.session?.passport?.user?.roles?.creator || req?.session?.passport?.user?.roles?.editor
|| req?.session?.passport?.user?.roles?.viewer
|| req?.session?.passport?.user?.roles?.commenter
|| req?.session?.passport?.user?.roles?.user
const roles = req?.session?.passport?.user?.roles;
if (!(roles?.creator || roles?.editor
|| roles?.viewer
|| roles?.commenter
|| roles?.user
|| roles?.user_new
)) {
return res.status(401).json({
msg: 'Unauthorized access : xc-auth does not have admin permission'

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

@ -751,13 +751,16 @@ export default class RestAuthCtrl {
} else {
const roles = 'user';
let roles = 'user';
if (!(await this.users.first())) {
// roles = 'owner,creator,editor'
} else {
// todo : opening up signup for timebeing
return next(new Error('Not allowed to signup, contact super admin.'));
if (process.env.NC_INVITE_ONLY_SIGNUP) {
return next(new Error('Not allowed to signup, contact super admin.'));
} else {
roles = 'user_new';
}
}
await this.users.insert({

5
packages/nocodb/src/lib/noco/rest/RestAuthCtrlEE.ts

@ -38,6 +38,11 @@ export default class RestAuthCtrlEE extends RestAuthCtrl {
// add user to project if user already exist
const user = await this.users.where({email}).first();
if (user) {
await this.users.update({
roles: 'user'
}).where({roles: 'user_new', email});
if (!await this.xcMeta.isUserHaveAccessToProject(req.body.project_id, user.id)) {
await this.xcMeta.projectAddUser(req.body.project_id, user.id, 'editor');
}

3
packages/nocodb/src/lib/utils/projectAcl.ts

@ -209,6 +209,9 @@ export default {
'indexList': true,
'list': true,
},
user_new: {
projectList: true,
},
user: {
projectList: true,
testConnection: true,

Loading…
Cancel
Save