Browse Source

Merge pull request #1697 from nocodb/fix/ltar-bugs

Fix - LinkToAnotherRecord related bug fixes
pull/1700/head
Raju Udava 3 years ago committed by GitHub
parent
commit
8c24cf2fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue
  2. 27
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue
  3. 18
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue
  4. 20
      packages/nc-gui/plugins/tele.js
  5. 12
      packages/nc-gui/store/users.js
  6. 42
      packages/nocodb-sdk/src/lib/Api.ts
  7. 14
      packages/nocodb/package-lock.json
  8. 4
      packages/nocodb/package.json
  9. 15
      packages/nocodb/src/lib/noco/meta/api/index.ts
  10. 3
      packages/nocodb/src/lib/utils/projectAcl.ts
  11. 208
      scripts/sdk/swagger.json

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

@ -281,7 +281,7 @@ export default {
const id = this.meta.columns.filter(c => c.pk).map(c => this.row[c.title]).join('___')
// todo: audit
await this.$api.dbTableRow.nestedDelete(
await this.$api.dbTableRow.nestedRemove(
'noco',
this.projectName,
this.meta.title,

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

@ -342,11 +342,13 @@ export default {
return
}
const id = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___')
await this.$api.data.nestedDelete(
this.meta.id,
await this.$api.dbTableRow.nestedRemove(
'noco',
this.projectName,
this.meta.title,
this.parentId,
this.column.id,
'hm',
RelationTypes.HAS_MANY,
this.column.title,
id
)
@ -440,15 +442,18 @@ export default {
// eslint-disable-next-line no-cond-assign
while (child = this.localState.pop()) {
if (row) {
// todo: use common method
const pid = this.meta.columns.filter(c => c.pk).map(c => row[c.title]).join('___')
const id = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___')
const title = this.childForeignKey
await this.childApi.update(id, {
[title]: parseIfInteger(pid)
}, {
[title]: child[this.childForeignKey]
})
await this.$api.dbTableRow.nestedAdd(
'noco',
this.projectName,
this.meta.title,
pid,
'hm',
this.column.title,
id
)
} else {
await this.addChildToParent(child)
}

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

@ -318,7 +318,7 @@ export default {
const cid = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___')
const pid = this.meta.columns.filter(c => c.pk).map(c => this.row[c.title]).join('___')
await this.$api.dbTableRow.nestedDelete(
await this.$api.dbTableRow.nestedRemove(
'noco',
this.projectName,
this.meta.title,
@ -461,16 +461,18 @@ export default {
// eslint-disable-next-line no-cond-assign
while (child = this.localState.pop()) {
if (row) {
// todo: use common method
const cid = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___')
const pid = this.meta.columns.filter(c => c.pk).map(c => row[c.title]).join('___')
const vcidCol = this.assocMeta.columns.find(c => c.id === this.column.colOptions.fk_mm_parent_column_id).title
const vpidCol = this.assocMeta.columns.find(c => c.id === this.column.colOptions.fk_mm_child_column_id).title
await this.assocApi.insert({
[vcidCol]: parseIfInteger(cid),
[vpidCol]: parseIfInteger(pid)
})
await this.$api.dbTableRow.nestedAdd(
'noco',
this.projectName,
this.meta.title,
pid,
'mm',
this.column.title,
cid
)
} else {
await this.addChildToParent(child)
}

20
packages/nc-gui/plugins/tele.js

@ -23,7 +23,8 @@ export default function({
socket.disconnect()
socket = null
})
} catch { }
} catch {
}
}
app.router.onReady(() => {
@ -32,13 +33,11 @@ export default function({
return
}
socket.emit('page', {
id: store.state.users.user && store.state.users.user.id,
path: to.matched[0].path + (to.query && to.query.type ? `?type=${to.query.type}` : '')
})
})
if (socket) {
socket.emit('page', {
id: store.state.users.user && store.state.users.user.id,
path: route.matched[0].path + (route.query && route.query.type ? `?type=${route.query.type}` : '')
})
}
@ -49,9 +48,8 @@ export default function({
if (socket) {
socket.emit('event', {
event: evt,
id: store.state.users.user && store.state.users.user.id,
...(data || {}),
$current_url: gatPath(app)
path: gatPath(app)
})
}
}
@ -61,14 +59,14 @@ export default function({
function getListener(binding) {
return function(e) {
if (!socket) { return }
const cat = window.location.hash.replace(/\d+\/(?=dashboard)/, '')
if (!socket) {
return
}
const event = binding.value && binding.value[0]
const data = binding.value && binding.value[1]
const extra = binding.value && binding.value.slice(2)
tele.emit(event,
{
cat,
data,
extra
})
@ -87,14 +85,16 @@ export default function({
store.watch(state => state.project.projectInfo && state.project.projectInfo.teleEnabled && state.users.token, (token) => {
if (token) {
init(token).then(() => {})
init(token).then(() => {
})
} else if (socket) {
socket.disconnect()
socket = null
}
})
if (store.state.project.projectInfo && store.state.project.projectInfo.teleEnabled && store.state.users.token) {
init(store.state.users.token).then(() => {})
init(store.state.users.token).then(() => {
})
}
}

12
packages/nc-gui/store/users.js

@ -153,7 +153,7 @@ export const actions = {
setInterval(async() => {
if (getters.GtrUser) {
try {
const res = await this.$api.auth.me() // this.$axios.get('/user/me')
const res = await this.$api.auth.me()
if (res === null || !res.email) {
commit('MutSetUser', null)
} else {
@ -239,7 +239,6 @@ export const actions = {
// console.log('in action signin');
let err = null
try {
const userPromise = await this.$api.auth.signin(data)
commit('MutSetToken', userPromise.token)
@ -272,7 +271,7 @@ export const actions = {
async ActGetUserDetails({ commit, state }) {
try {
const user = await this.$api.auth.me({ // await this.$axios.get('/user/me', {
const user = await this.$api.auth.me({}, {
headers: {
'xc-auth': state.token
}
@ -285,11 +284,10 @@ export const actions = {
async ActGetProjectUserDetails({ commit, state }, projectId) {
try {
const user = await this.$api.auth.me({ // '/user/me?project_id=' + projectId, {
const user = await this.$api.auth.me({ project_id: projectId }, {
headers: {
'xc-auth': state.token
},
query: { project_id: projectId }
}
})
commit('MutProjectRole', user && user.roles)
} catch (e) {
@ -299,7 +297,7 @@ export const actions = {
async ActGetBaseUserDetails({ commit, state }, sharedBaseId) {
try {
try {
const user = await this.$api.auth.me({ // '/user/me', {
const user = await this.$api.auth.me({}, {
headers: {
'xc-shared-base-id': sharedBaseId
}

42
packages/nocodb-sdk/src/lib/Api.ts

@ -620,6 +620,15 @@ export type ColumnReqType =
}
| { uidt?: string; formula_raw?: string; formula?: string; title?: string };
export interface UserInfoType {
id?: string;
email?: string;
email_verified?: string;
firstname?: string;
lastname?: string;
roles?: any;
}
import axios, { AxiosInstance, AxiosRequestConfig, ResponseType } from 'axios';
export type QueryParamsType = Record<string | number, any>;
@ -798,7 +807,7 @@ export class Api<
* @summary Signup
* @request POST:/api/v1/db/auth/user/signup
* @response `200` `{ token?: string }` OK
* @response `400` `void` Bad Request
* @response `400` `{ msg?: string }` Bad Request
* @response `401` `void` Unauthorized
* @response `403` `void` Forbidden
*/
@ -806,7 +815,7 @@ export class Api<
data: { email?: string; password?: string },
params: RequestParams = {}
) =>
this.request<{ token?: string }, void>({
this.request<{ token?: string }, { msg?: string } | void>({
path: `/api/v1/db/auth/user/signup`,
method: 'POST',
body: data,
@ -822,12 +831,13 @@ export class Api<
* @summary Signin
* @request POST:/api/v1/db/auth/user/signin
* @response `200` `{ token?: string }` OK
* @response `400` `{ msg?: string }` Bad Request
*/
signin: (
data: { email: string; password: string },
params: RequestParams = {}
) =>
this.request<{ token?: string }, any>({
this.request<{ token?: string }, { msg?: string }>({
path: `/api/v1/db/auth/user/signin`,
method: 'POST',
body: data,
@ -843,12 +853,13 @@ export class Api<
* @name Me
* @summary User Info
* @request GET:/api/v1/db/auth/user/me
* @response `200` `UserType` OK
* @response `200` `UserInfoType` OK
*/
me: (params: RequestParams = {}) =>
this.request<UserType, any>({
me: (query?: { project_id?: string }, params: RequestParams = {}) =>
this.request<UserInfoType, any>({
path: `/api/v1/db/auth/user/me`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
@ -861,9 +872,10 @@ export class Api<
* @summary Password Forgot
* @request POST:/api/v1/db/auth/password/forgot
* @response `200` `void` OK
* @response `401` `void` Unauthorized
*/
passwordForgot: (data: { email?: string }, params: RequestParams = {}) =>
this.request<void, any>({
this.request<void, void>({
path: `/api/v1/db/auth/password/forgot`,
method: 'POST',
body: data,
@ -878,21 +890,19 @@ export class Api<
* @name PasswordChange
* @summary Password Change
* @request POST:/api/v1/db/auth/password/change
* @response `200` `void` OK
* @response `200` `{ msg?: string }` OK
* @response `400` `{ msg?: string }` Bad request
*/
passwordChange: (
data: {
currentPassword?: string;
newPassword?: string;
verifyPassword?: string;
},
data: { currentPassword?: string; newPassword?: string },
params: RequestParams = {}
) =>
this.request<void, any>({
this.request<{ msg?: string }, { msg?: string }>({
path: `/api/v1/db/auth/password/change`,
method: 'POST',
body: data,
type: ContentType.Json,
format: 'json',
...params,
}),
@ -2466,11 +2476,11 @@ export class Api<
* No description
*
* @tags DB table row
* @name NestedDelete
* @name NestedRemove
* @request DELETE:/api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}/{relationType}/{columnName}/{refRowId}
* @response `200` `any` OK
*/
nestedDelete: (
nestedRemove: (
orgs: string,
projectName: string,
tableName: string,

14
packages/nocodb/package-lock.json generated

@ -68,7 +68,7 @@
"mysql2": "^2.2.5",
"nanoid": "^3.1.20",
"nc-common": "0.0.6",
"nc-help": "^0.2.31",
"nc-help": "^0.2.44",
"nc-lib-gui": "0.84.15",
"nc-plugin": "^0.1.1",
"ncp": "^2.0.0",
@ -16034,9 +16034,9 @@
}
},
"node_modules/nc-help": {
"version": "0.2.42",
"resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.42.tgz",
"integrity": "sha512-qRQ9ijK3K5HfEp4LUJekk/EerNAa4YgM+jRtNLL1RMv+4IPAMO6NsXvdxNOW6h3robdY+xcWuaNqekXqGn1FXA==",
"version": "0.2.44",
"resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.44.tgz",
"integrity": "sha512-AAcMIh2Nhzm7iFQSaTOu27W4KU5eOAbPrGQLND+VAmdQurXACuHMCN6y7IZR3cPZMM1H7GQ0JmxVYzZ+S49MzQ==",
"dependencies": {
"axios": "^0.21.1",
"boxen": "^4.2.0",
@ -37473,9 +37473,9 @@
"integrity": "sha512-3AryS9uwa5NfISLxMciUonrH7YfXp+nlahB9T7girXIsLQrmwX4MdnuKs32akduCOGpKmjTJSWmATULbuMkbfw=="
},
"nc-help": {
"version": "0.2.42",
"resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.42.tgz",
"integrity": "sha512-qRQ9ijK3K5HfEp4LUJekk/EerNAa4YgM+jRtNLL1RMv+4IPAMO6NsXvdxNOW6h3robdY+xcWuaNqekXqGn1FXA==",
"version": "0.2.44",
"resolved": "https://registry.npmjs.org/nc-help/-/nc-help-0.2.44.tgz",
"integrity": "sha512-AAcMIh2Nhzm7iFQSaTOu27W4KU5eOAbPrGQLND+VAmdQurXACuHMCN6y7IZR3cPZMM1H7GQ0JmxVYzZ+S49MzQ==",
"requires": {
"axios": "^0.21.1",
"boxen": "^4.2.0",

4
packages/nocodb/package.json

@ -67,7 +67,7 @@
"help:c": "ts-node ./help/a",
"watch:build": "nodemon -e ts,js -w ./src -x npm run build",
"watch:serve": "nodemon -e ts -w ./build -x npm run debug-local ",
"watch:run": "cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/docker --log-error --project tsconfig.json\"",
"watch:run": "cross-env NC_DISABLE_TELE1=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/docker --log-error --project tsconfig.json\"",
"watch:run:cypress": "cross-env EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/docker --log-error --project tsconfig.json\"",
"watch:run:mysql": "cross-env NC_DISABLE_TELE=true EE=true nodemon -e ts,js -w ./src -x \"ts-node src/example/dockerRunMysql --log-error --project tsconfig.json\"",
"run": "ts-node src/example/docker",
@ -150,7 +150,7 @@
"mysql2": "^2.2.5",
"nanoid": "^3.1.20",
"nc-common": "0.0.6",
"nc-help": "^0.2.31",
"nc-help": "^0.2.44",
"nc-lib-gui": "0.84.15",
"nc-plugin": "^0.1.1",
"ncp": "^2.0.0",

15
packages/nocodb/src/lib/noco/meta/api/index.ts

@ -44,6 +44,8 @@ import { Tele } from 'nc-help';
import { Server } from 'socket.io';
import passport from 'passport';
import crypto from 'crypto';
export default function(router: Router, server) {
initStrategies(router);
projectApis(router);
@ -106,11 +108,20 @@ export default function(router: Router, server) {
}
)(socket.handshake, {}, next);
}).on('connection', socket => {
const id = getHash(Tele.id + (socket?.handshake as any)?.user?.id);
socket.on('page', args => {
Tele.page(args);
Tele.page({ ...args, id });
});
socket.on('event', args => {
Tele.event(args);
Tele.event({ ...args, id });
});
});
}
function getHash(str) {
return crypto
.createHash('md5')
.update(str)
.digest('hex');
}

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

@ -139,8 +139,10 @@ export default {
columnList: true,
mmList: true,
hmList: true,
commentList: true,
commentRow: true,
projectInfoGet: true,
// data
dataList: true,
@ -184,6 +186,7 @@ export default {
// sort & filter
sortList: true,
projectInfoGet: true,
mmList: true,
hmList: true,

208
scripts/sdk/swagger.json

@ -26,12 +26,58 @@
"type": "string"
}
}
},
"examples": {
"Successful registration response": {
"value": {
"token": "string"
}
}
}
}
}
},
"400": {
"description": "Bad Request"
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
},
"examples": {
"Invalid email": {
"value": {
"msg": "Invalid email"
}
},
"Invalid invite url": {
"value": {
"msg": "Invalid invite url"
}
},
"Expired invite url": {
"value": {
"msg": "Expired invite url, Please contact super admin to get a new invite url"
}
},
"User already exist": {
"value": {
"msg": "User already exist"
}
},
"Invite only signup": {
"value": {
"msg": "Not allowed to signup, contact super admin"
}
}
}
}
}
},
"401": {
"description": "Unauthorized"
@ -68,6 +114,21 @@
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
}
}
}
}
},
"tags": [
@ -90,6 +151,14 @@
"email",
"password"
]
},
"examples": {
"example-1": {
"value": {
"email": "user@nocodb.com",
"password": "Password"
}
}
}
}
}
@ -109,7 +178,21 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
"$ref": "#/components/schemas/UserInfo"
},
"examples": {
"example-1": {
"value": {
"id": "string",
"email": "string",
"email_verified": "string",
"firstname": "string",
"lastname": "string",
"roles": {
"editor": true
}
}
}
}
}
}
@ -118,7 +201,17 @@
"tags": [
"Auth"
],
"description": "Returns authenticated user info"
"description": "Returns authenticated user info",
"parameters": [
{
"schema": {
"type": "string"
},
"in": "query",
"name": "project_id",
"description": "Pass project id to get project specific roles along with user info"
}
]
}
},
"/api/v1/db/auth/password/forgot": {
@ -128,6 +221,9 @@
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized"
}
},
"description": "Emails user with a reset url.",
@ -146,7 +242,8 @@
}
}
}
}
},
"description": "Pass registered user email id in request body"
}
},
"parameters": []
@ -157,7 +254,53 @@
"operationId": "auth-password-change",
"responses": {
"200": {
"description": "OK"
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
},
"examples": {
"Success response": {
"value": {
"msg": "Password updated successfully"
}
}
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"msg": {
"type": "string"
}
}
},
"examples": {
"Missing params": {
"value": {
"msg": "Missing new/old password"
}
},
"Wrong password": {
"value": {
"msg": "Current password is wrong"
}
}
}
}
}
}
},
"description": "Change password of authenticated user with a new one.",
@ -175,14 +318,20 @@
},
"newPassword": {
"type": "string"
},
"verifyPassword": {
"type": "string"
}
}
},
"examples": {
"example-1": {
"value": {
"currentPassword": "string",
"newPassword": "string"
}
}
}
}
}
},
"description": "Old password need to be passed along with new password for changing password."
}
},
"parameters": []
@ -292,7 +441,6 @@
},
"parameters": []
},
"/api/v1/db/meta/projects/{projectId}/users": {
"get": {
"summary": "Project Users",
@ -1522,8 +1670,7 @@
"get": {
"summary": "",
"operationId": "db-view-column-list",
"responses": {
},
"responses": {},
"tags": [
"DB View Column"
]
@ -2281,7 +2428,6 @@
}
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}": {
"parameters": [
{
@ -3104,7 +3250,8 @@
"name": "relationType",
"in": "path",
"required": true
},{
},
{
"schema": {
"type": "string"
},
@ -3245,7 +3392,7 @@
},
"delete": {
"summary": "",
"operationId": "db-table-row-nested-delete",
"operationId": "db-table-row-nested-remove",
"responses": {
"200": {
"description": "OK",
@ -3350,7 +3497,6 @@
]
}
},
"/api/v1/db/public/shared-view/{sharedViewUuid}/rows": {
"parameters": [
{
@ -3421,7 +3567,7 @@
"multipart/form-data": {
"schema": {
"type": "object",
"properties": { }
"properties": {}
}
}
}
@ -3707,7 +3853,6 @@
]
}
},
"/api/v1/db/meta/audits/comments": {
"parameters": [],
"get": {
@ -3945,7 +4090,6 @@
}
}
},
"/api/v1/db/meta/tables/{tableId}/hooks": {
"parameters": [
{
@ -4195,7 +4339,6 @@
]
}
},
"/api/v1/db/meta/plugins": {
"parameters": [],
"get": {
@ -4374,7 +4517,6 @@
]
}
},
"/api/v1/db/meta/connection/test": {
"parameters": [],
"post": {
@ -4480,7 +4622,6 @@
},
"parameters": []
},
"/api/v1/db/meta/projects/{projectId}/api-tokens": {
"get": {
"summary": "Your GET endpoint",
@ -4583,7 +4724,6 @@
}
]
},
"/api/v1/db/storage/upload": {
"post": {
"summary": "Attachment",
@ -7031,6 +7171,28 @@
],
"description": "",
"type": "object"
},
"UserInfo": {
"title": "UserInfo",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"email": {
"type": "string"
},
"email_verified": {
"type": "string"
},
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"roles": {}
}
}
},
"requestBodies": {

Loading…
Cancel
Save