mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
Remove *Source
fields from API test permissions
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7275 GitOrigin-RevId: 44345ec361fdbb93f2c166825e5d78983759b5b0
This commit is contained in:
parent
beb20c7dab
commit
f2dd4a5eb7
@ -14,12 +14,10 @@ module Test.Queries.FilterSearch.AggregationPredicatesSpec (spec) where
|
||||
|
||||
import Data.Aeson (Value)
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
import Data.Text qualified as Text
|
||||
import Harness.Backend.Postgres qualified as Postgres
|
||||
import Harness.GraphqlEngine (postGraphql, postGraphqlWithHeaders)
|
||||
import Harness.Quoter.Graphql (graphql)
|
||||
import Harness.Quoter.Yaml (interpolateYaml, yaml)
|
||||
import Harness.Test.BackendType qualified as BackendType
|
||||
import Harness.Test.Fixture qualified as Fixture
|
||||
import Harness.Test.Permissions (Permission (SelectPermission), SelectPermissionDetails (..), selectPermission)
|
||||
import Harness.Test.Schema (Table (..), table)
|
||||
@ -39,7 +37,7 @@ spec = do
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnv, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnv,
|
||||
Postgres.setupPermissionsAction (permissions Postgres.backendTypeMetadata) testEnv
|
||||
Postgres.setupPermissionsAction permissions testEnv
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -80,19 +78,17 @@ schema =
|
||||
}
|
||||
]
|
||||
|
||||
permissions :: BackendType.BackendTypeConfig -> [Permission]
|
||||
permissions backend =
|
||||
permissions :: [Permission]
|
||||
permissions =
|
||||
[ SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionTable = "author",
|
||||
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
|
||||
selectPermissionRole = "role-select-author-name-only",
|
||||
selectPermissionColumns = ["id", "name"]
|
||||
},
|
||||
SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionTable = "article",
|
||||
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
|
||||
selectPermissionRole = "role-select-author-name-only",
|
||||
selectPermissionColumns = ["id", "title", "author_id"],
|
||||
selectPermissionRows =
|
||||
@ -104,14 +100,12 @@ permissions backend =
|
||||
SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionTable = "author",
|
||||
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
|
||||
selectPermissionRole = "disallow-aggregation-queries",
|
||||
selectPermissionColumns = ["id", "name"]
|
||||
},
|
||||
SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionTable = "article",
|
||||
selectPermissionSource = Text.pack $ BackendType.backendSourceName backend,
|
||||
selectPermissionRole = "disallow-aggregation-queries",
|
||||
selectPermissionColumns = ["id", "title", "author_id"],
|
||||
selectPermissionAllowAggregations = False
|
||||
|
@ -66,7 +66,6 @@ updatePermission =
|
||||
Permissions.UpdatePermission
|
||||
Permissions.updatePermission
|
||||
{ Permissions.updatePermissionTable = authorTableName,
|
||||
Permissions.updatePermissionSource = "postgres",
|
||||
Permissions.updatePermissionRole = "user",
|
||||
Permissions.updatePermissionColumns = ["age"]
|
||||
}
|
||||
|
@ -29,19 +29,19 @@ spec = do
|
||||
[ (Fixture.fixture $ Fixture.Backend Postgres.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Postgres.setupTablesAction schema testEnvironment,
|
||||
Postgres.setupPermissionsAction (permissions "postgres") testEnvironment
|
||||
Postgres.setupPermissionsAction permissions testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Citus.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Citus.setupTablesAction schema testEnvironment,
|
||||
Citus.setupPermissionsAction (permissions "citus") testEnvironment
|
||||
Citus.setupPermissionsAction permissions testEnvironment
|
||||
]
|
||||
},
|
||||
(Fixture.fixture $ Fixture.Backend Cockroach.backendTypeMetadata)
|
||||
{ Fixture.setupTeardown = \(testEnvironment, _) ->
|
||||
[ Cockroach.setupTablesAction schema testEnvironment,
|
||||
Cockroach.setupPermissionsAction (permissions "cockroach") testEnvironment
|
||||
Cockroach.setupPermissionsAction permissions testEnvironment
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -70,19 +70,17 @@ schema =
|
||||
--------------------------------------------------------------------------------
|
||||
-- Permissions
|
||||
|
||||
permissions :: Text -> [Permission]
|
||||
permissions source =
|
||||
permissions :: [Permission]
|
||||
permissions =
|
||||
[ SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionTable = "foo",
|
||||
selectPermissionSource = source,
|
||||
selectPermissionRole = "role-select-only",
|
||||
selectPermissionColumns = ["id", "bar"]
|
||||
},
|
||||
InsertPermission
|
||||
insertPermission
|
||||
{ insertPermissionTable = "foo",
|
||||
insertPermissionSource = source,
|
||||
insertPermissionRole = "role-insert-only",
|
||||
insertPermissionColumns = ["id", "bar"]
|
||||
}
|
||||
|
@ -232,8 +232,7 @@ setupMetadata testEnvironment =
|
||||
testEnvironment
|
||||
$ SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionSource = T.pack source,
|
||||
selectPermissionTable = "author",
|
||||
{ selectPermissionTable = "author",
|
||||
selectPermissionRole = "user_1",
|
||||
selectPermissionColumns = (["id", "name"] :: [Text])
|
||||
},
|
||||
@ -245,8 +244,7 @@ setupMetadata testEnvironment =
|
||||
testEnvironment
|
||||
$ SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionSource = T.pack source,
|
||||
selectPermissionTable = "article",
|
||||
{ selectPermissionTable = "article",
|
||||
selectPermissionRole = "user_1",
|
||||
selectPermissionColumns = (["id", "title", "content", "author_id"] :: [Text])
|
||||
},
|
||||
@ -259,8 +257,7 @@ setupMetadata testEnvironment =
|
||||
testEnvironment
|
||||
$ SelectPermission
|
||||
selectPermission
|
||||
{ selectPermissionSource = T.pack source,
|
||||
selectPermissionTable = "author",
|
||||
{ selectPermissionTable = "author",
|
||||
selectPermissionRole = "user_2",
|
||||
selectPermissionColumns = (["id", "name"] :: [Text])
|
||||
},
|
||||
|
@ -192,7 +192,6 @@ lhsRole1 =
|
||||
Permissions.SelectPermission
|
||||
Permissions.selectPermission
|
||||
{ selectPermissionRole = "role1",
|
||||
selectPermissionSource = lhsSourceName_,
|
||||
selectPermissionTable = lhsTableName_,
|
||||
selectPermissionColumns = (["id", "name"] :: [Text])
|
||||
}
|
||||
@ -202,7 +201,6 @@ lhsRole2 =
|
||||
Permissions.SelectPermission
|
||||
Permissions.selectPermission
|
||||
{ selectPermissionRole = "role2",
|
||||
selectPermissionSource = lhsSourceName_,
|
||||
selectPermissionTable = lhsTableName_,
|
||||
selectPermissionColumns = (["id", "name"] :: [Text])
|
||||
}
|
||||
@ -260,7 +258,6 @@ rhsRole1 =
|
||||
Permissions.SelectPermission
|
||||
Permissions.selectPermission
|
||||
{ selectPermissionRole = "role1",
|
||||
selectPermissionSource = rhsSourceName_,
|
||||
selectPermissionTable = rhsTableName_,
|
||||
selectPermissionColumns = (["title", "artist_id"] :: [Text]),
|
||||
selectPermissionRows =
|
||||
@ -275,7 +272,6 @@ rhsRole2 =
|
||||
Permissions.SelectPermission
|
||||
Permissions.selectPermission
|
||||
{ selectPermissionRole = "role2",
|
||||
selectPermissionSource = rhsSourceName_,
|
||||
selectPermissionTable = rhsTableName_,
|
||||
selectPermissionColumns = (["id", "title", "artist_id"] :: [Text]),
|
||||
selectPermissionAllowAggregations = True,
|
||||
|
@ -39,7 +39,6 @@ data Permission
|
||||
|
||||
data SelectPermissionDetails = SelectPermissionDetails
|
||||
{ selectPermissionTable :: Text,
|
||||
selectPermissionSource :: Text,
|
||||
selectPermissionRole :: Text,
|
||||
selectPermissionColumns :: [Text],
|
||||
selectPermissionRows :: Aeson.Value,
|
||||
@ -49,7 +48,6 @@ data SelectPermissionDetails = SelectPermissionDetails
|
||||
|
||||
data UpdatePermissionDetails = UpdatePermissionDetails
|
||||
{ updatePermissionTable :: Text,
|
||||
updatePermissionSource :: Text,
|
||||
updatePermissionRole :: Text,
|
||||
updatePermissionColumns :: [Text],
|
||||
updatePermissionRows :: Aeson.Value
|
||||
@ -57,7 +55,6 @@ data UpdatePermissionDetails = UpdatePermissionDetails
|
||||
|
||||
data InsertPermissionDetails = InsertPermissionDetails
|
||||
{ insertPermissionTable :: Text,
|
||||
insertPermissionSource :: Text,
|
||||
insertPermissionRole :: Text,
|
||||
insertPermissionColumns :: [Text],
|
||||
insertPermissionRows :: Aeson.Value
|
||||
@ -67,7 +64,6 @@ selectPermission :: SelectPermissionDetails
|
||||
selectPermission =
|
||||
SelectPermissionDetails
|
||||
{ selectPermissionTable = mempty,
|
||||
selectPermissionSource = mempty,
|
||||
selectPermissionRole = mempty,
|
||||
selectPermissionColumns = mempty,
|
||||
selectPermissionRows = [yaml|{}|],
|
||||
@ -79,7 +75,6 @@ updatePermission :: UpdatePermissionDetails
|
||||
updatePermission =
|
||||
UpdatePermissionDetails
|
||||
{ updatePermissionTable = mempty,
|
||||
updatePermissionSource = mempty,
|
||||
updatePermissionRole = mempty,
|
||||
updatePermissionColumns = mempty,
|
||||
updatePermissionRows = [yaml|{}|]
|
||||
@ -89,7 +84,6 @@ insertPermission :: InsertPermissionDetails
|
||||
insertPermission =
|
||||
InsertPermissionDetails
|
||||
{ insertPermissionTable = mempty,
|
||||
insertPermissionSource = mempty,
|
||||
insertPermissionRole = mempty,
|
||||
insertPermissionColumns = mempty,
|
||||
insertPermissionRows = [yaml|{}|]
|
||||
@ -103,6 +97,7 @@ createPermission testEnvironment (InsertPermission InsertPermissionDetails {..})
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
|
||||
schemaName = Schema.getSchemaName testEnvironment
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
requestType = backendType <> "_create_insert_permission"
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -111,7 +106,7 @@ createPermission testEnvironment (InsertPermission InsertPermissionDetails {..})
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *insertPermissionSource
|
||||
source: *sourceName
|
||||
role: *insertPermissionRole
|
||||
permission:
|
||||
columns: *insertPermissionColumns
|
||||
@ -123,6 +118,7 @@ createPermission testEnvironment (UpdatePermission UpdatePermissionDetails {..})
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
|
||||
schemaName = Schema.getSchemaName testEnvironment
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
requestType = backendType <> "_create_update_permission"
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -131,7 +127,7 @@ createPermission testEnvironment (UpdatePermission UpdatePermissionDetails {..})
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *updatePermissionSource
|
||||
source: *sourceName
|
||||
role: *updatePermissionRole
|
||||
permission:
|
||||
columns: *updatePermissionColumns
|
||||
@ -143,6 +139,7 @@ createPermission testEnvironment (SelectPermission SelectPermissionDetails {..})
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ backendTypeConfig testEnvironment
|
||||
schemaName = Schema.getSchemaName testEnvironment
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
requestType = backendType <> "_create_select_permission"
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -151,7 +148,7 @@ createPermission testEnvironment (SelectPermission SelectPermissionDetails {..})
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *selectPermissionSource
|
||||
source: *sourceName
|
||||
role: *selectPermissionRole
|
||||
permission:
|
||||
columns: *selectPermissionColumns
|
||||
@ -165,6 +162,7 @@ dropPermission backendTypeMetadata env (InsertPermission InsertPermissionDetails
|
||||
let schemaName = Schema.getSchemaName env
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
requestType = backendType <> "_drop_insert_permission"
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName insertPermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
env
|
||||
@ -172,12 +170,13 @@ dropPermission backendTypeMetadata env (InsertPermission InsertPermissionDetails
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *insertPermissionSource
|
||||
source: *sourceName
|
||||
role: *insertPermissionRole
|
||||
|]
|
||||
dropPermission backendTypeMetadata env (SelectPermission SelectPermissionDetails {..}) = do
|
||||
let schemaName = Schema.getSchemaName env
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
requestType = backendType <> "_drop_select_permission"
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName selectPermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -186,12 +185,13 @@ dropPermission backendTypeMetadata env (SelectPermission SelectPermissionDetails
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *selectPermissionSource
|
||||
source: *sourceName
|
||||
role: *selectPermissionRole
|
||||
|]
|
||||
dropPermission backendTypeMetadata env (UpdatePermission UpdatePermissionDetails {..}) = do
|
||||
let schemaName = Schema.getSchemaName env
|
||||
backendType = BackendType.backendTypeString backendTypeMetadata
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
requestType = backendType <> "_drop_update_permission"
|
||||
qualifiedTable = Schema.mkTableField backendTypeMetadata schemaName updatePermissionTable
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -200,7 +200,7 @@ dropPermission backendTypeMetadata env (UpdatePermission UpdatePermissionDetails
|
||||
type: *requestType
|
||||
args:
|
||||
table: *qualifiedTable
|
||||
source: *updatePermissionSource
|
||||
source: *sourceName
|
||||
role: *updatePermissionRole
|
||||
|]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user