mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-20 15:09:02 +03:00
server: fix dropping column from a table that has update permissions
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4840 GitOrigin-RevId: cea142fe225315f4f4094f157d8a95df14273306
This commit is contained in:
parent
3c33996e7d
commit
7634be3216
@ -49,6 +49,7 @@
|
||||
|
||||
### Bug fixes and improvements
|
||||
|
||||
- server: fix dropping column from a table that has update permissions (fix #8415)
|
||||
- console: Hide TimescaleDB internal schema from data tab
|
||||
- console: support naming convention in source customization for postgres DB [CON-297]
|
||||
|
||||
|
@ -489,7 +489,7 @@ buildUpdPermInfo source tn fieldInfoMap (UpdPerm colSpec set fltr check backendO
|
||||
<<> " is not updatable and so cannot have update permissions defined"
|
||||
)
|
||||
|
||||
let updColDeps = map (mkColDep @b DRUntyped source tn) allUpdCols
|
||||
let updColDeps = map (mkColDep @b DRUntyped source tn) updCols
|
||||
deps = mkParentDep @b source tn : beDeps ++ maybe [] snd checkExpr ++ updColDeps ++ setColDeps
|
||||
depHeaders = getDependentHeaders fltr
|
||||
reqHeaders = depHeaders `HS.union` (HS.fromList setHeaders)
|
||||
|
@ -4,9 +4,13 @@
|
||||
module Test.RunSQLSpec (spec) where
|
||||
|
||||
import Harness.Backend.BigQuery qualified as BigQuery
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.Constants qualified as Constants
|
||||
import Harness.GraphqlEngine qualified as GraphqlEngine
|
||||
import Harness.Quoter.Yaml
|
||||
import Harness.Test.Context qualified as Context
|
||||
import Harness.Test.Permissions qualified as Permissions
|
||||
import Harness.Test.Schema
|
||||
import Harness.TestEnvironment (TestEnvironment)
|
||||
import Test.Hspec
|
||||
import Prelude
|
||||
@ -14,7 +18,8 @@ import Prelude
|
||||
--------------------------------------------------------------------------------
|
||||
-- Preamble
|
||||
spec :: SpecWith TestEnvironment
|
||||
spec =
|
||||
spec = do
|
||||
-- BigQuery
|
||||
Context.run
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.BigQuery,
|
||||
@ -24,13 +29,61 @@ spec =
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
tests
|
||||
bigqueryTests
|
||||
-- Postgres
|
||||
Context.run
|
||||
[ Context.Context
|
||||
{ name = Context.Backend Context.Postgres,
|
||||
mkLocalTestEnvironment = Context.noLocalTestEnvironment,
|
||||
setup = postgresSetup,
|
||||
teardown = postgresTeardown,
|
||||
customOptions = Nothing
|
||||
}
|
||||
]
|
||||
postgresTests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Setup & Teardown
|
||||
|
||||
postgresSetup :: (TestEnvironment, ()) -> IO ()
|
||||
postgresSetup (env, ()) = do
|
||||
Postgres.setup [testTable] (env, ())
|
||||
Postgres.setupPermissions [updatePermission] env
|
||||
|
||||
postgresTeardown :: (TestEnvironment, ()) -> IO ()
|
||||
postgresTeardown (env, ()) = do
|
||||
Postgres.teardownPermissions [updatePermission] env
|
||||
Postgres.teardown [testTable] (env, ())
|
||||
|
||||
updatePermission :: Permissions.Permission
|
||||
updatePermission =
|
||||
Permissions.UpdatePermission
|
||||
{ Permissions.permissionTable = "test",
|
||||
Permissions.permissionSource = "postgres",
|
||||
Permissions.permissionRole = "user",
|
||||
Permissions.permissionColumns = ["age"]
|
||||
}
|
||||
|
||||
testTable :: Table
|
||||
testTable =
|
||||
(table "test")
|
||||
{ tableColumns =
|
||||
[ column "id" TInt,
|
||||
column "name" TStr,
|
||||
column "age" TInt
|
||||
],
|
||||
tablePrimaryKey = ["id"],
|
||||
tableData =
|
||||
[ [VInt 1, VStr "Author 1", VInt 25],
|
||||
[VInt 2, VStr "Author 2", VInt 30]
|
||||
]
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Tests
|
||||
|
||||
tests :: Context.Options -> SpecWith TestEnvironment
|
||||
tests opts = do
|
||||
bigqueryTests :: Context.Options -> SpecWith TestEnvironment
|
||||
bigqueryTests opts = do
|
||||
it "BigQuery - running invalid SQL" \testEnvironment ->
|
||||
shouldReturnYaml
|
||||
opts
|
||||
@ -61,3 +114,46 @@ path: "$"
|
||||
error: Bigquery HTTP request failed with status code 400 and status message "Bad Request"
|
||||
code: bigquery-error
|
||||
|]
|
||||
|
||||
postgresTests :: Context.Options -> SpecWith TestEnvironment
|
||||
postgresTests opts = do
|
||||
-- Testing regression reported at https://github.com/hasura/graphql-engine/issues/8415
|
||||
it "Drop column which is not referred in update permission" \testEnvironment -> do
|
||||
let runSQL = "alter table " <> Constants.postgresDb <> ".test drop column name;"
|
||||
shouldReturnYaml
|
||||
opts
|
||||
( GraphqlEngine.postV2Query
|
||||
200
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
result: null
|
||||
result_type: CommandOk
|
||||
|]
|
||||
|
||||
it "Drop column which is referred in update permission" \testEnvironment -> do
|
||||
let runSQL = "alter table " <> Constants.postgresDb <> ".test drop column age;"
|
||||
shouldReturnYaml
|
||||
opts
|
||||
( GraphqlEngine.postV2Query
|
||||
400
|
||||
testEnvironment
|
||||
[yaml|
|
||||
type: run_sql
|
||||
args:
|
||||
source: postgres
|
||||
sql: *runSQL
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
code: dependency-error
|
||||
error: 'cannot drop due to the following dependent objects : permission hasura.test.user.update
|
||||
in source "postgres"'
|
||||
path: "$"
|
||||
|]
|
||||
|
Loading…
Reference in New Issue
Block a user