mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Script File Access: no row for a grant with an empty script or path
script.grants lists a kept grant whose script or path is an empty string, but script.grants.revoke does not take an empty path, so its Revoke button could not remove it. Such a grant now has no row.
This commit is contained in:
1 parent
4701251879
commit
b3430b7f82
2 files changed
+24
-1
No files matched your search
@@ -77,7 +77,8 @@ pub(super) fn load(app: &mut VectorcraftApp) -> Option<Access> {
|
||||
|
||||
/// The rows for the grants `grants` lists: one for each script and path, sorted by script and then by path, with the
|
||||
/// widest access any kept version of the pair has (`folder`, then `write`, then `read`) and how many versions are
|
||||
/// kept. A grant without a script or a path is left out.
|
||||
/// kept. A grant without a script or a path, or with an empty one, which `script.grants.revoke` does not take, is
|
||||
/// left out.
|
||||
fn rows(grants: &Value) -> Vec<Grant> {
|
||||
let rank = |access: &str| match access {
|
||||
"folder" => 2,
|
||||
@@ -87,6 +88,9 @@ fn rows(grants: &Value) -> Vec<Grant> {
|
||||
let mut pairs: BTreeMap<(&str, &str), (&'static str, usize)> = BTreeMap::new();
|
||||
for g in grants.as_array().into_iter().flatten() {
|
||||
let (Some(script), Some(path)) = (g["script"].as_str(), g["path"].as_str()) else { continue };
|
||||
if script.is_empty() || path.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let access = if g["folder"] == true {
|
||||
"folder"
|
||||
} else if g["write"] == true {
|
||||
|
||||
@@ -833,6 +833,25 @@ fn script_file_access_shows_none_and_a_revoke_of_a_removed_row() {
|
||||
assert!(access_texts(&mut web).is_empty());
|
||||
}
|
||||
|
||||
/// A kept grant with an empty script or path, which `script.grants` lists and `script.grants.revoke` does not take,
|
||||
/// has no row.
|
||||
#[test]
|
||||
fn script_file_access_leaves_out_a_grant_with_an_empty_script_or_path() {
|
||||
let dir = std::env::temp_dir().join("vc-ui-prefs-grants-nowhere");
|
||||
let (script, path) = (dir.join("a.jsx"), dir.join("out.txt"));
|
||||
let grants = json!([
|
||||
grant(&script, &path, "1", false, false),
|
||||
grant(&script, "".as_ref(), "1", false, false),
|
||||
grant("".as_ref(), &path, "1", false, false)
|
||||
]);
|
||||
let (mut a, store) = app_with_grants("grants-empty", grants);
|
||||
assert_eq!(a.session.execute("script.grants", &json!({})).unwrap()["grants"].as_array().map(Vec::len), Some(3));
|
||||
open(&mut a, Some("General"));
|
||||
let row = (script.to_string_lossy().into_owned(), path.to_string_lossy().into_owned(), "read".to_string(), 1);
|
||||
assert_eq!(access_rows(&a), [row]);
|
||||
let _ = std::fs::remove_dir_all(store.parent().unwrap());
|
||||
}
|
||||
|
||||
/// Preferences opened with a read root in force shows a script and a path outside it by their file
|
||||
/// names alone, as `script.grants` lists them, and `ui.inspect` names them the same way; Revoke
|
||||
/// still removes that pair's kept grants, both with the root in force and without it.
|
||||
|
||||
Reference in new issue
Block a user