Skip to content

Commit

Permalink
[BugFix] Fix bug the user has the query permission of mv, but cannot …
Browse files Browse the repository at this point in the history
…use database (StarRocks#28545)

Fixes #issue

## What type of PR is this:
- [x] BugFix
- [ ] Feature
- [ ] Enhancement
- [ ] Refactor
- [ ] UT
- [ ] Doc
- [ ] Tool

## Checklist:
- [ ] I have added test cases for my bug fix or my new feature
- [ ] This pr will affect users' behaviors
- [ ] This pr needs user documentation (for new or modified features or
behaviors)
  - [ ] I have added documentation for my new feature or new function

## Bugfix cherry-pick branch check:
- [ ] I have checked the version labels which the pr will be
auto-backported to the target branch
  - [ ] 3.1
  - [ ] 3.0
  - [ ] 2.5
  - [ ] 2.4

Signed-off-by: HangyuanLiu <[email protected]>
  • Loading branch information
HangyuanLiu committed Aug 8, 2023
1 parent 5ea6957 commit 68448bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
import com.starrocks.http.BaseAction;
import com.starrocks.http.BaseRequest;
import com.starrocks.http.BaseResponse;
import com.starrocks.http.HttpConnectContext;
import com.starrocks.privilege.AccessDeniedException;
import com.starrocks.http.UnauthorizedException;
import com.starrocks.qe.ConnectContext;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.ast.UserIdentity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void checkAnyActionOnMaterializedView(UserIdentity currentUser, Set<Long>

@Override
public void checkAnyActionOnAnyMaterializedView(UserIdentity currentUser, Set<Long> roleIds, String db) {
checkAnyActionOnView(currentUser, roleIds, new TableName(db, "*"));
checkAnyActionOnMaterializedView(currentUser, roleIds, new TableName(db, "*"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,22 @@ public void testGrantView() throws Exception {
new TableName("db", "view1"), PrivilegeType.ALTER);
}

@Test
public void testGrantMaterializedView() throws Exception {
DDLStmtExecutor.execute(UtFrameUtils.parseStmtWithNewParser(
"create user mv_user", ctx), ctx);
DDLStmtExecutor.execute(UtFrameUtils.parseStmtWithNewParser(
"grant select on materialized view db3.mv1 to mv_user", ctx), ctx);
UserIdentity user = UserIdentity.createAnalyzedUserIdentWithIp("mv_user", "%");
setCurrentUserAndRoles(ctx, user);
new NativeAccessControl().checkMaterializedViewAction(ctx.getCurrentUserIdentity(), ctx.getCurrentRoleIds(),
new TableName("db3", "mv1"), PrivilegeType.SELECT);
new NativeAccessControl().checkAnyActionOnMaterializedView(ctx.getCurrentUserIdentity(), ctx.getCurrentRoleIds(),
new TableName("db3", "mv1"));
new NativeAccessControl().checkAnyActionOnAnyMaterializedView(ctx.getCurrentUserIdentity(), ctx.getCurrentRoleIds(),
"db3");
}

@Test
public void testGrantBrief() throws Exception {
ctx.setDatabase("db");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.starrocks.sql.ast.ShowStmt;
import com.starrocks.sql.ast.StatementBase;
import com.starrocks.sql.ast.UserIdentity;
import com.starrocks.sql.common.StarRocksPlannerException;
import com.starrocks.sql.plan.ConnectorPlanTestBase;
import com.starrocks.statistic.AnalyzeJob;
import com.starrocks.statistic.AnalyzeMgr;
Expand Down

0 comments on commit 68448bc

Please sign in to comment.