Skip to content

Commit 2f85a65

Browse files
committed
Permissions with no extra arguments
1 parent 87a7e73 commit 2f85a65

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

abstra_json_sql/authorization.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,14 @@ def __init__(self, default: bool = False):
126126
self.rules = []
127127

128128
def grant(
129-
self, command: RuleCommand, table_name: str, condition: Optional[str]
129+
self, command: RuleCommand, table_name: str, condition: Optional[str] = None
130130
) -> "ITablesSnapshot":
131-
if condition is None:
132-
133-
def condition(_):
134-
return self.default
135-
136131
self.rules.append(Rule("GRANT", command, table_name, condition))
137132
return self
138133

139134
def revoke(
140-
self, command: RuleCommand, table_name: str, condition: Optional[str]
135+
self, command: RuleCommand, table_name: str, condition: Optional[str] = None
141136
) -> "ITablesSnapshot":
142-
if condition is None:
143-
144-
def condition(_):
145-
return not self.default
146-
147137
self.rules.append(Rule("REVOKE", command, table_name, condition))
148138
return self
149139

abstra_json_sql/authorization_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55

66
class TestPermissions(TestCase):
7+
def test_grant_no_conditions(self):
8+
p = Permissions(default=False)
9+
p.grant("SELECT", "users")
10+
11+
self.assertTrue(p.allowed("select * from users"))
12+
self.assertTrue(p.allowed("select * from users where age > 18"))
13+
714
def test_select(self):
815
p = Permissions(default=False)
916
p.grant("SELECT", "users", "age > 18")

0 commit comments

Comments
 (0)