tablo_core/declaration/area.rs
1//! The declaration mistakes of a panel's [`Area`](crate::Area)s.
2
3use std::fmt;
4
5/// Why an area cannot hold one of the pages auth serves:
6/// [`DeclarationErrorKind::Area`](super::DeclarationErrorKind::Area). Each names the page:
7/// `profile`, `two-factor` or `tenant settings`.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum AreaFault {
11 /// An area holds a page the panel's auth does not install.
12 ///
13 /// Install it on the panel's `Auth`, or take it out of the area.
14 AuthPageNotOffered(&'static str),
15 /// Two groups hold the same page auth serves, which mounts at one URL.
16 ///
17 /// Keep one.
18 AuthPagePlacedTwice(&'static str),
19 /// The def of a page auth serves declares what its page does not render: widgets, filters,
20 /// an access check or header actions.
21 ///
22 /// Drop it from the def.
23 AuthPageDeclares {
24 /// The page.
25 page: &'static str,
26 /// What the def declares.
27 feature: &'static str,
28 },
29 /// An area holds the audit log's list, but the panel keeps no audit log.
30 ///
31 /// Call `Panel::audit_log`, or take it out of the area.
32 AuditLogNotKept,
33 /// Two groups hold the audit log's list, which mounts at one URL.
34 ///
35 /// Keep one.
36 AuditLogPlacedTwice,
37}
38
39impl fmt::Display for AreaFault {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::AuthPageNotOffered(page) => write!(
43 f,
44 "an area holds the {page} page, which the panel's auth does not install: \
45 install it on the `Auth`, or take it out of the area"
46 ),
47 Self::AuthPagePlacedTwice(page) => write!(
48 f,
49 "two area groups hold the {page} page, which mounts at one URL: keep one"
50 ),
51 Self::AuthPageDeclares { page, feature } => write!(
52 f,
53 "the def of the {page} page declares {feature}, which the page does not render: \
54 drop them from the def"
55 ),
56 Self::AuditLogNotKept => f.write_str(
57 "an area holds the audit log, which the panel does not keep: call \
58 `Panel::audit_log`, or take it out of the area",
59 ),
60 Self::AuditLogPlacedTwice => {
61 f.write_str("two area groups hold the audit log, which mounts at one URL: keep one")
62 }
63 }
64 }
65}