Merge pull request #6747 from dotCooCoo/fix/plugin-grant-sealed-api

Plug-ins: only an approval records a grant, and installs need one
This commit is contained in:
BFlat
2026-11-12 12:41:15 +07:00
committed by GitHub
12 changed files with 339 additions and 42 deletions
+5 -4
View File
@@ -52,7 +52,7 @@ use vectorcraft_plugins::{Budget, Command, Kind, Plugin, effect, export, objects
use super::{CommandSpec, EngineError, NodeId, Result, Session, always, bad, cmd, has_doc, ids_param, str_param, switch_or};
use vectorcraft_plugins::permissions::{self, Grant, Permission};
use vectorcraft_plugins::permissions::{self, Grant, GrantToken, Permission};
/// What a plug-in error looks like to the user. A run the caller cancelled changed nothing.
fn err(e: vectorcraft_plugins::Error) -> EngineError {
@@ -750,7 +750,7 @@ fn install(s: &mut Session, p: &Value) -> Result<Value> {
let holds_new = |s: &Session| s.stored_plugin_bytes(plugin.id()).is_ok_and(|held| held.as_deref() == Some(&bytes[..]));
if m.asks_permissions() {
let g = Grant { id: m.id.clone(), hash: plugin.hash().to_string(), permissions: wanted };
registry::grant(g.clone());
registry::grant(GrantToken::after_engine_approval(g.clone()));
if stored && !s.store_grant(&m.id, Some(g)) {
stored = !s.put_back_plugin(plugin.id(), previous.ok().flatten().as_deref()) && holds_new(s);
}
@@ -787,7 +787,8 @@ fn install(s: &mut Session, p: &Value) -> Result<Value> {
if changed {
s.store_disabled_plugins();
}
let mut v = describe_installed(&registry::install(plugin));
let installed = registry::install(plugin).map_err(err)?;
let mut v = describe_installed(&installed);
if !unknown.is_empty() {
v["unknownCommands"] = json!(unknown);
}
@@ -886,7 +887,7 @@ fn load_folder(s: &Session, folder: &str) -> Value {
None if crate::file_access::current().is_none() => Ok(()),
None => Err(format!("automation path rejected: {} isn't valid text", f.display())),
};
match registry::load_folder_where(std::path::Path::new(folder), allow, s.plugin_approver()) {
match registry::load_folder_where(std::path::Path::new(folder), allow, s.plugin_folder_approver()) {
Ok(r) => {
for id in &r.loaded {
s.attach_plugin_storage(id);