//! The administrator pages: sender and reminders with the message to members (`/settings`), mail rules //! (`/rules`) and logs (`/logs`). Each page is plain data in, markup out. Handlers build the data in //! `pages/`; nothing here reads the store. //! //! The password of the sender is never a field value: the form shows only whether one is set. Every //! value is escaped by `view!`, and no script or handler is emitted. use topcoat::Result; use topcoat::view::{View, component, view}; use crate::i18n::Lang; use crate::i18n::admin::{K, fill, t}; use crate::i18n::structure::{K as StructureK, t as structure_t}; use crate::views::board::flag; use crate::views::structure::{limits_section, members_section, server_section, storage_section}; use crate::views::{alert, notice}; /// The sender form as it is shown. The password is never here, only `password_set`. #[derive(Debug, Clone, Default)] pub struct SenderForm { /// Host name. pub host: String, /// Port, as text. pub port: String, /// `implicit`, `starttls` or `plain`. pub tls: String, /// SMTP user name. pub username: String, /// From address. pub from_address: String, /// From name. pub from_name: String, /// Whether a password is stored. pub password_set: bool, } /// A row of the rules list: the name, the sentence the rule says, and whether it is on. #[derive(Debug, Clone)] pub struct RuleRow { /// Rule id. pub id: String, /// The admin's name for the rule. pub name: String, /// The rule in one sentence. pub sentence: String, /// Whether the rule is on. pub enabled: bool, } /// The rule form as it is shown: the typed values, or the saved rule being edited. #[derive(Debug, Clone, Default)] pub struct RuleFormView { /// The name. pub name: String, /// The trigger word. pub trigger: String, /// The column id (only for the status trigger). pub column: String, /// The project id, or empty for any. pub tag: String, /// The audience word. pub audience: String, /// The subject template. pub subject: String, /// Whether the mail carries the details block. pub include_details: bool, /// Whether the rule is on. pub enabled: bool, } /// One activity row of the logs. #[derive(Debug, Clone)] pub struct ActivityRow { /// When it happened, as stored. pub at: String, /// Who did it, by name. pub who: String, /// The event kind. pub kind: String, /// The details, as stored JSON text. pub detail: String, } /// The sections of the logs page. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum LogSection { /// Mail queued for sending. Outbox, /// The rules' decisions. Decisions, /// The board's activity. Activity, } /// The rows of one logs page. Only the section in `section` is filled. #[derive(Debug, Clone)] pub struct LogsView { /// The section shown. pub section: LogSection, /// Outbox rows, newest first. pub outbox: Vec, /// Rule decisions, newest first. pub decisions: Vec, /// Activity rows, newest first. pub activity: Vec, /// The kind filter text, as typed. pub kind: String, /// The link to the older page, when there is one. pub next: Option, /// A confirmation, already translated. pub notice: Option, } /// The settings page: sender, reminders and the message to members. #[derive(Debug, Clone)] pub struct SettingsView { /// The language. pub lang: Lang, /// Whether the sender is complete enough to send. pub configured: bool, /// The sender form. pub sender: SenderForm, /// Lead time of the reminders, in minutes. pub reminder_lead: u32, /// Reminder mails one member may get per hour. pub reminder_cap: u32, /// A confirmation to show above the page, already translated. pub notice: Option, /// A refusal to show above the page, already translated or a store message. pub alert: Option, /// Members and their roles, in name order. pub members: Vec, /// The attachment size limit in MiB, as text for the form. pub limit_mib: String, /// The allowed attachment extensions, space separated, for the form. pub extensions: String, /// Read-only facts about the server. pub server: crate::views::structure::ServerInfo, /// Where attachments are kept and how far the move between places has got. pub storage: crate::views::structure::StorageInfo, /// The Backups card: whether backups are on, and the outcome of the last runs. pub backup: BackupCard, /// The Recently deleted card: tasks deleted within the restore window, newest first. pub deleted: Vec, } /// One row of the Recently deleted card. `at` is already in the viewer's zone. #[derive(Debug, Clone, Default)] pub struct DeletedRow { /// Task id, for the restore form. pub id: String, /// Readable key `PREFIX-n`. pub key: String, /// Title. pub title: String, /// When it was deleted, as `YYYY-MM-DD HH:MM`. pub at: String, /// The name of who deleted it, when the activity trail recorded it. pub by: Option, } /// The Backups card. Times are already in the viewer's zone; an empty text means nothing was recorded. #[derive(Debug, Clone, Default)] pub struct BackupCard { /// Whether scheduled backups are on (`[backup] dir` is set). The button and the status show only then. pub enabled: bool, /// When the latest attempt started, as `YYYY-MM-DD HH:MM`. pub last_attempt: String, /// When the last success finished, as `YYYY-MM-DD HH:MM`. pub last_success: String, /// The error of the latest attempt, shown in an alert. Empty when that attempt succeeded. pub last_error: String, /// Whether no success is recent enough: the warning is shown only when backups are on. pub stale: bool, } /// One status line of the Backups card: its label with the time, or "none yet" when nothing was recorded. fn backup_line(lang: Lang, key: K, stamp: &str) -> String { let when = if stamp.is_empty() { t(lang, K::BackupNever) } else { stamp }; fill(t(lang, key), &[when]) } /// The alert for a failed latest attempt, with the short error the worker recorded. #[component] async fn backup_failed_alert(lang: Lang, error: &str) -> Result { let text = fill(t(lang, K::BackupFailed), &[error]); Ok(view! { alert(message: text.as_str()) }) } /// The rules page: the list, the form (new or editing), and the choices of the form. #[derive(Debug, Clone)] pub struct RulesView { /// The language. pub lang: Lang, /// The rules, oldest first. pub rules: Vec, /// The columns the status trigger can name, `(id, name)`. pub columns: Vec<(String, String)>, /// The projects the rule can be limited to, `(id, name)`. pub tags: Vec<(String, String)>, /// The form to show. pub form: RuleFormView, /// The id of the rule being edited, or `None` for a new rule. pub editing: Option, /// Whether the form is shown. pub show_form: bool, /// A confirmation, already translated. pub notice: Option, /// A refusal, already translated or a store message. pub alert: Option, } /// The tabs of the administrator area. `current` is the page shown. #[component] pub async fn admin_tabs(lang: Lang, current: &str) -> Result { let settings = if current == "settings" { "tab current" } else { "tab" }; let rules = if current == "rules" { "tab current" } else { "tab" }; let logs = if current == "logs" { "tab current" } else { "tab" }; let tags = if current == "tags" { "tab current" } else { "tab" }; let columns = if current == "columns" { "tab current" } else { "tab" }; Ok(view! { }) } /// The settings page body. #[component] pub async fn settings_content(page: &SettingsView, csrf: &str) -> Result { let lang = page.lang; let sender = &page.sender; let tls_implicit = sender.tls == "implicit"; let tls_starttls = sender.tls == "starttls"; let tls_plain = sender.tls == "plain"; let lead = page.reminder_lead.to_string(); let cap = page.reminder_cap.to_string(); let password_state = if sender.password_set { t(lang, K::PasswordSet) } else { t(lang, K::PasswordNotSet) }; Ok(view! {

