mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-17 11:50:26 +03:00
feat: enhance multiple capabilities file format & fix mixed permissions schema (#9079)
* feat: enhance multiple capabilities file format & fix mixed permissions schema * change files
This commit is contained in:
parent
4bf1c55b0d
commit
bb23511ea8
5
.changes/build-schema-generation.md
Normal file
5
.changes/build-schema-generation.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri-build": patch:bug
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed generation of capability schema for permissions field which previously disallowed mixed (strings and objects) permission definition.
|
5
.changes/utils-named-capability-file.md
Normal file
5
.changes/utils-named-capability-file.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri-utils": major:breaking
|
||||||
|
---
|
||||||
|
|
||||||
|
Changed `CapabiltyFile::List` enum variant to be a tuple-struct and added `CapabiltyFile::NamedList`. This allows more flexibility when parsing capabilties from JSON files.
|
@ -168,8 +168,8 @@ fn capabilities_schema(acl_manifests: &BTreeMap<String, Manifest>) -> RootSchema
|
|||||||
if let Some(Schema::Object(obj)) = schema.definitions.get_mut("PermissionEntry") {
|
if let Some(Schema::Object(obj)) = schema.definitions.get_mut("PermissionEntry") {
|
||||||
let permission_entry_any_of_schemas = obj.subschemas().any_of.as_mut().unwrap();
|
let permission_entry_any_of_schemas = obj.subschemas().any_of.as_mut().unwrap();
|
||||||
|
|
||||||
if let Schema::Object(mut scope_extended_schema_obj) =
|
if let Schema::Object(scope_extended_schema_obj) =
|
||||||
permission_entry_any_of_schemas.remove(permission_entry_any_of_schemas.len() - 1)
|
permission_entry_any_of_schemas.last_mut().unwrap()
|
||||||
{
|
{
|
||||||
let mut global_scope_one_of = Vec::new();
|
let mut global_scope_one_of = Vec::new();
|
||||||
|
|
||||||
@ -246,8 +246,6 @@ fn capabilities_schema(acl_manifests: &BTreeMap<String, Manifest>) -> RootSchema
|
|||||||
one_of: Some(global_scope_one_of),
|
one_of: Some(global_scope_one_of),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
permission_entry_any_of_schemas.push(scope_extended_schema_obj.into());
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,8 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
|||||||
CapabilityFile::Capability(c) => {
|
CapabilityFile::Capability(c) => {
|
||||||
capabilities.insert(c.identifier.clone(), c);
|
capabilities.insert(c.identifier.clone(), c);
|
||||||
}
|
}
|
||||||
CapabilityFile::List {
|
CapabilityFile::List(capabilities_list)
|
||||||
|
| CapabilityFile::NamedList {
|
||||||
capabilities: capabilities_list,
|
capabilities: capabilities_list,
|
||||||
} => {
|
} => {
|
||||||
capabilities.extend(
|
capabilities.extend(
|
||||||
|
@ -136,7 +136,7 @@ pub fn parse_capabilities(
|
|||||||
CapabilityFile::Capability(capability) => {
|
CapabilityFile::Capability(capability) => {
|
||||||
capabilities_map.insert(capability.identifier.clone(), capability);
|
capabilities_map.insert(capability.identifier.clone(), capability);
|
||||||
}
|
}
|
||||||
CapabilityFile::List { capabilities } => {
|
CapabilityFile::List(capabilities) | CapabilityFile::NamedList { capabilities } => {
|
||||||
for capability in capabilities {
|
for capability in capabilities {
|
||||||
capabilities_map.insert(capability.identifier.clone(), capability);
|
capabilities_map.insert(capability.identifier.clone(), capability);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,9 @@ pub enum CapabilityFile {
|
|||||||
/// A single capability.
|
/// A single capability.
|
||||||
Capability(Capability),
|
Capability(Capability),
|
||||||
/// A list of capabilities.
|
/// A list of capabilities.
|
||||||
List {
|
List(Vec<Capability>),
|
||||||
|
/// A list of capabilities.
|
||||||
|
NamedList {
|
||||||
/// The list of capabilities.
|
/// The list of capabilities.
|
||||||
capabilities: Vec<Capability>,
|
capabilities: Vec<Capability>,
|
||||||
},
|
},
|
||||||
@ -135,11 +137,9 @@ impl FromStr for CapabilityFile {
|
|||||||
type Err = super::Error;
|
type Err = super::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s.chars().next() {
|
serde_json::from_str(s)
|
||||||
Some('[') => toml::from_str(s).map_err(Into::into),
|
.or_else(|_| toml::from_str(s))
|
||||||
Some('{') => serde_json::from_str(s).map_err(Into::into),
|
.map_err(Into::into)
|
||||||
_ => Err(super::Error::UnknownCapabilityFormat(s.into())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,9 @@ impl RuntimeAuthority {
|
|||||||
CapabilityFile::Capability(c) => {
|
CapabilityFile::Capability(c) => {
|
||||||
capabilities.insert(c.identifier.clone(), c);
|
capabilities.insert(c.identifier.clone(), c);
|
||||||
}
|
}
|
||||||
CapabilityFile::List {
|
|
||||||
|
CapabilityFile::List(capabilities_list)
|
||||||
|
| CapabilityFile::NamedList {
|
||||||
capabilities: capabilities_list,
|
capabilities: capabilities_list,
|
||||||
} => {
|
} => {
|
||||||
capabilities.extend(
|
capabilities.extend(
|
||||||
|
Loading…
Reference in New Issue
Block a user