mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
342391f39d
This upgrades the version of Ormolu required by the HGE repository to v0.5.0.1, and reformats all code accordingly. Ormolu v0.5 reformats code that uses infix operators. This is mostly useful, adding newlines and indentation to make it clear which operators are applied first, but in some cases, it's unpleasant. To make this easier on the eyes, I had to do the following: * Add a few fixity declarations (search for `infix`) * Add parentheses to make precedence clear, allowing Ormolu to keep everything on one line * Rename `relevantEq` to `(==~)` in #6651 and set it to `infix 4` * Add a few _.ormolu_ files (thanks to @hallettj for helping me get started), mostly for Autodocodec operators that don't have explicit fixity declarations In general, I think these changes are quite reasonable. They mostly affect indentation. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6675 GitOrigin-RevId: cd47d87f1d089fb0bc9dcbbe7798dbceedcd7d83
74 lines
2.7 KiB
Haskell
74 lines
2.7 KiB
Haskell
module Hasura.RQL.DDL.InheritedRoles
|
|
( runAddInheritedRole,
|
|
runDropInheritedRole,
|
|
dropInheritedRoleInMetadata,
|
|
resolveInheritedRole,
|
|
)
|
|
where
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
|
import Data.HashSet qualified as Set
|
|
import Data.Text.Extended
|
|
import Hasura.Base.Error
|
|
import Hasura.EncJSON
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Common
|
|
import Hasura.RQL.Types.Metadata
|
|
import Hasura.RQL.Types.Metadata.Object
|
|
import Hasura.RQL.Types.Roles
|
|
import Hasura.RQL.Types.SchemaCache
|
|
import Hasura.RQL.Types.SchemaCache.Build
|
|
import Hasura.Session
|
|
|
|
runAddInheritedRole ::
|
|
( MonadError QErr m,
|
|
CacheRWM m,
|
|
MetadataM m
|
|
) =>
|
|
InheritedRole ->
|
|
m EncJSON
|
|
runAddInheritedRole addInheritedRoleQ@(Role inheritedRoleName (ParentRoles parentRoles)) = do
|
|
when (inheritedRoleName `elem` parentRoles) $
|
|
throw400 InvalidParams "an inherited role name cannot be in the role combination"
|
|
buildSchemaCacheFor (MOInheritedRole inheritedRoleName) $
|
|
MetadataModifier $
|
|
metaInheritedRoles %~ OMap.insert inheritedRoleName addInheritedRoleQ
|
|
pure successMsg
|
|
|
|
dropInheritedRoleInMetadata :: RoleName -> MetadataModifier
|
|
dropInheritedRoleInMetadata roleName =
|
|
MetadataModifier $ metaInheritedRoles %~ OMap.delete roleName
|
|
|
|
runDropInheritedRole ::
|
|
(MonadError QErr m, CacheRWM m, MetadataM m) =>
|
|
DropInheritedRole ->
|
|
m EncJSON
|
|
runDropInheritedRole (DropInheritedRole roleName) = do
|
|
inheritedRolesMetadata <- _metaInheritedRoles <$> getMetadata
|
|
unless (roleName `OMap.member` inheritedRolesMetadata) $
|
|
throw400 NotExists $
|
|
roleName <<> " inherited role doesn't exist"
|
|
buildSchemaCacheFor (MOInheritedRole roleName) (dropInheritedRoleInMetadata roleName)
|
|
pure successMsg
|
|
|
|
-- | `resolveInheritedRole` resolves an inherited role by checking if
|
|
-- all the parent roles of an inherited role exists and report
|
|
-- the dependencies of the inherited role which will be the list
|
|
-- of the parent roles
|
|
resolveInheritedRole ::
|
|
MonadError QErr m =>
|
|
HashSet RoleName ->
|
|
InheritedRole ->
|
|
m (Role, [SchemaDependency])
|
|
resolveInheritedRole allRoles (Role roleName (ParentRoles parentRoles)) = do
|
|
let missingParentRoles = Set.filter (`notElem` allRoles) parentRoles
|
|
unless (Set.null missingParentRoles) $
|
|
let errMessage roles =
|
|
"the following parent role(s) are not found: "
|
|
<> roles
|
|
<> " which are required to construct the inherited role: " <>> roleName
|
|
in throw400 NotExists $ errMessage $ commaSeparated $ Set.map roleNameToTxt missingParentRoles
|
|
let schemaDependencies =
|
|
map (\parentRole -> SchemaDependency (SORole parentRole) DRParentRole) $ toList parentRoles
|
|
pure $ (Role roleName $ ParentRoles parentRoles, schemaDependencies)
|