You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/24 11:42:07 UTC

[GitHub] [shardingsphere] RaigorJiang commented on a diff in pull request #21722: authority type DATABASE_PERMITTED not apply correctly for some account when there are multi accounts #21615

RaigorJiang commented on code in PR #21722:
URL: https://github.com/apache/shardingsphere/pull/21722#discussion_r1003215184


##########
proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java:
##########
@@ -84,7 +86,12 @@ private String getFirstDatabaseName() {
         if (databaseNames.isEmpty()) {
             throw new NoDatabaseSelectedException();
         }
-        Optional<String> result = databaseNames.stream().filter(each -> ProxyContext.getInstance().getDatabase(each).containsDataSource()).findFirst();
+        AuthorityRule authorityRule = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(
+                AuthorityRule.class);
+        Optional<ShardingSpherePrivileges> privileges = authorityRule.findPrivileges(connectionSession.getGrantee());
+        Optional<String> result = privileges.isPresent() ? databaseNames.stream().filter(each -> privileges.get().hasPrivileges(each)

Review Comment:
   Hi @wallacezhou ,
   Welcome, your PR provides a working solution, but please don't do complicated logical operations in the ternary operator, can you extract the judgment condition as a variable?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org