1
/*
2
 * This file is part of mailpot
3
 *
4
 * Copyright 2020 - Manos Pitsidianakis
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 */
19

            
20
//! Changeset structs: update specific struct fields.
21

            
22
macro_rules! impl_display {
23
    ($t:ty) => {
24
        impl std::fmt::Display for $t {
25
            fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
26
                write!(fmt, "{:?}", self)
27
            }
28
        }
29
    };
30
}
31

            
32
/// Changeset struct for [`Mailinglist`](super::MailingList).
33
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
34
pub struct MailingListChangeset {
35
    /// Database primary key.
36
    pub pk: i64,
37
    /// Optional new value.
38
    pub name: Option<String>,
39
    /// Optional new value.
40
    pub id: Option<String>,
41
    /// Optional new value.
42
    pub address: Option<String>,
43
    /// Optional new value.
44
    pub description: Option<Option<String>>,
45
    /// Optional new value.
46
    pub archive_url: Option<Option<String>>,
47
    /// Optional new value.
48
    pub owner_local_part: Option<Option<String>>,
49
    /// Optional new value.
50
    pub request_local_part: Option<Option<String>>,
51
    /// Optional new value.
52
    pub verify: Option<bool>,
53
    /// Optional new value.
54
    pub hidden: Option<bool>,
55
    /// Optional new value.
56
    pub enabled: Option<bool>,
57
}
58

            
59
impl_display!(MailingListChangeset);
60

            
61
/// Changeset struct for [`ListSubscription`](super::ListSubscription).
62
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
63
pub struct ListSubscriptionChangeset {
64
    /// Mailing list foreign key (See [`MailingList`](super::MailingList)).
65
    pub list: i64,
66
    /// Subscription e-mail address.
67
    pub address: String,
68
    /// Optional new value.
69
    pub account: Option<Option<i64>>,
70
    /// Optional new value.
71
    pub name: Option<Option<String>>,
72
    /// Optional new value.
73
    pub digest: Option<bool>,
74
    /// Optional new value.
75
    pub enabled: Option<bool>,
76
    /// Optional new value.
77
    pub verified: Option<bool>,
78
    /// Optional new value.
79
    pub hide_address: Option<bool>,
80
    /// Optional new value.
81
    pub receive_duplicates: Option<bool>,
82
    /// Optional new value.
83
    pub receive_own_posts: Option<bool>,
84
    /// Optional new value.
85
    pub receive_confirmation: Option<bool>,
86
}
87

            
88
impl_display!(ListSubscriptionChangeset);
89

            
90
/// Changeset struct for [`ListOwner`](super::ListOwner).
91
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
92
pub struct ListOwnerChangeset {
93
    /// Database primary key.
94
    pub pk: i64,
95
    /// Mailing list foreign key (See [`MailingList`](super::MailingList)).
96
    pub list: i64,
97
    /// Optional new value.
98
    pub address: Option<String>,
99
    /// Optional new value.
100
    pub name: Option<Option<String>>,
101
}
102

            
103
impl_display!(ListOwnerChangeset);
104

            
105
/// Changeset struct for [`Account`](super::Account).
106
6
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
107
pub struct AccountChangeset {
108
    /// Account e-mail address.
109
3
    pub address: String,
110
    /// Optional new value.
111
3
    pub name: Option<Option<String>>,
112
    /// Optional new value.
113
3
    pub public_key: Option<Option<String>>,
114
    /// Optional new value.
115
3
    pub password: Option<String>,
116
    /// Optional new value.
117
3
    pub enabled: Option<Option<bool>>,
118
}
119

            
120
impl_display!(AccountChangeset);