1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// Helper struct to generate role strings for [Permission].
pub struct Role;
impl Role {
/// Grants access to anyone.
///
/// This includes authenticated and unauthenticated users.
pub fn any() -> String {
"any".to_string()
}
/// Grants access to a specific user by user ID.
///
/// You can optionally pass verified or unverified for
/// [status] to target specific types of users.
pub fn user(id: &str, status: Option<String>) -> String {
if status.is_none() {
return format!("user:{}", id);
}
format!("user:{}/{}", id, status.unwrap_or("".to_string()))
}
/// Grants access to any authenticated or anonymous user.
///
/// You can optionally pass verified or unverified for
/// [status] to target specific types of users.
pub fn users(status: Option<String>) -> String {
if status.is_none() {
return String::from("users");
}
format!("users/{}", status.unwrap_or("".to_string()))
}
/// Grants access to any guest user without a session.
///
/// Authenticated users don't have access to this role.
pub fn guests() -> String {
"guests".to_string()
}
/// Grants access to a team by team ID.
///
/// You can optionally pass a role for [role] to target
/// team members with the specified role.
pub fn team(id: &str, role: Option<String>) -> String {
if role.is_none() {
return format!("team:{}", id);
}
format!("team:{}/{}", id, role.unwrap_or("".to_string()))
}
/// Grants access to a specific member of a team.
///
/// When the member is removed from the team, they will
/// no longer have access.
pub fn member(id: &str) -> String {
format!("member:{}", id)
}
/// Grants access to a user with the specified label.
pub fn label(name: &str) -> String {
format!("label:{}", name)
}
}