gestura_core_foundation/
permissions.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
9#[serde(rename_all = "lowercase")]
10pub enum PermissionLevel {
11 Sandbox,
13 #[default]
15 Restricted,
16 Full,
18}
19
20impl PermissionLevel {
21 pub fn parse(s: &str) -> Self {
23 match s.to_lowercase().as_str() {
24 "sandbox" => Self::Sandbox,
25 "restricted" => Self::Restricted,
26 "full" => Self::Full,
27 _ => Self::default(),
28 }
29 }
30
31 pub fn allows_without_confirmation(&self, is_write_operation: bool) -> bool {
33 match self {
34 Self::Sandbox => !is_write_operation,
35 Self::Restricted => !is_write_operation,
36 Self::Full => true,
37 }
38 }
39
40 pub fn blocks(&self, is_write_operation: bool) -> bool {
42 match self {
43 Self::Sandbox => is_write_operation,
44 Self::Restricted => false,
45 Self::Full => false,
46 }
47 }
48
49 pub fn requires_confirmation(&self, is_write_operation: bool) -> bool {
51 match self {
52 Self::Sandbox => false, Self::Restricted => is_write_operation,
54 Self::Full => false,
55 }
56 }
57}