1#include <Interpreters/InterpreterDropAccessEntityQuery.h>
2#include <Parsers/ASTDropAccessEntityQuery.h>
3#include <Interpreters/Context.h>
4#include <Access/AccessControlManager.h>
5#include <Access/Quota.h>
6#include <Access/RowPolicy.h>
7#include <boost/range/algorithm/transform.hpp>
8
9
10namespace DB
11{
12BlockIO InterpreterDropAccessEntityQuery::execute()
13{
14 const auto & query = query_ptr->as<const ASTDropAccessEntityQuery &>();
15 auto & access_control = context.getAccessControlManager();
16 using Kind = ASTDropAccessEntityQuery::Kind;
17
18 switch (query.kind)
19 {
20 case Kind::QUOTA:
21 {
22 context.checkQuotaManagementIsAllowed();
23 if (query.if_exists)
24 access_control.tryRemove(access_control.find<Quota>(query.names));
25 else
26 access_control.remove(access_control.getIDs<Quota>(query.names));
27 return {};
28 }
29 case Kind::ROW_POLICY:
30 {
31 context.checkRowPolicyManagementIsAllowed();
32 Strings full_names;
33 boost::range::transform(
34 query.row_policies_names, std::back_inserter(full_names),
35 [this](const RowPolicy::FullNameParts & row_policy_name) { return row_policy_name.getFullName(context); });
36 if (query.if_exists)
37 access_control.tryRemove(access_control.find<RowPolicy>(full_names));
38 else
39 access_control.remove(access_control.getIDs<RowPolicy>(full_names));
40 return {};
41 }
42 }
43
44 __builtin_unreachable();
45}
46}
47