Merge pull request #15163 from Budibase/cheeks-fixes
Prevent syncing row changes between users for views filtered by current user
This commit is contained in:
commit
640008dd97
|
@ -43,12 +43,11 @@
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
overflow-y: scroll !important;
|
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
.main {
|
.main {
|
||||||
overflow: auto;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -61,7 +61,7 @@ a {
|
||||||
height: 8px;
|
height: 8px;
|
||||||
}
|
}
|
||||||
::-webkit-scrollbar-track {
|
::-webkit-scrollbar-track {
|
||||||
background: var(--spectrum-alias-background-color-default);
|
background: transparent;
|
||||||
}
|
}
|
||||||
::-webkit-scrollbar-thumb {
|
::-webkit-scrollbar-thumb {
|
||||||
background-color: var(--spectrum-global-color-gray-400);
|
background-color: var(--spectrum-global-color-gray-400);
|
||||||
|
@ -71,6 +71,5 @@ a {
|
||||||
background: var(--spectrum-alias-background-color-default);
|
background: var(--spectrum-alias-background-color-default);
|
||||||
}
|
}
|
||||||
html * {
|
html * {
|
||||||
scrollbar-color: var(--spectrum-global-color-gray-400)
|
scrollbar-color: var(--spectrum-global-color-gray-400) transparent;
|
||||||
var(--spectrum-alias-background-color-default);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import authorized from "../middleware/authorized"
|
import authorized from "../middleware/authorized"
|
||||||
import currentApp from "../middleware/currentapp"
|
import currentApp from "../middleware/currentapp"
|
||||||
import { BaseSocket } from "./websocket"
|
import { BaseSocket } from "./websocket"
|
||||||
import { auth, permissions } from "@budibase/backend-core"
|
import { auth, permissions, context } from "@budibase/backend-core"
|
||||||
import http from "http"
|
import http from "http"
|
||||||
import Koa from "koa"
|
import Koa from "koa"
|
||||||
import { getSourceId } from "../api/controllers/row/utils"
|
import { getSourceId } from "../api/controllers/row/utils"
|
||||||
|
@ -10,6 +10,12 @@ import { Socket } from "socket.io"
|
||||||
import { GridSocketEvent } from "@budibase/shared-core"
|
import { GridSocketEvent } from "@budibase/shared-core"
|
||||||
import { userAgent } from "koa-useragent"
|
import { userAgent } from "koa-useragent"
|
||||||
import { createContext, runMiddlewares } from "./middleware"
|
import { createContext, runMiddlewares } from "./middleware"
|
||||||
|
import sdk from "../sdk"
|
||||||
|
import {
|
||||||
|
findHBSBlocks,
|
||||||
|
isJSBinding,
|
||||||
|
decodeJSBinding,
|
||||||
|
} from "@budibase/string-templates"
|
||||||
|
|
||||||
const { PermissionType, PermissionLevel } = permissions
|
const { PermissionType, PermissionLevel } = permissions
|
||||||
|
|
||||||
|
@ -18,15 +24,46 @@ export default class GridSocket extends BaseSocket {
|
||||||
super(app, server, "/socket/grid")
|
super(app, server, "/socket/grid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if a view's query contains any current user bindings
|
||||||
|
containsCurrentUserBinding(view: ViewV2): boolean {
|
||||||
|
return findHBSBlocks(JSON.stringify(view.query))
|
||||||
|
.map(binding => {
|
||||||
|
const sanitizedBinding = binding.replace(/\\"/g, '"')
|
||||||
|
if (isJSBinding(sanitizedBinding)) {
|
||||||
|
return decodeJSBinding(sanitizedBinding)
|
||||||
|
} else {
|
||||||
|
return sanitizedBinding
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.some(binding => binding?.includes("[user]"))
|
||||||
|
}
|
||||||
|
|
||||||
async onConnect(socket: Socket) {
|
async onConnect(socket: Socket) {
|
||||||
// Initial identification of connected spreadsheet
|
// Initial identification of connected spreadsheet
|
||||||
socket.on(GridSocketEvent.SelectDatasource, async (payload, callback) => {
|
socket.on(GridSocketEvent.SelectDatasource, async (payload, callback) => {
|
||||||
const ds = payload.datasource
|
const ds = payload.datasource
|
||||||
const appId = payload.appId
|
const appId = payload.appId
|
||||||
const resourceId = ds?.type === "table" ? ds?.tableId : ds?.id
|
const resourceId = ds?.type === "table" ? ds?.tableId : ds?.id
|
||||||
|
let valid = true
|
||||||
|
|
||||||
// Ignore if no table or app specified
|
// Validate datasource
|
||||||
if (!resourceId || !appId) {
|
if (!resourceId || !appId) {
|
||||||
|
// Ignore if no table or app specified
|
||||||
|
valid = false
|
||||||
|
} else if (ds.type === "viewV2") {
|
||||||
|
// If this is a view filtered by current user, don't sync changes
|
||||||
|
try {
|
||||||
|
await context.doInAppContext(appId, async () => {
|
||||||
|
const view = await sdk.views.get(ds.id)
|
||||||
|
if (this.containsCurrentUserBinding(view)) {
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
socket.disconnect(true)
|
socket.disconnect(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue