Skip to main content

uqa_sql/catalog/security/
acl_warning.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The warning of a `GRANT` or `REVOKE` that changes fewer privileges than it names.
8
9use crate::SQLNotice;
10
11/// The warning `PostgreSQL`'s `restrict_and_check_grant` reports when the grantor holds the grant option for none of the privileges a `GRANT` or `REVOKE` of `name` names, or, when `partial`, for only some of them: SQLSTATE `01007` (`warning_privilege_not_granted`) for a grant and `01006` (`warning_privilege_not_revoked`) for a revocation.
12pub fn acl_warning(is_grant: bool, partial: bool, name: &str) -> SQLNotice {
13    let (message, sqlstate) = match (is_grant, partial) {
14        (true, true) => (
15            format!("not all privileges were granted for \"{name}\""),
16            "01007",
17        ),
18        (true, false) => (
19            format!("no privileges were granted for \"{name}\""),
20            "01007",
21        ),
22        (false, true) => (
23            format!("not all privileges could be revoked for \"{name}\""),
24            "01006",
25        ),
26        (false, false) => (
27            format!("no privileges could be revoked for \"{name}\""),
28            "01006",
29        ),
30    };
31    SQLNotice::warning(message).with_sqlstate(sqlstate)
32}