|
| 1 | +use bitflags::bitflags; |
1 | 2 | use std::{ |
2 | 3 | fmt::{self, Debug, Display, Formatter}, |
3 | 4 | path::Path, |
@@ -27,6 +28,39 @@ pub trait UserDetail: Send + Sync + Display + Debug { |
27 | 28 | fn home(&self) -> Option<&Path> { |
28 | 29 | None |
29 | 30 | } |
| 31 | + |
| 32 | + /// Tells what the user is authorised to do in terms of FTP filesystem operations. |
| 33 | + /// |
| 34 | + /// The default implementation gives all permissions. |
| 35 | + fn storage_permissions(&self) -> StoragePermissions { |
| 36 | + StoragePermissions::all() |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +bitflags! { |
| 41 | + /// The FTP operations that can be enabled/disabled for the storage back-end. |
| 42 | + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 43 | + pub struct StoragePermissions: u32 { |
| 44 | + /// If set allows FTP make directory |
| 45 | + const MK_DIR = 0b00000001; |
| 46 | + /// If set allows FTP remove directory |
| 47 | + const RM_DIR = 0b00000010; |
| 48 | + /// If set allows FTP GET i.e. clients can download files. |
| 49 | + const GET = 0b00000100; |
| 50 | + /// If set allows FTP PUT i.e. clients can upload files. |
| 51 | + const PUT = 0b00001000; |
| 52 | + /// If set allows FTP DELE i.e. clients can remove files. |
| 53 | + const DEL = 0b00010000; |
| 54 | + /// If set allows FTP RENAME i.e. clients can rename directories and files |
| 55 | + const RENAME = 0b00100000; |
| 56 | + /// If set allows the extended SITE MD5 command to calculate checksums |
| 57 | + const MD5 = 0b01000000; |
| 58 | + /// If set allows clients to list the contents of a directory. |
| 59 | + const LIST = 0b10000000; |
| 60 | + |
| 61 | + /// Convenience aggregation of all the write operation bits. |
| 62 | + const WRITE_OPS = Self::MK_DIR.bits() | Self::RM_DIR.bits() | Self::PUT.bits() | Self::DEL.bits() | Self::RENAME.bits(); |
| 63 | + } |
30 | 64 | } |
31 | 65 |
|
32 | 66 | /// DefaultUser is a default implementation of the `UserDetail` trait that doesn't hold any user |
|
0 commit comments