mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
fix for USAGE or NONE privilege
This commit is contained in:
parent
6a05a7d51a
commit
c06f45ea4f
@ -28,17 +28,20 @@ namespace
|
|||||||
const ASTGrantQuery & query,
|
const ASTGrantQuery & query,
|
||||||
const std::vector<UUID> & roles_to_grant_or_revoke)
|
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.access_rights_elements.empty())
|
||||||
{
|
{
|
||||||
if (query.is_revoke)
|
if (query.is_revoke)
|
||||||
grantee.access.revoke(query.access_rights_elements);
|
grantee.access.revoke(query.access_rights_elements);
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (query.is_replace)
|
|
||||||
grantee.access = {};
|
|
||||||
|
|
||||||
grantee.access.grant(query.access_rights_elements);
|
grantee.access.grant(query.access_rights_elements);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!roles_to_grant_or_revoke.empty())
|
if (!roles_to_grant_or_revoke.empty())
|
||||||
@ -52,9 +55,6 @@ namespace
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (query.is_replace)
|
|
||||||
grantee.granted_roles = {};
|
|
||||||
|
|
||||||
if (query.admin_option)
|
if (query.admin_option)
|
||||||
grantee.granted_roles.grantWithAdminOption(roles_to_grant_or_revoke);
|
grantee.granted_roles.grantWithAdminOption(roles_to_grant_or_revoke);
|
||||||
else
|
else
|
||||||
|
@ -102,18 +102,20 @@ ASTPtr ASTGrantQuery::clone() const
|
|||||||
|
|
||||||
void ASTGrantQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) 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 : "");
|
<< (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())
|
if (!access_rights_elements.sameOptions())
|
||||||
throw Exception("Elements of an ASTGrantQuery are expected to have the same options", ErrorCodes::LOGICAL_ERROR);
|
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)
|
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);
|
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;
|
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);
|
formatOnCluster(settings);
|
||||||
|
|
||||||
if (is_revoke)
|
if (is_revoke)
|
||||||
|
@ -231,15 +231,18 @@ bool ParserGrantQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|||||||
if (attach_mode && !ParserKeyword{"ATTACH"}.ignore(pos, expected))
|
if (attach_mode && !ParserKeyword{"ATTACH"}.ignore(pos, expected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool is_revoke = false;
|
|
||||||
bool is_replace = false;
|
bool is_replace = false;
|
||||||
|
if (ParserKeyword{"REPLACE"}.ignore(pos, expected))
|
||||||
|
is_replace = true;
|
||||||
|
|
||||||
|
bool is_revoke = false;
|
||||||
if (ParserKeyword{"REVOKE"}.ignore(pos, expected))
|
if (ParserKeyword{"REVOKE"}.ignore(pos, expected))
|
||||||
is_revoke = true;
|
is_revoke = true;
|
||||||
else if (!ParserKeyword{"GRANT"}.ignore(pos, expected))
|
else if (!ParserKeyword{"GRANT"}.ignore(pos, expected))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!is_revoke && ParserKeyword{"BY REPLACE"}.ignore(pos, expected))
|
if (is_replace && is_revoke)
|
||||||
is_replace = true;
|
return false;
|
||||||
|
|
||||||
String cluster;
|
String cluster;
|
||||||
parseOnCluster(pos, expected, cluster);
|
parseOnCluster(pos, expected, cluster);
|
||||||
|
Loading…
Reference in New Issue
Block a user