+85 -2 +/-4 browse
1 | diff --git a/cli/src/args.rs b/cli/src/args.rs |
2 | index 98dc512..eb65f52 100644 |
3 | --- a/cli/src/args.rs |
4 | +++ b/cli/src/args.rs |
5 | @@ -329,6 +329,8 @@ pub struct AccountOptions { |
6 | pub enum ListCommand { |
7 | /// List subscriptions of list. |
8 | Subscriptions, |
9 | + /// List subscription requests. |
10 | + SubscriptionRequests, |
11 | /// Add subscription to list. |
12 | AddSubscription { |
13 | /// E-mail address. |
14 | @@ -350,6 +352,11 @@ pub enum ListCommand { |
15 | #[clap(flatten)] |
16 | subscription_options: SubscriptionOptions, |
17 | }, |
18 | + /// Accept a subscription request by its primary key. |
19 | + AcceptSubscriptionRequest { |
20 | + /// The primary key of the request. |
21 | + pk: i64, |
22 | + }, |
23 | /// Add a new post policy. |
24 | AddPostPolicy { |
25 | #[arg(long)] |
26 | diff --git a/cli/src/main.rs b/cli/src/main.rs |
27 | index e3e71fe..62aa476 100644 |
28 | --- a/cli/src/main.rs |
29 | +++ b/cli/src/main.rs |
30 | @@ -482,6 +482,26 @@ fn run_app(opt: Opt) -> Result<()> { |
31 | tx.commit()?; |
32 | } |
33 | } |
34 | + SubscriptionRequests => { |
35 | + let subscriptions = db.list_subscription_requests(list.pk)?; |
36 | + if subscriptions.is_empty() { |
37 | + println!("No subscription requests found."); |
38 | + } else { |
39 | + println!("Subscription requests of list {}", list.id); |
40 | + for l in subscriptions { |
41 | + println!("- {}", &l); |
42 | + } |
43 | + } |
44 | + } |
45 | + AcceptSubscriptionRequest { pk } => match db.accept_candidate_subscription(pk) { |
46 | + Ok(subscription) => { |
47 | + println!("Added: {subscription:#?}"); |
48 | + } |
49 | + Err(err) => { |
50 | + eprintln!("Could not accept subscription request!"); |
51 | + return Err(err); |
52 | + } |
53 | + }, |
54 | } |
55 | } |
56 | CreateList { |
57 | diff --git a/core/src/subscriptions.rs b/core/src/subscriptions.rs |
58 | index f25ffb9..cb6edbf 100644 |
59 | --- a/core/src/subscriptions.rs |
60 | +++ b/core/src/subscriptions.rs |
61 | @@ -33,11 +33,11 @@ use crate::{ |
62 | |
63 | impl Connection { |
64 | /// Fetch all subscriptions of a mailing list. |
65 | - pub fn list_subscriptions(&self, pk: i64) -> Result<Vec<DbVal<ListSubscription>>> { |
66 | + pub fn list_subscriptions(&self, list_pk: i64) -> Result<Vec<DbVal<ListSubscription>>> { |
67 | let mut stmt = self |
68 | .connection |
69 | .prepare("SELECT * FROM subscription WHERE list = ?;")?; |
70 | - let list_iter = stmt.query_map([&pk], |row| { |
71 | + let list_iter = stmt.query_map([&list_pk], |row| { |
72 | let pk = row.get("pk")?; |
73 | Ok(DbVal( |
74 | ListSubscription { |
75 | @@ -186,6 +186,36 @@ impl Connection { |
76 | self.list_subscription(list_pk, val.pk()) |
77 | } |
78 | |
79 | + /// Fetch all candidate subscriptions of a mailing list. |
80 | + pub fn list_subscription_requests( |
81 | + &self, |
82 | + list_pk: i64, |
83 | + ) -> Result<Vec<DbVal<ListCandidateSubscription>>> { |
84 | + let mut stmt = self |
85 | + .connection |
86 | + .prepare("SELECT * FROM candidate_subscription WHERE list = ?;")?; |
87 | + let list_iter = stmt.query_map([&list_pk], |row| { |
88 | + let pk = row.get("pk")?; |
89 | + Ok(DbVal( |
90 | + ListCandidateSubscription { |
91 | + pk: row.get("pk")?, |
92 | + list: row.get("list")?, |
93 | + address: row.get("address")?, |
94 | + name: row.get("name")?, |
95 | + accepted: row.get("accepted")?, |
96 | + }, |
97 | + pk, |
98 | + )) |
99 | + })?; |
100 | + |
101 | + let mut ret = vec![]; |
102 | + for list in list_iter { |
103 | + let list = list?; |
104 | + ret.push(list); |
105 | + } |
106 | + Ok(ret) |
107 | + } |
108 | + |
109 | /// Create subscription candidate. |
110 | pub fn add_candidate_subscription( |
111 | &self, |
112 | diff --git a/docs/mpot.1 b/docs/mpot.1 |
113 | index f950b67..8331f07 100644 |
114 | --- a/docs/mpot.1 |
115 | +++ b/docs/mpot.1 |
116 | @@ -150,6 +150,16 @@ List subscriptions of list. |
117 | .ie \n(.g .ds Aq \(aq |
118 | .el .ds Aq ' |
119 | .\fB |
120 | + .SS mpot list subscription-requests |
121 | + .\fR |
122 | + .br |
123 | + |
124 | + .br |
125 | + |
126 | + List subscription requests. |
127 | + .ie \n(.g .ds Aq \(aq |
128 | + .el .ds Aq ' |
129 | + .\fB |
130 | .SS mpot list add-subscription |
131 | .\fR |
132 | .br |
133 | @@ -330,6 +340,22 @@ Is subscription enabled. |
134 | .ie \n(.g .ds Aq \(aq |
135 | .el .ds Aq ' |
136 | .\fB |
137 | + .SS mpot list accept-subscription-request |
138 | + .\fR |
139 | + .br |
140 | + |
141 | + .br |
142 | + |
143 | + mpot list accept\-subscription\-request \fIPK\fR |
144 | + .br |
145 | + |
146 | + Accept a subscription request by its primary key. |
147 | + .TP |
148 | + \fIPK\fR |
149 | + The primary key of the request. |
150 | + .ie \n(.g .ds Aq \(aq |
151 | + .el .ds Aq ' |
152 | + .\fB |
153 | .SS mpot list add-post-policy |
154 | .\fR |
155 | .br |