Uninstall plugins from settings
This commit is contained in:
@@ -19,6 +19,7 @@ pub enum PluginAuditAction {
|
||||
Installed,
|
||||
Enabled,
|
||||
Disabled,
|
||||
Uninstalled,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -119,6 +120,18 @@ impl BrowserCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn uninstall_plugin(&mut self, plugin_id: &PluginId) -> Result<(), CoreError> {
|
||||
let plugin_index = self
|
||||
.installed_plugins
|
||||
.iter()
|
||||
.position(|plugin| plugin.id() == plugin_id)
|
||||
.ok_or_else(|| CoreError::PluginNotFound { id: plugin_id.clone() })?;
|
||||
|
||||
self.installed_plugins.remove(plugin_index);
|
||||
self.record_plugin_audit_event(plugin_id.clone(), PluginAuditAction::Uninstalled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn record_plugin_audit_event(&mut self, plugin_id: PluginId, action: PluginAuditAction) {
|
||||
self.plugin_audit_events.push(PluginAuditEvent::record(
|
||||
plugin_id,
|
||||
|
||||
@@ -95,6 +95,40 @@ fn records_plugin_enable_disable_audit_events() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uninstalls_plugin_and_records_audit_event() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let plugin_id =
|
||||
core.install_plugin(plugin_manifest("com.elydora.reader", &["page:metadata"])?, false)?;
|
||||
|
||||
core.uninstall_plugin(&plugin_id)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert!(snapshot.installed_plugins.is_empty());
|
||||
assert_eq!(snapshot.plugin_audit_events.len(), 2);
|
||||
assert_eq!(snapshot.plugin_audit_events[1].plugin_id(), &plugin_id);
|
||||
assert_eq!(snapshot.plugin_audit_events[1].action(), &PluginAuditAction::Uninstalled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_reinstall_after_plugin_uninstall() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let plugin_id =
|
||||
core.install_plugin(plugin_manifest("com.elydora.reader", &["page:metadata"])?, false)?;
|
||||
core.uninstall_plugin(&plugin_id)?;
|
||||
|
||||
let reinstalled_id =
|
||||
core.install_plugin(plugin_manifest("com.elydora.reader", &["page:metadata"])?, false)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(reinstalled_id, plugin_id);
|
||||
assert_eq!(snapshot.installed_plugins.len(), 1);
|
||||
assert_eq!(snapshot.plugin_audit_events.len(), 3);
|
||||
assert_eq!(snapshot.plugin_audit_events[2].action(), &PluginAuditAction::Installed);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_unknown_plugin_state_change() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user