allow _is_null operator for filter/check permissions (close #456) (#477)

This commit is contained in:
Rakesh Emmadi
2018-09-18 17:15:35 +05:30
committed by Shahidh K Muhammed
parent cde559fe58
commit ec516ce55b
5 changed files with 76 additions and 6 deletions

View File

@@ -1,9 +1,10 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Hasura.RQL.GBoolExp where
@@ -111,6 +112,8 @@ data RQLOp
| RSIMILAR -- similar, regex
| RNSIMILAR -- not similar, regex
| RISNULL -- is null
deriving (Eq)
instance Show RQLOp where
@@ -134,6 +137,8 @@ instance Show RQLOp where
show RSIMILAR = "$similar"
show RNSIMILAR = "$nsimilar"
show RISNULL = "$is_null"
instance DQuote RQLOp where
dquoteTxt op = T.pack $ show op
@@ -175,6 +180,9 @@ parseOp opStr = case opStr of
"$nsimilar" -> return $ Left RNSIMILAR
"_nsimilar" -> return $ Left RNSIMILAR
"$is_null" -> return $ Left RISNULL
"_is_null" -> return $ Left RISNULL
"$ceq" -> return $ Right CEQ
"_ceq" -> return $ Right CEQ
"$cne" -> return $ Right CNE
@@ -219,6 +227,8 @@ parseAnnOpExpG parser op ty val = case op of
RNILIKE -> ANILIKE <$> parseOne -- NOT ILIKE, case insensitive
RSIMILAR -> ASIMILAR <$> parseOne -- similar, regex
RNSIMILAR -> ANSIMILAR <$> parseOne -- not similar, regex
RISNULL -> bool ANISNOTNULL ANISNULL -- is null
<$> decodeValue val
where
parseOne = parser ty val
-- runAesonParser (parsePGValue ty) val
@@ -290,6 +300,7 @@ getOpTypeChecker RILIKE = textOnlyOp
getOpTypeChecker RNILIKE = textOnlyOp
getOpTypeChecker RSIMILAR = textOnlyOp
getOpTypeChecker RNSIMILAR = textOnlyOp
getOpTypeChecker RISNULL = validOnAllTypes
-- This convoluted expression instead of col = val
-- to handle the case of col : null

View File

@@ -0,0 +1,20 @@
description: Inserts author without bio as a student (Error)
url: /v1alpha1/graphql
status: 400
headers:
X-Hasura-Role: student
query:
query: |
mutation insert_author {
insert_author (
objects: [
{
id: 5
name: "Student 1"
is_registered: false
}
]
) {
affected_rows
}
}

View File

@@ -0,0 +1,21 @@
description: Inserts author with bio as a student
url: /v1alpha1/graphql
status: 200
headers:
X-Hasura-Role: student
query:
query: |
mutation insert_author {
insert_author (
objects: [
{
id: 5
name: "Student 1"
bio: "Electrical Engineering"
is_registered: false
}
]
) {
affected_rows
}
}

View File

@@ -8,6 +8,7 @@ args:
create table author(
id serial primary key,
name text unique,
bio text,
is_registered boolean not null default false
);
- type: track_table
@@ -127,3 +128,14 @@ args:
- is_registered: false
allow_upsert: true
#Author insert permission for student
#A Student should specify their Bio
- type: create_insert_permission
args:
table: author
role: student
permission:
check:
bio:
_is_null: false
allow_upsert: true

View File

@@ -85,6 +85,12 @@ class TestGraphqlInsertPermission(object):
def test_user_role_insert_check_user_id_fail(self, hge_ctx):
check_query_f(hge_ctx, self.dir + "/author_user_role_insert_check_user_id_fail.yaml")
def test_student_role_insert_check_bio_success(self, hge_ctx):
check_query_f(hge_ctx, self.dir + "/author_student_role_insert_check_bio_success.yaml")
def test_student_role_insert_check_bio_fail(self, hge_ctx):
check_query_f(hge_ctx, self.dir + "/author_student_role_insert_check_bio_fail.yaml")
@pytest.fixture(autouse=True)