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
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::deserializers::string_list_deserializer;
use super::{
permission::PermissionLevel, MongoId, ResourceTargetVariant, I64,
};
/// Permission users at the group level.
///
/// All users that are part of a group inherit the group's permissions.
/// A user can be a part of multiple groups. A user's permission on a particular resource
/// will be resolved to be the maximum permission level between the user's own permissions and
/// any groups they are a part of.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(
feature = "mongo",
derive(mongo_indexed::derive::MongoIndexed)
)]
pub struct UserGroup {
/// The Mongo ID of the UserGroup.
/// This field is de/serialized from/to JSON as
/// `{ "_id": { "$oid": "..." }, ...(rest of serialized User) }`
#[serde(
default,
rename = "_id",
skip_serializing_if = "String::is_empty",
with = "bson::serde_helpers::hex_string_as_object_id"
)]
pub id: MongoId,
/// A name for the user group
#[cfg_attr(feature = "mongo", unique_index)]
pub name: String,
/// User ids of group members
#[cfg_attr(feature = "mongo", index)]
#[serde(default, deserialize_with = "string_list_deserializer")]
pub users: Vec<String>,
/// Give the user group elevated permissions on all resources of a certain type
#[serde(default)]
pub all: HashMap<ResourceTargetVariant, PermissionLevel>,
/// Unix time (ms) when user group last updated
#[serde(default)]
pub updated_at: I64,
}