Skip to main content

paperless_api/metadata/
permission.rs

1use serde::{Deserialize, Serialize};
2
3use crate::id::{GroupId, UserId};
4
5/// The permissions for a paperless item.
6///
7/// If full permissions are not explicitly requested, only the `Simple` variant is available.
8#[derive(Debug, Clone, Deserialize, Serialize)]
9#[serde(untagged)]
10pub enum ItemPermissions {
11    /// Full permissions.
12    Full { permissions: FullPermissions },
13
14    /// Simple permissions.
15    Simple { user_can_change: bool },
16}
17
18/// The full permissions for a paperless item.
19#[derive(Debug, Clone, Deserialize, Serialize)]
20pub struct FullPermissions {
21    /// The users and groups that can view the item.
22    pub view: Permission,
23
24    /// The users and groups that can change the item.
25    pub change: Permission,
26}
27
28/// A detailed permission for a paperless item.
29#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct Permission {
31    pub users: Vec<UserId>,
32    pub groups: Vec<GroupId>,
33}
34
35impl Default for ItemPermissions {
36    fn default() -> Self {
37        Self::Full {
38            permissions: FullPermissions {
39                view: Permission {
40                    users: Vec::new(),
41                    groups: Vec::new(),
42                },
43                change: Permission {
44                    users: Vec::new(),
45                    groups: Vec::new(),
46                },
47            },
48        }
49    }
50}