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
// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct User {
pub id: Uuid,
pub sub: String,
pub display_name: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewUser {
pub sub: String,
pub display_name: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UpdateUser {
pub id: Uuid,
pub sub: Option<String>,
pub display_name: Option<Option<String>>,
}
impl UpdateUser {
pub fn new(id: Uuid) -> Self {
Self {
id,
sub: None,
display_name: None,
}
}
// The naming collides with the `sub` function which is short for subtraction.
// In the authentication domain, `sub` is a well-established and specificed
// name for "subject", so we want to provide it under that name.
#[allow(clippy::should_implement_trait)]
pub fn sub(self, sub: String) -> Self {
Self {
sub: Some(sub),
..self
}
}
pub fn display_name(self, display_name: String) -> Self {
Self {
display_name: Some(Some(display_name)),
..self
}
}
}