Skip to main content

ephemeris_forge/access/
operation.rs

1use std::fmt;
2
3use super::{TeamName, UserName};
4
5/// A write to team or collaborator grants that every forge has.
6///
7/// `P` is the forge's permission type.
8#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum AccessOperation<P> {
10    /// Grant a team access to the repository.
11    AddTeam {
12        /// The team to grant.
13        team: TeamName,
14        /// The permission to grant.
15        permission: P,
16    },
17    /// Remove a direct team grant from the repository.
18    RemoveTeam {
19        /// The team to remove.
20        team: TeamName,
21    },
22    /// Grant a user access, or change the permission of an existing grant.
23    AddCollaborator {
24        /// The user to grant.
25        user: UserName,
26        /// The permission to grant.
27        permission: P,
28    },
29    /// Remove a direct collaborator grant.
30    RemoveCollaborator {
31        /// The user to remove.
32        user: UserName,
33    },
34}
35
36impl<P> fmt::Display for AccessOperation<P> {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Self::AddTeam {
40                team,
41                permission: _,
42            }
43            | Self::RemoveTeam { team } => write!(f, "team {team}"),
44            Self::AddCollaborator {
45                user,
46                permission: _,
47            }
48            | Self::RemoveCollaborator { user } => write!(f, "collaborator {user}"),
49        }
50    }
51}