server: rename spiScalarComputedFields to spiComputedFields

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4629
GitOrigin-RevId: 53d72d8ed73ecab486718f424bbd8d30c6f423bf
This commit is contained in:
Rakesh Emmadi 2022-06-06 12:53:00 +05:30 committed by hasura-bot
parent ebc8cd5134
commit 524819b4b7
8 changed files with 17 additions and 15 deletions

View File

@ -1355,7 +1355,7 @@ computedFieldPG sourceInfo ComputedFieldInfo {..} parentTable tableInfo = runMay
case _cfiReturnType of
PG.CFRScalar scalarReturnType -> do
caseBoolExpMaybe <-
hoistMaybe (Map.lookup _cfiName (spiScalarComputedFields selectPermissions))
hoistMaybe (Map.lookup _cfiName (spiComputedFields selectPermissions))
let caseBoolExpUnpreparedValue =
(fmap . fmap) partialSQLExpToUnpreparedValue <$> caseBoolExpMaybe
fieldArgsParser = do

View File

@ -191,7 +191,7 @@ tableSelectFields sourceInfo tableInfo = do
canBeSelected (Just permissions) (FIComputedField computedFieldInfo) =
case computedFieldReturnType @b (_cfiReturnType computedFieldInfo) of
ReturnsScalar _ ->
pure $ Map.member (_cfiName computedFieldInfo) $ spiScalarComputedFields permissions
pure $ Map.member (_cfiName computedFieldInfo) $ spiComputedFields permissions
ReturnsTable tableName -> do
tableInfo' <- askTableInfo sourceInfo tableName
isJust <$> tableSelectPermissions @b tableInfo'

View File

@ -343,7 +343,7 @@ buildSelPermInfo source tn fieldInfoMap sp = withPathK "permission" $ do
askColumnType fieldInfoMap pgCol autoInferredErr
-- validate computed fields
scalarComputedFields <-
validComputedFields <-
withPathK "computed_fields" $
indexedForM computedFields $ \fieldName -> do
computedFieldInfo <- askComputedFieldInfo fieldInfoMap fieldName
@ -363,7 +363,7 @@ buildSelPermInfo source tn fieldInfoMap sp = withPathK "permission" $ do
let deps =
mkParentDep @b source tn :
boolExpDeps ++ map (mkColDep @b DRUntyped source tn) pgCols
++ map (mkComputedFieldDep @b DRUntyped source tn) scalarComputedFields
++ map (mkComputedFieldDep @b DRUntyped source tn) validComputedFields
depHeaders = getDependentHeaders $ spFilter sp
mLimit = spLimit sp
@ -372,10 +372,10 @@ buildSelPermInfo source tn fieldInfoMap sp = withPathK "permission" $ do
throw400 NotSupported "unexpected negative value"
let pgColsWithFilter = HM.fromList $ map (,Nothing) pgCols
scalarComputedFieldsWithFilter = HS.toMap (HS.fromList scalarComputedFields) $> Nothing
computedFieldsWithFilter = HS.toMap (HS.fromList validComputedFields) $> Nothing
let selPermInfo =
SelPermInfo pgColsWithFilter scalarComputedFieldsWithFilter boolExp mLimit allowAgg depHeaders
SelPermInfo pgColsWithFilter computedFieldsWithFilter boolExp mLimit allowAgg depHeaders
return (selPermInfo, deps)
where

View File

@ -189,7 +189,7 @@ checkSelectPermOnScalarComputedField ::
m ()
checkSelectPermOnScalarComputedField selPermInfo computedField = do
role <- askCurRole
unless (M.member computedField $ spiScalarComputedFields selPermInfo) $
unless (M.member computedField $ spiComputedFields selPermInfo) $
throw400 PermissionDenied $ permErrMsg role
where
permErrMsg role

View File

@ -217,7 +217,8 @@ data SelPerm (b :: BackendType) = SelPerm
spLimit :: !(Maybe Int),
-- | Allow aggregation
spAllowAggregations :: !Bool,
-- | Allowed computed fields
-- | Allowed computed fields which should not
-- include the fields returning rows of existing table.
spComputedFields :: ![ComputedFieldName]
}
deriving (Show, Eq, Generic)

View File

@ -94,7 +94,7 @@ rolePermInfoToCombineRolePermInfo RolePermInfo {..} =
modifySingleSelectPerm SelPermInfo {..} =
let columnCaseBoolExp = fmap AnnColumnCaseBoolExpField spiFilter
colsWithColCaseBoolExp = spiCols $> Just columnCaseBoolExp
scalarCompFieldsWithColCaseBoolExp = spiScalarComputedFields $> Just columnCaseBoolExp
scalarCompFieldsWithColCaseBoolExp = spiComputedFields $> Just columnCaseBoolExp
in CombinedSelPermInfo
[colsWithColCaseBoolExp]
[scalarCompFieldsWithColCaseBoolExp]

View File

@ -353,7 +353,7 @@ instance
-- to combine more than one select permissions for inherited roles.
data CombinedSelPermInfo (b :: BackendType) = CombinedSelPermInfo
{ cspiCols :: ![(M.HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b)))],
cspiScalarComputedFields :: ![(M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b)))],
cspiComputedFields :: ![(M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b)))],
cspiFilter :: ![(AnnBoolExpPartialSQL b)],
cspiLimit :: !(Maybe (Max Int)),
cspiAllowAgg :: !Any,
@ -379,7 +379,7 @@ combinedSelPermInfoToSelPermInfo ::
combinedSelPermInfoToSelPermInfo selPermsCount CombinedSelPermInfo {..} =
SelPermInfo
(mergeColumnsWithBoolExp <$> M.unionsAll cspiCols)
(mergeColumnsWithBoolExp <$> M.unionsAll cspiScalarComputedFields)
(mergeColumnsWithBoolExp <$> M.unionsAll cspiComputedFields)
(BoolOr cspiFilter)
(getMax <$> cspiLimit)
(getAny cspiAllowAgg)
@ -419,9 +419,10 @@ data SelPermInfo (b :: BackendType) = SelPermInfo
-- bool exp will determine if the column should be nullified in a row, when
-- there aren't requisite permissions.
spiCols :: !(M.HashMap (Column b) (Maybe (AnnColumnCaseBoolExpPartialSQL b))),
-- | HashMap of accessible scalar computed fields to the role, mapped to
-- `AnnColumnCaseBoolExpPartialSQL`, simililar to `spiCols`
spiScalarComputedFields :: !(M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))),
-- | HashMap of accessible computed fields to the role, mapped to
-- `AnnColumnCaseBoolExpPartialSQL`, simililar to `spiCols`.
-- These computed fields do not return rows of existing table.
spiComputedFields :: !(M.HashMap ComputedFieldName (Maybe (AnnColumnCaseBoolExpPartialSQL b))),
spiFilter :: !(AnnBoolExpPartialSQL b),
spiLimit :: !(Maybe Int),
spiAllowAgg :: !Bool,

View File

@ -175,7 +175,7 @@ mkParser table cib =
selPermInfo =
SelPermInfo
{ spiCols = HM.fromList . fmap ((,Nothing) . unsafePGCol . cibName) $ cib,
spiScalarComputedFields = mempty,
spiComputedFields = mempty,
spiFilter = upiFilter,
spiLimit = Nothing,
spiAllowAgg = True,