mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 02:12:21 +00:00
495c6e03aa
* Replace all Context references with std::weak_ptr * Fix shared context captured by value * Fix build * Fix Context with named sessions * Fix copy context * Fix gcc build * Merge with master and fix build * Fix gcc-9 build
71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
#include <Interpreters/InterpreterDropAccessEntityQuery.h>
|
|
#include <Parsers/ASTDropAccessEntityQuery.h>
|
|
#include <Parsers/ASTRowPolicyName.h>
|
|
#include <Interpreters/Context.h>
|
|
#include <Interpreters/executeDDLQueryOnCluster.h>
|
|
#include <Access/AccessControlManager.h>
|
|
#include <Access/AccessFlags.h>
|
|
#include <Access/User.h>
|
|
#include <Access/Role.h>
|
|
#include <Access/Quota.h>
|
|
#include <Access/RowPolicy.h>
|
|
#include <Access/SettingsProfile.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int NOT_IMPLEMENTED;
|
|
}
|
|
|
|
using EntityType = IAccessEntity::Type;
|
|
|
|
|
|
BlockIO InterpreterDropAccessEntityQuery::execute()
|
|
{
|
|
auto & query = query_ptr->as<ASTDropAccessEntityQuery &>();
|
|
auto & access_control = getContext()->getAccessControlManager();
|
|
getContext()->checkAccess(getRequiredAccess());
|
|
|
|
if (!query.cluster.empty())
|
|
return executeDDLQueryOnCluster(query_ptr, getContext());
|
|
|
|
query.replaceEmptyDatabase(getContext()->getCurrentDatabase());
|
|
|
|
auto do_drop = [&](const Strings & names)
|
|
{
|
|
if (query.if_exists)
|
|
access_control.tryRemove(access_control.find(query.type, names));
|
|
else
|
|
access_control.remove(access_control.getIDs(query.type, names));
|
|
};
|
|
|
|
if (query.type == EntityType::ROW_POLICY)
|
|
do_drop(query.row_policy_names->toStrings());
|
|
else
|
|
do_drop(query.names);
|
|
|
|
return {};
|
|
}
|
|
|
|
|
|
AccessRightsElements InterpreterDropAccessEntityQuery::getRequiredAccess() const
|
|
{
|
|
const auto & query = query_ptr->as<const ASTDropAccessEntityQuery &>();
|
|
AccessRightsElements res;
|
|
switch (query.type)
|
|
{
|
|
case EntityType::USER: res.emplace_back(AccessType::DROP_USER); return res;
|
|
case EntityType::ROLE: res.emplace_back(AccessType::DROP_ROLE); return res;
|
|
case EntityType::SETTINGS_PROFILE: res.emplace_back(AccessType::DROP_SETTINGS_PROFILE); return res;
|
|
case EntityType::ROW_POLICY: res.emplace_back(AccessType::DROP_ROW_POLICY); return res;
|
|
case EntityType::QUOTA: res.emplace_back(AccessType::DROP_QUOTA); return res;
|
|
case EntityType::MAX: break;
|
|
}
|
|
throw Exception(
|
|
toString(query.type) + ": type is not supported by DROP query", ErrorCodes::NOT_IMPLEMENTED);
|
|
}
|
|
|
|
}
|