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

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

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

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

@ -109,7 +109,8 @@ export default {
mm: [Object, Function],
parentId: [String, Number],
parentMeta: [Object],
isPublic: Boolean
isPublic: Boolean,
password: String
},
data: () => ({
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)`,
}"
:is-public="isPublic"
:password="password"
@add-new-record="insertAndAddNewChildRecord"
@add="addChildToParent"
/>
@ -172,7 +173,8 @@ export default {
isForm: Boolean,
required: Boolean,
isPublic: Boolean,
metas: Object
metas: Object,
password: String
},
data: () => ({
newRecordModal: false,

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

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

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

@ -119,6 +119,7 @@
:hint="localParams.fields[col.alias].description"
:required="localParams.fields[col.alias].description"
:metas="metas"
:password="password"
@update:localState="state => $set(virtual,col._cn, state)"
@updateCol="updateCol"
/>
@ -197,6 +198,28 @@
</v-col>
</template>
</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>
</template>
@ -219,6 +242,7 @@ export default {
return {
active: null,
loading: false,
showPasswordModal: false,
submitting: false,
submitted: false,
client: null,
@ -321,7 +345,7 @@ export default {
} catch (e) {
if (e.message === 'Not found') {
this.notFound = true
} else {
} else if (e.message === 'Invalid password') {
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 {
public projectConfigs = {};
public readonly pluginMgr: NcPluginMgr;
public twilioInstance: Twilio;
protected app: Noco;
protected config: NcConfig;
protected listener: (data) => Promise<any>;
protected xcMeta: NcMetaIO;
protected projectMgr: any;
// @ts-ignore
protected isEe = false;
protected readonly INVALID_PASSWORD_ERROR = 'Invalid password';
constructor(app: Noco, config: NcConfig, xcMeta: NcMetaIO) {
this.app = app;
@ -3452,6 +3453,14 @@ export default class NcMetaMgr {
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;
// @ts-ignore
@ -3504,6 +3513,18 @@ export default class NcMetaMgr {
})
.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 meta = JSON.parse(viewMeta.meta);
@ -3548,6 +3569,14 @@ export default class NcMetaMgr {
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
try {
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 !== args.args.password
) {
throw new Error('Invalid password');
throw new Error(this.INVALID_PASSWORD_ERROR);
}
const apiBuilder = this.app?.projectBuilders

Loading…
Cancel
Save