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 x-small
class="mr-2" class="mr-2"
:color=" :color="
props.item.status === 'started' !props.item.allowed ? 'blue' :(
? 'green' props.item.status === 'started'
: props.item.status === 'stopped' ? 'green'
? 'orange' : props.item.status === 'stopped'
: 'orange' ? 'orange'
: 'orange'
)
" "
> >
mdi-moon-full mdi-moon-full
@ -266,13 +268,15 @@
}} }}
</x-icon> </x-icon>
<span class="title font-weight-regular">{{ <span
class="title font-weight-regular"
>{{
props.item.title props.item.title
}}</span> }}</span>
</td> </td>
<td> <td>
<div <div
v-if="_isUIAllowed('projectActions',true)" v-if="props.item.allowed && _isUIAllowed('projectActions',true)"
:class="{ :class="{
'action-icons': !( 'action-icons': !(
projectStatusUpdating && projectStatusUpdating &&
@ -999,6 +1003,11 @@ export default {
this.loaded = true this.loaded = true
}, },
projectRouteHandler(project) { 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') { if (project.status !== 'started') {
this.$toast this.$toast
.info( .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[]> { public async userProjectList(userId: any): Promise<any[]> {
return (await this.knexConnection('nc_projects') return (await this.knexConnection('nc_projects')
.innerJoin('nc_projects_users', 'nc_projects_users.project_id', 'nc_projects.id') .leftJoin(this.knexConnection('nc_projects_users')
.select('nc_projects.*') .where(`nc_projects_users.user_id`, userId).as('user'), 'user.project_id', 'nc_projects.id')
.where(`nc_projects_users.user_id`, userId)).map(p => { .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) p.config = CryptoJS.AES.decrypt(p.config, this.config?.auth?.jwt?.secret).toString(CryptoJS.enc.Utf8)
return p; return p;
}); });

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

@ -144,10 +144,12 @@ export default class NcMetaMgr {
// auth to admin // auth to admin
if (this.config.auth) { if (this.config.auth) {
if (this.config.auth.jwt) { if (this.config.auth.jwt) {
if (!(req?.session?.passport?.user?.roles?.creator || req?.session?.passport?.user?.roles?.editor const roles = req?.session?.passport?.user?.roles;
|| req?.session?.passport?.user?.roles?.viewer if (!(roles?.creator || roles?.editor
|| req?.session?.passport?.user?.roles?.commenter || roles?.viewer
|| req?.session?.passport?.user?.roles?.user || roles?.commenter
|| roles?.user
|| roles?.user_new
)) { )) {
return res.status(401).json({ return res.status(401).json({
msg: 'Unauthorized access : xc-auth does not have admin permission' 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 { } else {
const roles = 'user'; let roles = 'user';
if (!(await this.users.first())) { if (!(await this.users.first())) {
// roles = 'owner,creator,editor' // roles = 'owner,creator,editor'
} else { } else {
// todo : opening up signup for timebeing if (process.env.NC_INVITE_ONLY_SIGNUP) {
return next(new Error('Not allowed to signup, contact super admin.')); return next(new Error('Not allowed to signup, contact super admin.'));
} else {
roles = 'user_new';
}
} }
await this.users.insert({ 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 // add user to project if user already exist
const user = await this.users.where({email}).first(); const user = await this.users.where({email}).first();
if (user) { if (user) {
await this.users.update({
roles: 'user'
}).where({roles: 'user_new', email});
if (!await this.xcMeta.isUserHaveAccessToProject(req.body.project_id, user.id)) { if (!await this.xcMeta.isUserHaveAccessToProject(req.body.project_id, user.id)) {
await this.xcMeta.projectAddUser(req.body.project_id, user.id, 'editor'); 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, 'indexList': true,
'list': true, 'list': true,
}, },
user_new: {
projectList: true,
},
user: { user: {
projectList: true, projectList: true,
testConnection: true, testConnection: true,

Loading…
Cancel
Save