main
rs 86 lines 2.14 KB
Raw
1 use super::ParticipantId;
2 use serde::{Deserialize, Serialize};
3 use uuid::Uuid;
4
5 #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
6 pub enum Role {
7 Reader,
8 Executor,
9 /// Executor, and can change ACLs of others
10 Full,
11 }
12
13 impl Role {
14 /// Returns true if this role has execution permissions.
15 pub fn can_execute(&self) -> bool {
16 matches!(self, Role::Executor | Role::Full)
17 }
18
19 /// Downgrades `Full` to `Executor` for clients that don't support the Full role.
20 pub fn downgrade_full(&mut self) {
21 if *self == Role::Full {
22 *self = Role::Executor;
23 }
24 }
25 }
26
27 impl Default for Role {
28 fn default() -> Self {
29 Self::Reader
30 }
31 }
32
33 #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
34 /// Info about different types of ACLs for a user.
35 pub struct AccessLevels {
36 /// The maximum ACL given to the user, could be direct, link-based, etc.
37 pub max_acl: Role,
38 /// The direct ACL given to the user.
39 pub direct_acl: Option<Role>,
40 }
41
42 /// An ID for a role request that is unique across all participants across all shared sessions.
43 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
44 pub struct RoleRequestId(String);
45
46 impl From<String> for RoleRequestId {
47 fn from(value: String) -> Self {
48 RoleRequestId(value)
49 }
50 }
51
52 impl RoleRequestId {
53 pub fn new() -> RoleRequestId {
54 RoleRequestId(Uuid::new_v4().to_string())
55 }
56 }
57
58 impl Default for RoleRequestId {
59 fn default() -> Self {
60 RoleRequestId::new()
61 }
62 }
63
64 impl std::fmt::Display for RoleRequestId {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 std::fmt::Display::fmt(&self.0, f)
67 }
68 }
69
70 #[derive(Serialize, Deserialize, Clone, Debug)]
71 pub enum RoleRequestRejectedReason {
72 RejectedBySharer,
73 }
74
75 #[derive(Serialize, Deserialize, Clone, Debug)]
76 pub enum RoleRequestResponse {
77 Approved { new_role: Role },
78 Rejected { reason: RoleRequestRejectedReason },
79 }
80
81 #[derive(Serialize, Deserialize, Clone, Debug)]
82 pub struct PendingRoleRequest {
83 participant_id: ParticipantId,
84 request_id: RoleRequestId,
85 role: Role,
86 }