(t(lang, K::SettingsTitle))

admin_tabs(lang: lang, current: "settings") if let Some(message) = &page.alert { alert(message: message.as_str()) } if let Some(message) = &page.notice { notice(message: message.as_str()) }

(t(lang, K::SenderHeading))

(t(lang, K::SenderHelp))

if !page.configured {

(t(lang, K::SenderNotConfigured))

}

(password_state) " " (t(lang, K::PasswordHint))

(t(lang, K::FromNameHint))

(t(lang, K::RemindersHeading))

(t(lang, K::MessageHeading))

(t(lang, K::MessageHelp))

(t(lang, K::BackupHeading))

if page.backup.enabled {

(t(lang, K::BackupHelp))

if page.backup.stale {
(t(lang, K::BackupStale))
} if !page.backup.last_error.is_empty() { backup_failed_alert(lang: lang, error: page.backup.last_error.as_str()) }

(backup_line(lang, K::BackupLastSuccess, page.backup.last_success.as_str()))

(backup_line(lang, K::BackupLastAttempt, page.backup.last_attempt.as_str()))

} else {

(t(lang, K::BackupOff))

}

(t(lang, K::DeletedHeading))

(t(lang, K::DeletedHelp))

if page.deleted.is_empty() {

(t(lang, K::DeletedEmpty))

} else { for row in page.deleted.iter() { }
(t(lang, K::DeletedTaskHeader)) (t(lang, K::DeletedAtHeader)) (t(lang, K::DeletedByHeader))
(row.key.as_str()) " " (row.title.as_str()) (row.at.as_str()) if let Some(name) = &row.by { (name.as_str()) } else { (t(lang, K::DeletedUnknown)) }
}
members_section(lang: lang, members: &page.members, csrf: csrf) storage_section(lang: lang, info: &page.storage, csrf: csrf) limits_section(lang: lang, limit_mib: page.limit_mib.as_str(), extensions: page.extensions.as_str(), csrf: csrf) server_section(lang: lang, info: &page.server) }) } /// The rules page body: the list with the sentence of each rule, then the form. #[component] pub async fn rules_content(page: &RulesView, csrf: &str) -> Result { let lang = page.lang; let form = &page.form; let heading = if page.editing.is_some() { t(lang, K::EditRule) } else { t(lang, K::NewRule) }; let audiences = ["assignees", "board", "creator", "watchers"]; let triggers = iz_core::rules::TRIGGERS; Ok(view! {

