fix for USAGE or NONE privilege

This commit is contained in:
caspian 2021-07-16 16:53:25 +08:00
parent 6a05a7d51a
commit c06f45ea4f
3 changed files with 20 additions and 15 deletions

View File

@ -28,17 +28,20 @@ namespace
const ASTGrantQuery & query,
const std::vector<UUID> & roles_to_grant_or_revoke)
{
if (query.is_replace && !query.is_revoke)
{
if (roles_to_grant_or_revoke.empty())
grantee.access = {};
else
grantee.granted_roles = {};
}
if (!query.access_rights_elements.empty())
{
if (query.is_revoke)
grantee.access.revoke(query.access_rights_elements);
else
{
if (query.is_replace)
grantee.access = {};
grantee.access.grant(query.access_rights_elements);
}
}
if (!roles_to_grant_or_revoke.empty())
@ -52,9 +55,6 @@ namespace
}
else
{
if (query.is_replace)
grantee.granted_roles = {};
if (query.admin_option)
grantee.granted_roles.grantWithAdminOption(roles_to_grant_or_revoke);
else

View File

@ -102,18 +102,20 @@ ASTPtr ASTGrantQuery::clone() const
void ASTGrantQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
{
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << (attach_mode ? "ATTACH " : "") << (is_revoke ? "REVOKE" : "GRANT")
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << (attach_mode ? "ATTACH " : "")
<< (settings.hilite ? IAST::hilite_none : "");
if (!is_revoke && is_replace)
settings.ostr << (settings.hilite ? hilite_keyword : "") << "REPLACE" << (settings.hilite ? hilite_none : "");
settings.ostr << (is_revoke ? " REVOKE" : " GRANT");
if (!access_rights_elements.sameOptions())
throw Exception("Elements of an ASTGrantQuery are expected to have the same options", ErrorCodes::LOGICAL_ERROR);
if (!access_rights_elements.empty() && access_rights_elements[0].is_partial_revoke && !is_revoke)
throw Exception("A partial revoke should be revoked, not granted", ErrorCodes::LOGICAL_ERROR);
bool grant_option = !access_rights_elements.empty() && access_rights_elements[0].grant_option;
if (!is_revoke && is_replace)
settings.ostr << (settings.hilite ? hilite_keyword : "") << " BY REPLACE" << (settings.hilite ? hilite_none : "");
formatOnCluster(settings);
if (is_revoke)

View File

@ -231,15 +231,18 @@ bool ParserGrantQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (attach_mode && !ParserKeyword{"ATTACH"}.ignore(pos, expected))
return false;
bool is_revoke = false;
bool is_replace = false;
if (ParserKeyword{"REPLACE"}.ignore(pos, expected))
is_replace = true;
bool is_revoke = false;
if (ParserKeyword{"REVOKE"}.ignore(pos, expected))
is_revoke = true;
else if (!ParserKeyword{"GRANT"}.ignore(pos, expected))
return false;
if (!is_revoke && ParserKeyword{"BY REPLACE"}.ignore(pos, expected))
is_replace = true;
if (is_replace && is_revoke)
return false;
String cluster;
parseOnCluster(pos, expected, cluster);