Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
KeXiangWang committed May 10, 2024
1 parent a341e1b commit 9f903c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
11 changes: 11 additions & 0 deletions e2e_test/batch/catalog/has_privilege.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -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');
----
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/catalog/database_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> {
pub fn get_grant_object_by_oid(&self, oid: u32) -> Option<Object> {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/catalog/schema_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ impl SchemaCatalog {
.map(|s| s.to_owned())
}

pub fn get_object_by_oid(&self, oid: u32) -> Option<Object> {
pub fn get_grant_object_by_oid(&self, oid: u32) -> Option<Object> {
#[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()
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/expr/function_impl/has_privilege.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand All @@ -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,
)
}
Expand Down Expand Up @@ -121,15 +121,15 @@ 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<Object> {
fn get_grant_object_by_oid(catalog_reader: &CatalogReader, db_name: &str, oid: i32) -> Result<Object> {
catalog_reader
.read_guard()
.get_database_by_name(db_name)
.map_err(|e| ExprError::InvalidParam {
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(),
Expand Down

0 comments on commit 9f903c0

Please sign in to comment.