Skip to content

Commit

Permalink
FTS reindex management action
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Sep 20, 2024
1 parent 8fb15e8 commit 7805ac8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/components/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@ pub fn IconDocumentText(
}
}

#[component]
pub fn IconDocumentMagnifyingGlass(
#[prop(optional)] size: Option<usize>,
#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
) -> impl IntoView {
view! {
<SvgWrapper size attrs>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Zm3.75 11.625a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z"
></path>
</SvgWrapper>
}
}

#[component]
pub fn IconInfo(
#[prop(optional)] size: Option<usize>,
Expand Down
1 change: 1 addition & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub enum Permission {
PurgeDataStore,
PurgeLookupStore,
PurgeAccount,
FtsReindex,
Undelete,
DkimSignatureCreate,
DkimSignatureGet,
Expand Down
1 change: 1 addition & 0 deletions src/core/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ impl OAuthCodeResponse {
Permission::PurgeDataStore,
Permission::PurgeLookupStore,
Permission::PurgeAccount,
Permission::FtsReindex,
Permission::Undelete,
Permission::DkimSignatureCreate,
Permission::DkimSignatureGet,
Expand Down
4 changes: 4 additions & 0 deletions src/pages/directory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ pub static PERMISSIONS: &[(&str, &str)] = &[
"purge-account",
"Completely remove an account and all associated data",
),
(
"fts-reindex",
"Rebuild the full-text search index for accounts",
),
("undelete", "Restore deleted items"),
(
"dkim-signature-create",
Expand Down
28 changes: 24 additions & 4 deletions src/pages/manage/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ use leptos_router::use_navigate;

use crate::{
components::{
icon::{IconCheckCircle, IconComputerDesktop, IconPower, IconRefresh, IconShieldCheck},
icon::{
IconCheckCircle, IconComputerDesktop, IconDocumentMagnifyingGlass, IconPower,
IconRefresh, IconShieldCheck,
},
messages::alert::{use_alerts, Alert, Alerts},
},
core::{
http::{self, HttpRequest},
oauth::use_authorization,
Permission,
},
pages::config::ReloadSettings,
};
Expand All @@ -26,6 +30,7 @@ struct Action {
icon: &'static str,
url: &'static str,
success_message: &'static str,
permission: Permission,
}

const ACTIONS: &[Action] = &[
Expand All @@ -35,34 +40,47 @@ const ACTIONS: &[Action] = &[
icon: "refresh",
url: "/api/reload",
success_message: "Successfully reloaded configuration",
permission: Permission::SettingsReload,
},
Action {
title: "Validate configuration",
description: "Checks the configuration for errors and warnings.",
icon: "check_circle",
url: "/api/reload?dry-run=true",
success_message: "Configuration is valid",
permission: Permission::SettingsReload,
},
Action {
title: "Restart server",
description: "Restarts the server. This will interrupt any active connections.",
icon: "power",
url: "/api/restart",
success_message: "Restarting server, try reloading this page in a few seconds.",
permission: Permission::Restart,
},
Action {
title: "Update SPAM rules",
description: "Downloads and installs the latest SPAM rules from the Github repository.",
icon: "shield_check",
url: "/api/update/spam-filter",
success_message: "Successfully updated SPAM rules to the latest version",
permission: Permission::UpdateSpamFilter,
},
Action {
title: "Update Webadmin",
description: "Downloads and installs the latest version of the Stalwart Webadmin from the Github repository.",
icon: "computer_desktop",
url: "/api/update/webadmin",
success_message: "Successfully updated the web admin to the latest version",
permission: Permission::UpdateWebadmin,
},
Action {
title: "Reindex FTS",
description: "Rebuilds the full-text search index for all accounts. This may take some time.",
icon: "document_magnifying_glass",
url: "/api/store/reindex",
success_message: "Successfully requested FTS reindex",
permission: Permission::FtsReindex,
},

];
Expand Down Expand Up @@ -124,18 +142,20 @@ pub fn Maintenance() -> impl IntoView {
}
});

let actions = ACTIONS.iter().enumerate().map(|(idx, action)| {
let permissions = auth.get_untracked().permissions().clone();
let actions = ACTIONS.iter().enumerate().filter_map(|(idx, action)| {
let icon_class = "mt-1 flex-shrink-0 size-5 text-gray-800 dark:text-gray-200";
let icon = match action.icon {
"refresh" => view! { <IconRefresh attr:class=icon_class/> },
"check_circle" => view! { <IconCheckCircle attr:class=icon_class/> },
"power" => view! { <IconPower attr:class=icon_class/> },
"shield_check" => view! { <IconShieldCheck attr:class=icon_class/> },
"computer_desktop" => view! { <IconComputerDesktop attr:class=icon_class/> },
"document_magnifying_glass" => view! { <IconDocumentMagnifyingGlass attr:class=icon_class/> },
_ => unreachable!("No icon specified"),
};

view! {
permissions.has_access(action.permission).then(|| view! {
<a
class="group flex flex-col bg-white border shadow-sm rounded-xl hover:shadow-md transition dark:bg-slate-900 dark:border-gray-800"
href="#"
Expand All @@ -157,7 +177,7 @@ pub fn Maintenance() -> impl IntoView {
</div>
</div>
</a>
}
})

}).collect_view();

Expand Down

0 comments on commit 7805ac8

Please sign in to comment.