wekan-cli 0.18.0

Agent-first, human-friendly command-line client for Wekan
Documentation
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
use super::input;
use crate::client::admin::{PreparedSettingsUpdate, settings::UpdateGlobalSettings};
use crate::{
    client::WekanClientFactory,
    command_result::*,
    commands::{
        authenticated::AuthenticatedContext,
        client_error::{map_client_error, map_partial_mutation_client_error_with_not_found},
    },
    credentials::CredentialStore,
    error::AppError,
    redaction::Redactor,
};
use clap::{ArgGroup, Args, Subcommand};
#[derive(Debug, Args)]
pub struct SettingsArgs {
    #[command(subcommand)]
    pub command: SettingsCommand,
}
#[derive(Debug, Subcommand)]
pub enum SettingsCommand {
    /// Return the complete mapped settings document.
    Get,
    /// Apply native settings updates, with no read-before-write merging.
    Update(Box<UpdateArgs>),
}
#[derive(Debug, Args)]
#[command(group(ArgGroup::new("setting_flags").args([
    "disable_registration",
    "disable_forgot_password",
    "product_name",
    "display_authentication_method",
    "default_authentication_method",
    "spinner_name",
    "hide_logo",
    "hide_card_counter_list",
    "hide_board_member_list",
    "custom_login_logo_image_url",
    "custom_login_logo_link_url",
    "custom_help_link_url",
    "text_below_custom_login_logo",
    "automatic_linked_url_schemes",
    "custom_top_left_corner_logo_image_url",
    "custom_top_left_corner_logo_link_url",
    "custom_top_left_corner_logo_height",
    "oidc_btn_text",
    "mail_domain_name",
    "legal_notice",
    "custom_head_enabled",
    "custom_head_meta_tags",
    "custom_head_link_tags",
    "custom_manifest_enabled",
    "custom_manifest_content",
    "custom_asset_links_enabled",
    "custom_asset_links_content",
    "accessibility_page_enabled",
    "accessibility_title",
    "accessibility_content",
    "support_popup_text",
    "support_page_enabled",
    "support_page_public",
    "support_title",
    "support_page_text",
]).multiple(true).conflicts_with("settings_source")), group(ArgGroup::new("update_input").args([
    "settings_file",
    "settings_stdin",
    "disable_registration",
    "disable_forgot_password",
    "product_name",
    "display_authentication_method",
    "default_authentication_method",
    "spinner_name",
    "hide_logo",
    "hide_card_counter_list",
    "hide_board_member_list",
    "custom_login_logo_image_url",
    "custom_login_logo_link_url",
    "custom_help_link_url",
    "text_below_custom_login_logo",
    "automatic_linked_url_schemes",
    "custom_top_left_corner_logo_image_url",
    "custom_top_left_corner_logo_link_url",
    "custom_top_left_corner_logo_height",
    "oidc_btn_text",
    "mail_domain_name",
    "legal_notice",
    "custom_head_enabled",
    "custom_head_meta_tags",
    "custom_head_link_tags",
    "custom_manifest_enabled",
    "custom_manifest_content",
    "custom_asset_links_enabled",
    "custom_asset_links_content",
    "accessibility_page_enabled",
    "accessibility_title",
    "accessibility_content",
    "support_popup_text",
    "support_page_enabled",
    "support_page_public",
    "support_title",
    "support_page_text",
]).required(true).multiple(true)), after_help = "Only the v11.06 REST allowlist is supported; SMTP/mailServer is excluded. Omitted fields remain unchanged. JSON source options conflict with all setting flags.")]
pub struct UpdateArgs {
    #[command(flatten)]
    source: input::SourceArgs,
    /// Set disable registration. Explicit true or false.
    #[arg(long = "disable-registration")]
    disable_registration: Option<bool>,
    /// Set disable forgot password. Explicit true or false.
    #[arg(long = "disable-forgot-password")]
    disable_forgot_password: Option<bool>,
    /// Set product name.
    #[arg(long = "product-name")]
    product_name: Option<String>,
    /// Set display authentication method. Explicit true or false.
    #[arg(long = "display-authentication-method")]
    display_authentication_method: Option<bool>,
    /// Set default authentication method.
    #[arg(long = "default-authentication-method")]
    default_authentication_method: Option<String>,
    /// Set spinner name.
    #[arg(long = "spinner-name")]
    spinner_name: Option<String>,
    /// Set hide logo. Explicit true or false.
    #[arg(long = "hide-logo")]
    hide_logo: Option<bool>,
    /// Set hide card counter list. Explicit true or false.
    #[arg(long = "hide-card-counter-list")]
    hide_card_counter_list: Option<bool>,
    /// Set hide board member list. Explicit true or false.
    #[arg(long = "hide-board-member-list")]
    hide_board_member_list: Option<bool>,
    /// Set custom login logo image url.
    #[arg(long = "custom-login-logo-image-url")]
    custom_login_logo_image_url: Option<String>,
    /// Set custom login logo link url.
    #[arg(long = "custom-login-logo-link-url")]
    custom_login_logo_link_url: Option<String>,
    /// Set custom help link url.
    #[arg(long = "custom-help-link-url")]
    custom_help_link_url: Option<String>,
    /// Set text below custom login logo.
    #[arg(long = "text-below-custom-login-logo")]
    text_below_custom_login_logo: Option<String>,
    /// Set automatic linked url schemes.
    #[arg(long = "automatic-linked-url-schemes")]
    automatic_linked_url_schemes: Option<String>,
    /// Set custom top left corner logo image url.
    #[arg(long = "custom-top-left-corner-logo-image-url")]
    custom_top_left_corner_logo_image_url: Option<String>,
    /// Set custom top left corner logo link url.
    #[arg(long = "custom-top-left-corner-logo-link-url")]
    custom_top_left_corner_logo_link_url: Option<String>,
    /// Set custom top left corner logo height.
    #[arg(long = "custom-top-left-corner-logo-height")]
    custom_top_left_corner_logo_height: Option<String>,
    /// Set oidc btn text.
    #[arg(long = "oidc-btn-text")]
    oidc_btn_text: Option<String>,
    /// Set mail domain name.
    #[arg(long = "mail-domain-name")]
    mail_domain_name: Option<String>,
    /// Set legal notice.
    #[arg(long = "legal-notice")]
    legal_notice: Option<String>,
    /// Set custom head enabled. Explicit true or false.
    #[arg(long = "custom-head-enabled")]
    custom_head_enabled: Option<bool>,
    /// Set custom head meta tags.
    #[arg(long = "custom-head-meta-tags")]
    custom_head_meta_tags: Option<String>,
    /// Set custom head link tags.
    #[arg(long = "custom-head-link-tags")]
    custom_head_link_tags: Option<String>,
    /// Set custom manifest enabled. Explicit true or false.
    #[arg(long = "custom-manifest-enabled")]
    custom_manifest_enabled: Option<bool>,
    /// Set custom manifest content.
    #[arg(long = "custom-manifest-content")]
    custom_manifest_content: Option<String>,
    /// Set custom asset links enabled. Explicit true or false.
    #[arg(long = "custom-asset-links-enabled")]
    custom_asset_links_enabled: Option<bool>,
    /// Set custom asset links content.
    #[arg(long = "custom-asset-links-content")]
    custom_asset_links_content: Option<String>,
    /// Set accessibility page enabled. Explicit true or false.
    #[arg(long = "accessibility-page-enabled")]
    accessibility_page_enabled: Option<bool>,
    /// Set accessibility title.
    #[arg(long = "accessibility-title")]
    accessibility_title: Option<String>,
    /// Set accessibility content.
    #[arg(long = "accessibility-content")]
    accessibility_content: Option<String>,
    /// Set support popup text.
    #[arg(long = "support-popup-text")]
    support_popup_text: Option<String>,
    /// Set support page enabled. Explicit true or false.
    #[arg(long = "support-page-enabled")]
    support_page_enabled: Option<bool>,
    /// Set support page public. Explicit true or false.
    #[arg(long = "support-page-public")]
    support_page_public: Option<bool>,
    /// Set support title.
    #[arg(long = "support-title")]
    support_title: Option<String>,
    /// Set support page text.
    #[arg(long = "support-page-text")]
    support_page_text: Option<String>,
}
pub(crate) async fn execute(
    command: SettingsCommand,
    factory: &WekanClientFactory,
    store: &dyn CredentialStore,
) -> Result<CommandSuccess, AppError> {
    match command {
        SettingsCommand::Get => {
            let context = AuthenticatedContext::load(factory, store)?;
            let document = context
                .client()
                .global_settings(context.record().token())
                .await
                .map_err(|e| {
                    map_client_error(
                        e,
                        &Redactor::with_secret(context.record().token()),
                        "admin settings get",
                        false,
                    )
                })?;
            Ok(CommandSuccess::GlobalSettings(Box::new(
                GlobalSettingsSuccess {
                    settings: document.into(),
                },
            )))
        }
        SettingsCommand::Update(args) => {
            let request = if let Some(request) = args.source.read::<UpdateGlobalSettings>().await? {
                request
            } else {
                UpdateGlobalSettings {
                    disable_registration: args.disable_registration,
                    disable_forgot_password: args.disable_forgot_password,
                    product_name: args.product_name,
                    display_authentication_method: args.display_authentication_method,
                    default_authentication_method: args.default_authentication_method,
                    spinner_name: args.spinner_name,
                    hide_logo: args.hide_logo,
                    hide_card_counter_list: args.hide_card_counter_list,
                    hide_board_member_list: args.hide_board_member_list,
                    custom_login_logo_image_url: args.custom_login_logo_image_url,
                    custom_login_logo_link_url: args.custom_login_logo_link_url,
                    custom_help_link_url: args.custom_help_link_url,
                    text_below_custom_login_logo: args.text_below_custom_login_logo,
                    automatic_linked_url_schemes: args.automatic_linked_url_schemes,
                    custom_top_left_corner_logo_image_url: args
                        .custom_top_left_corner_logo_image_url,
                    custom_top_left_corner_logo_link_url: args.custom_top_left_corner_logo_link_url,
                    custom_top_left_corner_logo_height: args.custom_top_left_corner_logo_height,
                    oidc_btn_text: args.oidc_btn_text,
                    mail_domain_name: args.mail_domain_name,
                    legal_notice: args.legal_notice,
                    custom_head_enabled: args.custom_head_enabled,
                    custom_head_meta_tags: args.custom_head_meta_tags,
                    custom_head_link_tags: args.custom_head_link_tags,
                    custom_manifest_enabled: args.custom_manifest_enabled,
                    custom_manifest_content: args.custom_manifest_content,
                    custom_asset_links_enabled: args.custom_asset_links_enabled,
                    custom_asset_links_content: args.custom_asset_links_content,
                    accessibility_page_enabled: args.accessibility_page_enabled,
                    accessibility_title: args.accessibility_title,
                    accessibility_content: args.accessibility_content,
                    support_popup_text: args.support_popup_text,
                    support_page_enabled: args.support_page_enabled,
                    support_page_public: args.support_page_public,
                    support_title: args.support_title,
                    support_page_text: args.support_page_text,
                }
            };
            let submitted_fields = submitted_fields(&request);
            input::validate_fields(&submitted_fields)?;
            let request = PreparedSettingsUpdate::new(&request)
                .map_err(|error| AppError::invalid_input(error.to_string()))?;
            let context = AuthenticatedContext::load(factory, store)?;
            let document = context
                .client()
                .update_global_settings(request, context.record().token())
                .await
                .map_err(|e| {
                    map_partial_mutation_client_error_with_not_found(
                        e,
                        &Redactor::with_secret(context.record().token()),
                        "admin settings update",
                        "the Wekan settings document was not found",
                    )
                })?;
            Ok(CommandSuccess::GlobalSettingsUpdated(Box::new(
                GlobalSettingsUpdateSuccess {
                    settings: document.into(),
                    submitted_fields,
                },
            )))
        }
    }
}

