This is an automated email from the ASF dual-hosted git repository.

wangbo pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 2edb9501b50 [Pick]Fix show role stmt missing grouo info (#37920)
2edb9501b50 is described below

commit 2edb9501b500e4d7353bcef0135c29fccd1ff313
Author: wangbo <wan...@apache.org>
AuthorDate: Tue Jul 16 20:41:59 2024 +0800

    [Pick]Fix show role stmt missing grouo info (#37920)
    
    ## Proposed changes
    
    pick #36032
---
 .../org/apache/doris/analysis/ShowRolesStmt.java   |  1 +
 .../apache/doris/mysql/privilege/RoleManager.java  |  3 +-
 .../org/apache/doris/mysql/privilege/AuthTest.java | 42 ++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowRolesStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowRolesStmt.java
index 52c5bd75765..87db511176d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowRolesStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowRolesStmt.java
@@ -41,6 +41,7 @@ public class ShowRolesStmt extends ShowStmt {
         builder.addColumn(new Column("DatabasePrivs", 
ScalarType.createVarchar(300)));
         builder.addColumn(new Column("TablePrivs", 
ScalarType.createVarchar(300)));
         builder.addColumn(new Column("ResourcePrivs", 
ScalarType.createVarchar(300)));
+        builder.addColumn(new Column("WorkloadGroupPrivs", 
ScalarType.createVarchar(300)));
 
         META_DATA = builder.build();
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/RoleManager.java 
b/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/RoleManager.java
index e5654b6598c..bc4344c2b89 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/RoleManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/RoleManager.java
@@ -174,7 +174,8 @@ public class RoleManager implements Writable, 
GsonPostProcessable {
                                 }
                             }, (s1, s2) -> s1 + " " + s2
                     ));
-            Stream.of(PrivLevel.GLOBAL, PrivLevel.CATALOG, PrivLevel.DATABASE, 
PrivLevel.TABLE, PrivLevel.RESOURCE)
+            Stream.of(PrivLevel.GLOBAL, PrivLevel.CATALOG, PrivLevel.DATABASE, 
PrivLevel.TABLE, PrivLevel.RESOURCE,
+                            PrivLevel.WORKLOAD_GROUP)
                     .forEach(level -> {
                         String infoItem = infoMap.get(level);
                         if (Strings.isNullOrEmpty(infoItem)) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/AuthTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/AuthTest.java
index baedd1483d4..69d612223c5 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/AuthTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/AuthTest.java
@@ -54,6 +54,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
@@ -2439,4 +2440,45 @@ public class AuthTest {
         Assert.assertTrue(
                 auth.checkPlainPasswordForTest("root", "192.168.0.1", 
"validRootPassword", null));
     }
+
+    @Test
+    public void testShowRoles() {
+        String role = "test_wg_role";
+        CreateRoleStmt roleStmt = new CreateRoleStmt(role);
+        try {
+            roleStmt.analyze(analyzer);
+            auth.createRole(roleStmt);
+        } catch (UserException e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+
+        AccessPrivilege accessPrivilege = 
AccessPrivilege.fromName("USAGE_PRIV");
+        AccessPrivilegeWithCols apwc = new 
AccessPrivilegeWithCols(accessPrivilege);
+        List<AccessPrivilegeWithCols> list = new ArrayList<>();
+        list.add(apwc);
+        WorkloadGroupPattern wgp = new WorkloadGroupPattern("test_wg");
+        GrantStmt grantStmt = new GrantStmt(null, role, wgp, list);
+        try {
+            grantStmt.analyze(analyzer);
+            auth.grant(grantStmt);
+        } catch (UserException e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+
+        List<List<String>> showInfo = auth.getRoleInfo();
+        boolean findWgPriv = false;
+        for (int i = 0; i < showInfo.size(); i++) {
+            List<String> row = showInfo.get(i);
+            String name = row.get(0);
+            if (role.equals(name)) {
+                findWgPriv = true;
+                String wgPriv = row.get(row.size() - 1);
+                Assert.assertTrue("test_wg: Usage_priv".equals(wgPriv));
+            }
+        }
+        Assert.assertTrue(findWgPriv);
+
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to