Skip to main content

raps_admin/
types.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2025 Dmytro Yemelianov
3
4//! Core types for bulk admin operations
5
6use serde::{Deserialize, Serialize};
7
8/// Type of bulk operation
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum OperationType {
12    /// Add user to projects
13    AddUser,
14    /// Remove user from projects
15    RemoveUser,
16    /// Update user role across projects
17    UpdateRole,
18    /// Update folder permissions across projects
19    UpdateFolderRights,
20}
21
22impl std::fmt::Display for OperationType {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            OperationType::AddUser => write!(f, "add_user"),
26            OperationType::RemoveUser => write!(f, "remove_user"),
27            OperationType::UpdateRole => write!(f, "update_role"),
28            OperationType::UpdateFolderRights => write!(f, "update_folder_rights"),
29        }
30    }
31}
32
33/// Status of a bulk operation
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35#[serde(rename_all = "snake_case")]
36pub enum OperationStatus {
37    /// Operation created but not started
38    Pending,
39    /// Operation currently running
40    InProgress,
41    /// Operation completed successfully
42    Completed,
43    /// Operation was cancelled by user
44    Cancelled,
45    /// Operation failed to complete
46    Failed,
47}
48
49impl std::fmt::Display for OperationStatus {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        match self {
52            OperationStatus::Pending => write!(f, "pending"),
53            OperationStatus::InProgress => write!(f, "in_progress"),
54            OperationStatus::Completed => write!(f, "completed"),
55            OperationStatus::Cancelled => write!(f, "cancelled"),
56            OperationStatus::Failed => write!(f, "failed"),
57        }
58    }
59}
60
61/// Folder types for permission management
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63#[serde(rename_all = "snake_case")]
64pub enum FolderType {
65    /// Project Files folder
66    ProjectFiles,
67    /// Plans folder
68    Plans,
69    /// Custom folder path
70    Custom(String),
71}
72
73/// Permission levels for folder access
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
75#[serde(rename_all = "snake_case")]
76pub enum PermissionLevel {
77    /// View only access
78    ViewOnly,
79    /// View and download
80    ViewDownload,
81    /// Upload only (publish)
82    UploadOnly,
83    /// View, download, and upload
84    ViewDownloadUpload,
85    /// View, download, upload, and edit
86    ViewDownloadUploadEdit,
87    /// Full folder control
88    FolderControl,
89}
90
91impl PermissionLevel {
92    /// Convert to API actions array
93    pub fn to_actions(&self) -> Vec<&'static str> {
94        match self {
95            PermissionLevel::ViewOnly => vec!["VIEW", "COLLABORATE"],
96            PermissionLevel::ViewDownload => vec!["VIEW", "DOWNLOAD", "COLLABORATE"],
97            PermissionLevel::UploadOnly => vec!["PUBLISH"],
98            PermissionLevel::ViewDownloadUpload => {
99                vec!["PUBLISH", "VIEW", "DOWNLOAD", "COLLABORATE"]
100            }
101            PermissionLevel::ViewDownloadUploadEdit => {
102                vec!["PUBLISH", "VIEW", "DOWNLOAD", "COLLABORATE", "EDIT"]
103            }
104            PermissionLevel::FolderControl => {
105                vec![
106                    "PUBLISH",
107                    "VIEW",
108                    "DOWNLOAD",
109                    "COLLABORATE",
110                    "EDIT",
111                    "CONTROL",
112                ]
113            }
114        }
115    }
116}