Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6995a8

Browse files
committedMay 12, 2024·
fix
1 parent de6a800 commit c6995a8

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed
 

‎e2e_test/batch/catalog/has_privilege.slt.part

+15
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ SELECT has_table_privilege('test_user', 'foo', 'INSERT WITH GRANT OPTION');
8686
----
8787
f
8888

89+
query I
90+
SELECT has_table_privilege('test_user', 'foo', 'INSERT, SELECT WITH GRANT OPTION');
91+
----
92+
t
93+
94+
query I
95+
SELECT has_table_privilege('test_user', 'foo', 'DELETE, INSERT, SELECT WITH GRANT OPTION');
96+
----
97+
t
98+
99+
query I
100+
SELECT has_table_privilege('test_user', 'foo', 'DELETE WITH GRANT OPTION, INSERT, SELECT WITH GRANT OPTION');
101+
----
102+
f
103+
89104
# FIXME(Kexiang): Currently, RW's grant privilege on all table doesn't apply to VIEWS.
90105
query I
91106
SELECT has_table_privilege('test_user', 'foo_view', 'SELECT');

‎src/frontend/src/user/user_catalog.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,26 @@ impl UserCatalog {
177177
if self.is_super {
178178
return true;
179179
}
180-
// Find matching privilege for the given object
181-
if let Some(privilege) = self
182-
.grant_privileges
183-
.iter()
184-
.find(|p| p.get_object().unwrap() == object)
185-
{
186-
for &(action, check_with_grant_option) in actions {
187-
// Check if any action_with_opts match the given action and with_grant_option
188-
if !privilege.action_with_opts.iter().any(|awo| {
189-
awo.get_action().unwrap() == action
190-
&& (!check_with_grant_option | awo.with_grant_option)
191-
}) {
192-
return false;
180+
let mut action_map: HashMap<_, _> =
181+
actions.into_iter().map(|action| (action, false)).collect();
182+
183+
for privilege in &self.grant_privileges {
184+
if privilege.get_object().unwrap() != object {
185+
continue;
186+
}
187+
for awo in &privilege.action_with_opts {
188+
let action = awo.get_action().unwrap();
189+
let with_grant_option = awo.with_grant_option;
190+
191+
for (&key, found) in action_map.iter_mut() {
192+
let (required_action, required_grant_option) = *key;
193+
194+
if action == required_action && (!required_grant_option | with_grant_option) {
195+
*found = true;
196+
}
193197
}
194198
}
195-
return true;
196199
}
197-
false
200+
action_map.values().all(|&found| found)
198201
}
199202
}

0 commit comments

Comments
 (0)
Please sign in to comment.