From 9f903c0b99d21bc203bad35bcf09c07615124b47 Mon Sep 17 00:00:00 2001 From: Kexiang Wang Date: Fri, 10 May 2024 01:09:29 -0400 Subject: [PATCH] rename --- e2e_test/batch/catalog/has_privilege.slt.part | 11 +++++++++++ src/frontend/src/catalog/database_catalog.rs | 4 ++-- src/frontend/src/catalog/schema_catalog.rs | 2 +- src/frontend/src/expr/function_impl/has_privilege.rs | 8 ++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/e2e_test/batch/catalog/has_privilege.slt.part b/e2e_test/batch/catalog/has_privilege.slt.part index a8f7e48d554b..8a4139ddf4b0 100644 --- a/e2e_test/batch/catalog/has_privilege.slt.part +++ b/e2e_test/batch/catalog/has_privilege.slt.part @@ -132,6 +132,17 @@ SELECT has_table_privilege('test_user', 'foo_source', 'INSERT'); ---- f +# Indexes are granted by `GRANT SELECT ON ALL MATERIALIZED VIEWS` +query I +SELECT has_table_privilege('test_user', 'foo_index'::regclass, 'SELECT'); +---- +t + +query I +SELECT has_table_privilege('test_user', 'foo_index', 'INSERT'); +---- +f + query I SELECT has_table_privilege('test_user', 'bar', 'INSERT'); ---- diff --git a/src/frontend/src/catalog/database_catalog.rs b/src/frontend/src/catalog/database_catalog.rs index d61ee4bb12f4..c562e5fc77a8 100644 --- a/src/frontend/src/catalog/database_catalog.rs +++ b/src/frontend/src/catalog/database_catalog.rs @@ -100,9 +100,9 @@ impl DatabaseCatalog { .find(|schema| schema.get_table_by_id(table_id).is_some()) } - pub fn get_object_by_oid(&self, oid: u32) -> Option { + pub fn get_grant_object_by_oid(&self, oid: u32) -> Option { for schema in self.schema_by_name.values() { - let object = schema.get_object_by_oid(oid); + let object = schema.get_grant_object_by_oid(oid); if object.is_some() { return object; } diff --git a/src/frontend/src/catalog/schema_catalog.rs b/src/frontend/src/catalog/schema_catalog.rs index b116179eab82..20a99ad820af 100644 --- a/src/frontend/src/catalog/schema_catalog.rs +++ b/src/frontend/src/catalog/schema_catalog.rs @@ -704,7 +704,7 @@ impl SchemaCatalog { .map(|s| s.to_owned()) } - pub fn get_object_by_oid(&self, oid: u32) -> Option { + pub fn get_grant_object_by_oid(&self, oid: u32) -> Option { #[allow(clippy::manual_map)] if self.get_table_by_id(&TableId::new(oid)).is_some() || self.get_index_by_id(&IndexId::new(oid)).is_some() diff --git a/src/frontend/src/expr/function_impl/has_privilege.rs b/src/frontend/src/expr/function_impl/has_privilege.rs index b338fcf04408..e82d8bb8165e 100644 --- a/src/frontend/src/expr/function_impl/has_privilege.rs +++ b/src/frontend/src/expr/function_impl/has_privilege.rs @@ -44,7 +44,7 @@ fn has_table_privilege_1(user_name: &str, table_oid: i32, privileges: &str) -> R // currently, we haven't support grant for view. has_privilege_impl_captured( user_name, - &get_object_id_by_oid_captured(table_oid)?, + &get_grant_object_by_oid_captured(table_oid)?, &actions, ) } @@ -62,7 +62,7 @@ fn has_any_column_privilege_1(user_name: &str, table_oid: i32, privileges: &str) let actions = parse_privilege(privileges, &allowed_actions)?; has_privilege_impl_captured( user_name, - &get_object_id_by_oid_captured(table_oid)?, + &get_grant_object_by_oid_captured(table_oid)?, &actions, ) } @@ -121,7 +121,7 @@ fn get_user_name_by_id(user_info_reader: &UserInfoReader, user_id: i32) -> Resul } #[capture_context(CATALOG_READER, DB_NAME)] -fn get_object_id_by_oid(catalog_reader: &CatalogReader, db_name: &str, oid: i32) -> Result { +fn get_grant_object_by_oid(catalog_reader: &CatalogReader, db_name: &str, oid: i32) -> Result { catalog_reader .read_guard() .get_database_by_name(db_name) @@ -129,7 +129,7 @@ fn get_object_id_by_oid(catalog_reader: &CatalogReader, db_name: &str, oid: i32) name: "oid", reason: e.to_report_string().into(), })? - .get_object_by_oid(oid as u32) + .get_grant_object_by_oid(oid as u32) .ok_or(ExprError::InvalidParam { name: "oid", reason: format!("Table {} not found", oid).as_str().into(),