Skip to content

Commit

Permalink
improve: improve drop system role error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuoTiJia committed Nov 21, 2023
1 parent 9581998 commit ea2eb15
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions query_server/query/src/sql/planner.rs
Expand Up @@ -427,6 +427,11 @@ impl<'a, S: ContextProviderExtension + Send + Sync + 'a> SqlPlanner<'a, S> {
}
TenantObjectType::Role => {
let role_name = normalize_ident(object_name);

if SystemTenantRole::try_from(role_name.as_str()).is_ok() {
return Err(QueryError::ForbiddenDropSystemRole { role: role_name });
}

(
DDLPlan::DropTenantObject(DropTenantObject {
tenant_name: tenant_name.to_string(),
Expand Down
6 changes: 6 additions & 0 deletions query_server/spi/src/lib.rs
Expand Up @@ -501,6 +501,12 @@ pub enum QueryError {
ForbiddenLimitTenant {
tenant: String,
},

#[snafu(display("Couldn't Drop System Role {}", role))]
#[error_code(code = 76)]
ForbiddenDropSystemRole {
role: String,
},
}

impl From<ParserError> for QueryError {
Expand Down
10 changes: 10 additions & 0 deletions query_server/test/cases/sys_table/information_schema/roles.result
Expand Up @@ -70,3 +70,13 @@ role_name,role_type,inherit_role
member,system,
owner,system,
test_rs_role1,custom,member

-- EXECUTE SQL: drop role owner; --
422 Unprocessable Entity
{"error_code":"010076","error_message":"Couldn't Drop System Role owner"}
-- ERROR: --

-- EXECUTE SQL: drop role member; --
422 Unprocessable Entity
{"error_code":"010076","error_message":"Couldn't Drop System Role member"}
-- ERROR: --
Expand Up @@ -38,3 +38,9 @@ alter tenant test_rs_tenant1 remove user test_rs_u2;
--#SORT=true
select * from information_schema.ROLES;

--#TENANT=cnosdb
--#USER_NAME=root

drop role owner;

drop role member;

0 comments on commit ea2eb15

Please sign in to comment.