Skip to content

Commit

Permalink
Require main_search_bar permission when entrypoint type 'inline-view'…
Browse files Browse the repository at this point in the history
… is used
  • Loading branch information
Exidex committed Sep 14, 2024
1 parent 1fe349d commit ea9c795
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
2 changes: 2 additions & 0 deletions bundled_plugins/calculator/gauntlet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ path = 'src/default.tsx'
type = 'inline-view'
description = ''

[permissions]
main_search_bar = ["read"]
3 changes: 2 additions & 1 deletion dev_plugin/gauntlet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ os = 'windows'
environment = ["RUST_LOG"]
system = ["systemMemoryInfo"]
network = ["upload.wikimedia.org", "api.github.com"]
clipboard = ["read", "write", "clear"]
clipboard = ["read", "write", "clear"]
main_search_bar = ["read"]
8 changes: 8 additions & 0 deletions rust/server/src/plugins/data_db_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub struct DbPluginPermissions {
pub system: Vec<String>,
#[serde(default)]
pub clipboard: Vec<DbPluginClipboardPermissions>,
#[serde(default)]
pub main_search_bar: Vec<DbPluginMainSearchBarPermissions>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions rust/server/src/plugins/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct PluginPermissions {
pub run_subprocess: Vec<String>,
pub system: Vec<String>,
pub clipboard: Vec<PluginClipboardPermissions>,
pub main_search_bar: Vec<PluginMainSearchBarPermissions>,
}

#[derive(Clone, Debug)]
Expand All @@ -97,6 +98,11 @@ pub enum PluginClipboardPermissions {
Clear
}

#[derive(Clone, Debug)]
pub enum PluginMainSearchBarPermissions {
Read,
}


#[derive(Clone, Debug)]
pub enum PluginCommand {
Expand Down
34 changes: 33 additions & 1 deletion rust/server/src/plugins/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -343,6 +365,7 @@ impl PluginLoader {
run_subprocess: plugin_manifest.permissions.run_subprocess,
system: plugin_manifest.permissions.system,
clipboard,
main_search_bar,
};

Ok(PluginDownloadData {
Expand Down Expand Up @@ -829,6 +852,8 @@ pub struct PluginManifestPermissions {
system: Vec<String>,
#[serde(default)]
clipboard: Vec<PluginManifestClipboardPermissions>,
#[serde(default)]
main_search_bar: Vec<PluginManifestMainSearchBarPermissions>,
}

#[derive(Debug, Deserialize)]
Expand All @@ -840,3 +865,10 @@ pub enum PluginManifestClipboardPermissions {
#[serde(rename = "clear")]
Clear
}

#[derive(Debug, Deserialize, Eq, PartialEq)]
pub enum PluginManifestMainSearchBarPermissions {
#[serde(rename = "read")]
Read,
}

13 changes: 11 additions & 2 deletions rust/server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion tools
Submodule tools updated 1 files
+8 −1 src/config.ts

0 comments on commit ea9c795

Please sign in to comment.