Browse Source

feat: password protected shared form view

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/644/head
Pranav C 3 years ago
parent
commit
91a1d5f316
  1. 6
      packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue
  2. 4
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue
  3. 3
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue
  4. 4
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue
  5. 4
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue
  6. 26
      packages/nc-gui/components/project/spreadsheet/public/xcForm.vue
  7. 31
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  8. 2
      packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts

6
packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue

@ -18,6 +18,7 @@
:required="required" :required="required"
:is-public="isPublic" :is-public="isPublic"
:metas="metas" :metas="metas"
:password="password"
v-on="$listeners" v-on="$listeners"
/> />
<many-to-many-cell <many-to-many-cell
@ -38,6 +39,7 @@
:is-locked="isLocked" :is-locked="isLocked"
:required="required" :required="required"
:metas="metas" :metas="metas"
:password="password"
v-on="$listeners" v-on="$listeners"
/> />
<belongs-to-cell <belongs-to-cell
@ -58,6 +60,7 @@
:breadcrumbs="breadcrumbs" :breadcrumbs="breadcrumbs"
:is-locked="isLocked" :is-locked="isLocked"
:metas="metas" :metas="metas"
:password="password"
v-on="$listeners" v-on="$listeners"
/> />
<lookup-cell <lookup-cell
@ -138,7 +141,8 @@ export default {
isLocked: Boolean, isLocked: Boolean,
required: Boolean, required: Boolean,
isPublic: Boolean, isPublic: Boolean,
metas: Object metas: Object,
password: String
}, },
computed: { computed: {
hm() { hm() {

4
packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue

@ -37,6 +37,7 @@
:query-params="parentQueryParams" :query-params="parentQueryParams"
:is-public="isPublic" :is-public="isPublic"
:tn="bt && bt.rtn" :tn="bt && bt.rtn"
:password="password"
@add-new-record="insertAndMapNewParentRecord" @add-new-record="insertAndMapNewParentRecord"
@add="addChildToParent" @add="addChildToParent"
/> />
@ -128,7 +129,8 @@ export default {
isNew: Boolean, isNew: Boolean,
disabledColumns: Object, disabledColumns: Object,
isPublic: Boolean, isPublic: Boolean,
metas: Object metas: Object,
password: String
}, },
data: () => ({ data: () => ({
newRecordModal: false, newRecordModal: false,

3
packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue

@ -109,7 +109,8 @@ export default {
mm: [Object, Function], mm: [Object, Function],
parentId: [String, Number], parentId: [String, Number],
parentMeta: [Object], parentMeta: [Object],
isPublic: Boolean isPublic: Boolean,
password: String
}, },
data: () => ({ data: () => ({
data: null, data: null,

4
packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue

@ -57,6 +57,7 @@
where: isNew ? null :`~not(${childForeignKey},eq,${parentId})~or(${childForeignKey},is,null)`, where: isNew ? null :`~not(${childForeignKey},eq,${parentId})~or(${childForeignKey},is,null)`,
}" }"
:is-public="isPublic" :is-public="isPublic"
:password="password"
@add-new-record="insertAndAddNewChildRecord" @add-new-record="insertAndAddNewChildRecord"
@add="addChildToParent" @add="addChildToParent"
/> />
@ -172,7 +173,8 @@ export default {
isForm: Boolean, isForm: Boolean,
required: Boolean, required: Boolean,
isPublic: Boolean, isPublic: Boolean,
metas: Object metas: Object,
password: String
}, },
data: () => ({ data: () => ({
newRecordModal: false, newRecordModal: false,

4
packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue

@ -49,6 +49,7 @@
:parent-id="row && row[parentPrimaryKey]" :parent-id="row && row[parentPrimaryKey]"
:is-public="isPublic" :is-public="isPublic"
:query-params="childQueryParams" :query-params="childQueryParams"
:password="password"
@add-new-record="insertAndAddNewChildRecord" @add-new-record="insertAndAddNewChildRecord"
@add="addChildToParent" @add="addChildToParent"
/> />
@ -152,7 +153,8 @@ export default {
isForm: Boolean, isForm: Boolean,
required: Boolean, required: Boolean,
isPublic: Boolean, isPublic: Boolean,
metas: Object metas: Object,
password: String
}, },
data: () => ({ data: () => ({
isNewChild: false, isNewChild: false,

26
packages/nc-gui/components/project/spreadsheet/public/xcForm.vue

@ -119,6 +119,7 @@
:hint="localParams.fields[col.alias].description" :hint="localParams.fields[col.alias].description"
:required="localParams.fields[col.alias].description" :required="localParams.fields[col.alias].description"
:metas="metas" :metas="metas"
:password="password"
@update:localState="state => $set(virtual,col._cn, state)" @update:localState="state => $set(virtual,col._cn, state)"
@updateCol="updateCol" @updateCol="updateCol"
/> />
@ -197,6 +198,28 @@
</v-col> </v-col>
</template> </template>
</v-row> </v-row>
<v-dialog v-model="showPasswordModal" width="400">
<v-card width="400" class="backgroundColor">
<v-container fluid>
<v-text-field
v-model="password"
dense
type="password"
solo
flat
hint="Enter the password"
persistent-hint
/>
<div class="text-center">
<v-btn small color="primary" @click="loadMetaData(); showPasswordModal =false">
Unlock
</v-btn>
</div>
</v-container>
</v-card>
</v-dialog>
</v-container> </v-container>
</template> </template>
@ -219,6 +242,7 @@ export default {
return { return {
active: null, active: null,
loading: false, loading: false,
showPasswordModal: false,
submitting: false, submitting: false,
submitted: false, submitted: false,
client: null, client: null,
@ -321,7 +345,7 @@ export default {
} catch (e) { } catch (e) {
if (e.message === 'Not found') { if (e.message === 'Not found') {
this.notFound = true this.notFound = true
} else { } else if (e.message === 'Invalid password') {
this.showPasswordModal = true this.showPasswordModal = true
} }
} }

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

@ -44,18 +44,19 @@ const NOCO_RELEASE = 'NOCO_RELEASE';
export default class NcMetaMgr { export default class NcMetaMgr {
public projectConfigs = {}; public projectConfigs = {};
public readonly pluginMgr: NcPluginMgr; public readonly pluginMgr: NcPluginMgr;
public twilioInstance: Twilio; public twilioInstance: Twilio;
protected app: Noco; protected app: Noco;
protected config: NcConfig; protected config: NcConfig;
protected listener: (data) => Promise<any>; protected listener: (data) => Promise<any>;
protected xcMeta: NcMetaIO; protected xcMeta: NcMetaIO;
protected projectMgr: any; protected projectMgr: any;
// @ts-ignore // @ts-ignore
protected isEe = false; protected isEe = false;
protected readonly INVALID_PASSWORD_ERROR = 'Invalid password';
constructor(app: Noco, config: NcConfig, xcMeta: NcMetaIO) { constructor(app: Noco, config: NcConfig, xcMeta: NcMetaIO) {
this.app = app; this.app = app;
@ -3452,6 +3453,14 @@ export default class NcMetaMgr {
throw new Error('Not found'); throw new Error('Not found');
} }
if (
viewMeta &&
viewMeta.password &&
viewMeta.password !== args.args.password
) {
throw new Error(this.INVALID_PASSWORD_ERROR);
}
const tn = args.args?.tn; const tn = args.args?.tn;
// @ts-ignore // @ts-ignore
@ -3504,6 +3513,18 @@ export default class NcMetaMgr {
}) })
.first(); .first();
if (!viewMeta) {
throw new Error('Not found');
}
if (
viewMeta &&
viewMeta.password &&
viewMeta.password !== args.args.password
) {
throw new Error(this.INVALID_PASSWORD_ERROR);
}
const queryParams = JSON.parse(viewMeta.query_params); const queryParams = JSON.parse(viewMeta.query_params);
// const meta = JSON.parse(viewMeta.meta); // const meta = JSON.parse(viewMeta.meta);
@ -3548,6 +3569,14 @@ export default class NcMetaMgr {
throw new Error('Not found'); throw new Error('Not found');
} }
if (
viewMeta &&
viewMeta.password &&
viewMeta.password !== args.args.password
) {
throw new Error(this.INVALID_PASSWORD_ERROR);
}
// todo : filter out columns of related table // todo : filter out columns of related table
try { try {
const apiBuilder = this.app?.projectBuilders const apiBuilder = this.app?.projectBuilders

2
packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts

@ -127,7 +127,7 @@ export default class NcMetaMgrEE extends NcMetaMgr {
viewMeta.password && viewMeta.password &&
viewMeta.password !== args.args.password viewMeta.password !== args.args.password
) { ) {
throw new Error('Invalid password'); throw new Error(this.INVALID_PASSWORD_ERROR);
} }
const apiBuilder = this.app?.projectBuilders const apiBuilder = this.app?.projectBuilders

Loading…
Cancel
Save