wekan_cli/command_result/users/
tokens.rs1use secrecy::{ExposeSecret, SecretString};
2use serde::{Serialize, Serializer};
3
4#[derive(Debug, Serialize)]
5pub struct UserTokenCreateSuccess {
6 pub user_id: String,
7 #[serde(serialize_with = "serialize_issued_token")]
8 auth_token: SecretString,
9 pub creation_requested: bool,
10 pub mutation_confirmed: bool,
11}
12
13impl UserTokenCreateSuccess {
14 pub fn new(user_id: String, auth_token: SecretString) -> Self {
15 Self {
16 user_id,
17 auth_token,
18 creation_requested: true,
19 mutation_confirmed: false,
20 }
21 }
22
23 pub fn auth_token(&self) -> &SecretString {
24 &self.auth_token
25 }
26}
27
28impl PartialEq for UserTokenCreateSuccess {
29 fn eq(&self, other: &Self) -> bool {
30 self.user_id == other.user_id
31 && self.auth_token.expose_secret() == other.auth_token.expose_secret()
32 && self.creation_requested == other.creation_requested
33 && self.mutation_confirmed == other.mutation_confirmed
34 }
35}
36impl Eq for UserTokenCreateSuccess {}
37
38fn serialize_issued_token<S: Serializer>(token: &SecretString, s: S) -> Result<S::Ok, S::Error> {
39 s.serialize_str(token.expose_secret())
40}
41
42#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
43#[serde(rename_all = "snake_case")]
44pub enum UserTokenDeleteScope {
45 Single,
46 All,
47}
48
49#[derive(Debug, Eq, PartialEq, Serialize)]
50pub struct UserTokenDeleteSuccess {
51 pub user_id: String,
52 pub scope: UserTokenDeleteScope,
53 pub message: String,
54 pub deletion_requested: bool,
55 pub mutation_confirmed: bool,
56}