From ea9c795973368069fddbcae0d837c841e23087f2 Mon Sep 17 00:00:00 2001 From: Exidex <16986685+Exidex@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:03:31 +0200 Subject: [PATCH] Require main_search_bar permission when entrypoint type 'inline-view' is used --- bundled_plugins/calculator/gauntlet.toml | 2 ++ dev_plugin/gauntlet.toml | 3 +- rust/server/src/plugins/data_db_repository.rs | 8 +++++ rust/server/src/plugins/js/mod.rs | 6 ++++ rust/server/src/plugins/loader.rs | 34 ++++++++++++++++++- rust/server/src/plugins/mod.rs | 13 +++++-- tools | 2 +- 7 files changed, 63 insertions(+), 5 deletions(-) diff --git a/bundled_plugins/calculator/gauntlet.toml b/bundled_plugins/calculator/gauntlet.toml index 678c27b..410c557 100644 --- a/bundled_plugins/calculator/gauntlet.toml +++ b/bundled_plugins/calculator/gauntlet.toml @@ -9,3 +9,5 @@ path = 'src/default.tsx' type = 'inline-view' description = '' +[permissions] +main_search_bar = ["read"] diff --git a/dev_plugin/gauntlet.toml b/dev_plugin/gauntlet.toml index 6b8018e..1c66244 100644 --- a/dev_plugin/gauntlet.toml +++ b/dev_plugin/gauntlet.toml @@ -148,4 +148,5 @@ os = 'windows' environment = ["RUST_LOG"] system = ["systemMemoryInfo"] network = ["upload.wikimedia.org", "api.github.com"] -clipboard = ["read", "write", "clear"] \ No newline at end of file +clipboard = ["read", "write", "clear"] +main_search_bar = ["read"] \ No newline at end of file diff --git a/rust/server/src/plugins/data_db_repository.rs b/rust/server/src/plugins/data_db_repository.rs index b868ced..646bf5c 100644 --- a/rust/server/src/plugins/data_db_repository.rs +++ b/rust/server/src/plugins/data_db_repository.rs @@ -132,6 +132,8 @@ pub struct DbPluginPermissions { pub system: Vec, #[serde(default)] pub clipboard: Vec, + #[serde(default)] + pub main_search_bar: Vec, } #[derive(Debug, Deserialize, Serialize)] @@ -144,6 +146,12 @@ pub enum DbPluginClipboardPermissions { Clear } +#[derive(Debug, Deserialize, Serialize)] +pub enum DbPluginMainSearchBarPermissions { + #[serde(rename = "read")] + Read, +} + #[derive(Debug, Deserialize, Serialize)] #[serde(tag = "type")] pub enum DbPluginPreferenceUserData { diff --git a/rust/server/src/plugins/js/mod.rs b/rust/server/src/plugins/js/mod.rs index c1c2c59..6bf4b0b 100644 --- a/rust/server/src/plugins/js/mod.rs +++ b/rust/server/src/plugins/js/mod.rs @@ -83,6 +83,7 @@ pub struct PluginPermissions { pub run_subprocess: Vec, pub system: Vec, pub clipboard: Vec, + pub main_search_bar: Vec, } #[derive(Clone, Debug)] @@ -97,6 +98,11 @@ pub enum PluginClipboardPermissions { Clear } +#[derive(Clone, Debug)] +pub enum PluginMainSearchBarPermissions { + Read, +} + #[derive(Clone, Debug)] pub enum PluginCommand { diff --git a/rust/server/src/plugins/loader.rs b/rust/server/src/plugins/loader.rs index e25c333..61c7c29 100644 --- a/rust/server/src/plugins/loader.rs +++ b/rust/server/src/plugins/loader.rs @@ -14,7 +14,7 @@ use itertools::Itertools; use tracing_subscriber::fmt::format; use common::model::{DownloadStatus, PluginId}; use crate::model::ActionShortcutKey; -use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_to_str, db_plugin_type_to_str, DbCode, DbPluginAction, DbPluginActionShortcutKind, DbPluginEntrypointType, DbPluginPermissions, DbPluginPreference, DbPluginPreferenceUserData, DbPluginType, DbPreferenceEnumValue, DbWritePlugin, DbWritePluginAssetData, DbWritePluginEntrypoint, DbPluginClipboardPermissions}; +use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_to_str, db_plugin_type_to_str, DbCode, DbPluginAction, DbPluginActionShortcutKind, DbPluginEntrypointType, DbPluginPermissions, DbPluginPreference, DbPluginPreferenceUserData, DbPluginType, DbPreferenceEnumValue, DbWritePlugin, DbWritePluginAssetData, DbWritePluginEntrypoint, DbPluginClipboardPermissions, DbPluginMainSearchBarPermissions}; use crate::plugins::download_status::DownloadStatusHolder; pub struct PluginLoader { @@ -242,6 +242,18 @@ impl PluginLoader { } } + let has_inline_view = plugin_manifest.entrypoint + .iter() + .find(|entrypoint| matches!(entrypoint.entrypoint_type, PluginManifestEntrypointTypes::InlineView)) + .is_some(); + + if has_inline_view { + let main_search_bar = &permissions.main_search_bar; + if !main_search_bar.contains(&PluginManifestMainSearchBarPermissions::Read) { + return Err(anyhow!("Plugin uses entrypoint type 'inline-view' but doesn't specify main search bar 'read' permission")) + } + } + let plugin_name = plugin_manifest.gauntlet.name; let plugin_description = plugin_manifest.gauntlet.description; @@ -333,6 +345,16 @@ impl PluginLoader { }) .collect(); + let main_search_bar = plugin_manifest.permissions + .main_search_bar + .into_iter() + .map(|permission| { + match permission { + PluginManifestMainSearchBarPermissions::Read => DbPluginMainSearchBarPermissions::Read, + } + }) + .collect(); + let permissions = DbPluginPermissions { environment: plugin_manifest.permissions.environment, high_resolution_time: plugin_manifest.permissions.high_resolution_time, @@ -343,6 +365,7 @@ impl PluginLoader { run_subprocess: plugin_manifest.permissions.run_subprocess, system: plugin_manifest.permissions.system, clipboard, + main_search_bar, }; Ok(PluginDownloadData { @@ -829,6 +852,8 @@ pub struct PluginManifestPermissions { system: Vec, #[serde(default)] clipboard: Vec, + #[serde(default)] + main_search_bar: Vec, } #[derive(Debug, Deserialize)] @@ -840,3 +865,10 @@ pub enum PluginManifestClipboardPermissions { #[serde(rename = "clear")] Clear } + +#[derive(Debug, Deserialize, Eq, PartialEq)] +pub enum PluginManifestMainSearchBarPermissions { + #[serde(rename = "read")] + Read, +} + diff --git a/rust/server/src/plugins/mod.rs b/rust/server/src/plugins/mod.rs index 42a3d16..7f4c05e 100644 --- a/rust/server/src/plugins/mod.rs +++ b/rust/server/src/plugins/mod.rs @@ -17,10 +17,10 @@ use utils::channel::RequestSender; use common::dirs::Dirs; use crate::model::ActionShortcutKey; use crate::plugins::config_reader::ConfigReader; -use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_from_str, DbPluginActionShortcutKind, DbPluginEntrypointType, DbPluginPreference, DbPluginPreferenceUserData, DbReadPluginEntrypoint, DbPluginClipboardPermissions}; +use crate::plugins::data_db_repository::{DataDbRepository, db_entrypoint_from_str, DbPluginActionShortcutKind, DbPluginEntrypointType, DbPluginPreference, DbPluginPreferenceUserData, DbReadPluginEntrypoint, DbPluginClipboardPermissions, DbPluginMainSearchBarPermissions}; use crate::plugins::global_shortcut::{convert_physical_shortcut_to_hotkey, register_listener}; use crate::plugins::icon_cache::IconCache; -use crate::plugins::js::{AllPluginCommandData, OnePluginCommandData, PluginCode, PluginCommand, PluginPermissions, PluginRuntimeData, start_plugin_runtime, PluginClipboardPermissions}; +use crate::plugins::js::{AllPluginCommandData, OnePluginCommandData, PluginCode, PluginCommand, PluginPermissions, PluginRuntimeData, start_plugin_runtime, PluginClipboardPermissions, PluginMainSearchBarPermissions}; use crate::plugins::loader::PluginLoader; use crate::plugins::run_status::RunStatusHolder; use crate::search::SearchIndex; @@ -564,6 +564,14 @@ impl ApplicationManager { }) .collect(); + let main_search_bar_permissions = plugin.permissions + .main_search_bar + .into_iter() + .map(|permission| match permission { + DbPluginMainSearchBarPermissions::Read => PluginMainSearchBarPermissions::Read, + }) + .collect(); + let data = PluginRuntimeData { id: plugin_id, uuid: plugin.uuid, @@ -579,6 +587,7 @@ impl ApplicationManager { run_subprocess: plugin.permissions.run_subprocess, system: plugin.permissions.system, clipboard: clipboard_permissions, + main_search_bar: main_search_bar_permissions }, command_receiver: receiver, db_repository: self.db_repository.clone(), diff --git a/tools b/tools index 2370948..0506c37 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 23709487f8e98709fe3f5d03cb2a143a62026dca +Subproject commit 0506c376f15a220e571e5ef573e94781ad789077