(t(lang, K::RulesTitle))

(t(lang, K::RulesHelp))

admin_tabs(lang: lang, current: "rules") if let Some(message) = &page.alert { alert(message: message.as_str()) } if let Some(message) = &page.notice { notice(message: message.as_str()) }
if page.rules.is_empty() {

(t(lang, K::NoRules))

}
    for rule in page.rules.iter() {
  • (rule.name.as_str())

    (rule.sentence.as_str())

    (t(lang, K::Edit))
  • }
(t(lang, K::NewRule))
if page.show_form {

(heading)

format!("/rules/{id}/edit"), None => "/rules".to_owned() }) class="stack">

(t(lang, K::SubjectHint))

(t(lang, K::CancelEdit))
} }) } /// The logs page body: the section tabs, the filter for the activity, and the rows of the section. #[component] pub async fn logs_content(page: &LogsView, csrf: &str, lang: Lang) -> Result { let outbox = page.section == LogSection::Outbox; let decisions = page.section == LogSection::Decisions; let activity = page.section == LogSection::Activity; Ok(view! {

(t(lang, K::LogsTitle))

if let Some(message) = &page.notice { notice(message: message.as_str()) } admin_tabs(lang: lang, current: "logs") if outbox {
if page.outbox.is_empty() {

(t(lang, K::NothingYet))

} else { for (row, attempts) in page.outbox.iter().map(|r| (r, r.attempts.to_string())) { }
(t(lang, K::ColWhen)) (t(lang, K::ColRecipient)) (t(lang, K::ColSubject)) (t(lang, K::ColState)) (t(lang, K::ColAttempts)) (t(lang, K::ColLastError))
(row.created_at.as_str()) (row.recipient_name.as_str()) " <" (row.recipient_email.as_str()) ">" (row.subject.as_str()) (outbox_state(lang, row.state.as_str())) (attempts.as_str()) (row.last_error.as_deref().unwrap_or("")) if row.state == "failed" || row.state == "abandoned" {
}
}
} if decisions {
if page.decisions.is_empty() {

(t(lang, K::NothingYet))

} else { for row in page.decisions.iter() { }
(t(lang, K::ColWhen)) (t(lang, K::ColRule)) (t(lang, K::ColTask)) (t(lang, K::ColOutcome)) (t(lang, K::ColDetail))
(row.at.as_str()) (row.rule_name.as_str()) (row.task_key.as_deref().unwrap_or("")) (outcome_label(lang, row.outcome.as_str())) (reason_label(lang, row.detail.as_str()))
}
} if activity {
if page.activity.is_empty() {

(t(lang, K::NothingYet))

} else { for row in page.activity.iter() { }
(t(lang, K::ColWhen)) (t(lang, K::ColWho)) (t(lang, K::ColWhat)) (t(lang, K::ColDetail))
(row.at.as_str()) (row.who.as_str()) (row.kind.as_str()) (row.detail.as_str())
}
} if let Some(href) = page.next.as_ref() {

(t(lang, K::Older))

} }) } /// The word for a trigger in the rules list and form. pub fn trigger_label(lang: Lang, word: &str) -> &'static str { t( lang, match word { "status" => K::TrigStatus, "unblocked" => K::TrigUnblocked, "created" => K::TrigCreated, "assigned" => K::TrigAssigned, "unassigned" => K::TrigUnassigned, "commented" => K::TrigCommented, "deadline_set" => K::TrigDeadlineSet, "deadline_cleared" => K::TrigDeadlineCleared, "retitled" => K::TrigRetitled, "linked" => K::TrigLinked, "unlinked" => K::TrigUnlinked, _ => K::TrigDeleted, }, ) } /// The phrase of an audience. pub fn audience_label(lang: Lang, word: &str) -> &'static str { t( lang, match word { "assignees" => K::AudAssignees, "board" => K::AudBoard, "creator" => K::AudCreator, _ => K::AudWatchers, }, ) } /// The label of an outbox state. fn outbox_state(lang: Lang, state: &str) -> &'static str { t( lang, match state { "sent" => K::StateSent, "failed" => K::StateFailed, "abandoned" => K::StateAbandoned, _ => K::StatePending, }, ) } /// The label of a decision outcome. fn outcome_label(lang: Lang, outcome: &str) -> &'static str { t( lang, match outcome { "owed" => K::OutOwed, "already_owed" => K::OutAlreadyOwed, "no_recipients" => K::OutNoRecipients, "not_matched" => K::OutNotMatched, "disabled" => K::OutDisabled, _ => K::OutTaskGone, }, ) } /// The label of the reason a decision gave, as stored (`column` or `project`). fn reason_label(lang: Lang, detail: &str) -> &'static str { match detail { "column" => t(lang, K::ReasonColumn), "project" => t(lang, K::ReasonProject), _ => "", } }