fn submitted_fields(request: &UpdateGlobalSettings) -> Vec<GlobalSettingField> {
    let mut fields = Vec::new();
    if request.disable_registration.is_some() {
        fields.push(GlobalSettingField::DisableRegistration);
    }
    if request.disable_forgot_password.is_some() {
        fields.push(GlobalSettingField::DisableForgotPassword);
    }
    if request.product_name.is_some() {
        fields.push(GlobalSettingField::ProductName);
    }
    if request.display_authentication_method.is_some() {
        fields.push(GlobalSettingField::DisplayAuthenticationMethod);
    }
    if request.default_authentication_method.is_some() {
        fields.push(GlobalSettingField::DefaultAuthenticationMethod);
    }
    if request.spinner_name.is_some() {
        fields.push(GlobalSettingField::SpinnerName);
    }
    if request.hide_logo.is_some() {
        fields.push(GlobalSettingField::HideLogo);
    }
    if request.hide_card_counter_list.is_some() {
        fields.push(GlobalSettingField::HideCardCounterList);
    }
    if request.hide_board_member_list.is_some() {
        fields.push(GlobalSettingField::HideBoardMemberList);
    }
    if request.custom_login_logo_image_url.is_some() {
        fields.push(GlobalSettingField::CustomLoginLogoImageUrl);
    }
    if request.custom_login_logo_link_url.is_some() {
        fields.push(GlobalSettingField::CustomLoginLogoLinkUrl);
    }
    if request.custom_help_link_url.is_some() {
        fields.push(GlobalSettingField::CustomHelpLinkUrl);
    }
    if request.text_below_custom_login_logo.is_some() {
        fields.push(GlobalSettingField::TextBelowCustomLoginLogo);
    }
    if request.automatic_linked_url_schemes.is_some() {
        fields.push(GlobalSettingField::AutomaticLinkedUrlSchemes);
    }
    if request.custom_top_left_corner_logo_image_url.is_some() {
        fields.push(GlobalSettingField::CustomTopLeftCornerLogoImageUrl);
    }
    if request.custom_top_left_corner_logo_link_url.is_some() {
        fields.push(GlobalSettingField::CustomTopLeftCornerLogoLinkUrl);
    }
    if request.custom_top_left_corner_logo_height.is_some() {
        fields.push(GlobalSettingField::CustomTopLeftCornerLogoHeight);
    }
    if request.oidc_btn_text.is_some() {
        fields.push(GlobalSettingField::OidcBtnText);
    }
    if request.mail_domain_name.is_some() {
        fields.push(GlobalSettingField::MailDomainName);
    }
    if request.legal_notice.is_some() {
        fields.push(GlobalSettingField::LegalNotice);
    }
    if request.custom_head_enabled.is_some() {
        fields.push(GlobalSettingField::CustomHeadEnabled);
    }
    if request.custom_head_meta_tags.is_some() {
        fields.push(GlobalSettingField::CustomHeadMetaTags);
    }
    if request.custom_head_link_tags.is_some() {
        fields.push(GlobalSettingField::CustomHeadLinkTags);
    }
    if request.custom_manifest_enabled.is_some() {
        fields.push(GlobalSettingField::CustomManifestEnabled);
    }
    if request.custom_manifest_content.is_some() {
        fields.push(GlobalSettingField::CustomManifestContent);
    }
    if request.custom_asset_links_enabled.is_some() {
        fields.push(GlobalSettingField::CustomAssetLinksEnabled);
    }
    if request.custom_asset_links_content.is_some() {
        fields.push(GlobalSettingField::CustomAssetLinksContent);
    }
    if request.accessibility_page_enabled.is_some() {
        fields.push(GlobalSettingField::AccessibilityPageEnabled);
    }
    if request.accessibility_title.is_some() {
        fields.push(GlobalSettingField::AccessibilityTitle);
    }
    if request.accessibility_content.is_some() {
        fields.push(GlobalSettingField::AccessibilityContent);
    }
    if request.support_popup_text.is_some() {
        fields.push(GlobalSettingField::SupportPopupText);
    }
    if request.support_page_enabled.is_some() {
        fields.push(GlobalSettingField::SupportPageEnabled);
    }
    if request.support_page_public.is_some() {
        fields.push(GlobalSettingField::SupportPagePublic);
    }
    if request.support_title.is_some() {
        fields.push(GlobalSettingField::SupportTitle);
    }
    if request.support_page_text.is_some() {
        fields.push(GlobalSettingField::SupportPageText);
    }
    fields
}