move dsl's to rhailib wip
This commit is contained in:
parent
e2640b9421
commit
cd2557c1c3
@ -655,7 +655,7 @@ mod rhai_library_module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_library_rhai_module(engine: &mut Engine, db: Arc<OurDB>) {
|
pub fn register_library_rhai_module(engine: &mut Engine) {
|
||||||
let module = exported_module!(rhai_library_module);
|
let module = exported_module!(rhai_library_module);
|
||||||
engine.register_global_module(module.into());
|
engine.register_global_module(module.into());
|
||||||
|
|
@ -86,4 +86,4 @@ required-features = ["rhai"]
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "rhai_auth_example"
|
name = "rhai_auth_example"
|
||||||
path = "examples/rhai_auth_example.rs"
|
path = "examples/rhai_auth_example.rs"
|
||||||
required-features = ["rhai", "authorization"]
|
required-features = ["rhai", "macros"]
|
||||||
|
@ -87,16 +87,16 @@ impl Access {
|
|||||||
pub fn can_access_resource(
|
pub fn can_access_resource(
|
||||||
db: Arc<OurDB>,
|
db: Arc<OurDB>,
|
||||||
public_key: &str,
|
public_key: &str,
|
||||||
_resource_id_to_check: u32,
|
object_id: u32,
|
||||||
_resource_type_to_check: &str,
|
_object_type: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
// Query for Access records matching the public key.
|
println!("Checking access for public key: {}", public_key);
|
||||||
// Note: This fetches all access records for the user. For performance with many records,
|
|
||||||
// consider a more specific query if your DB supports it, or caching.
|
// get all access records for object
|
||||||
let access_records = match db
|
let access_records = match db
|
||||||
.collection::<Access>()
|
.collection::<Access>()
|
||||||
.expect("Failed to get Access collection")
|
.expect("Failed to get Access collection")
|
||||||
.get::<access_index::circle_pk, _>(public_key)
|
.get::<access_index::object_id, _>(&object_id)
|
||||||
{
|
{
|
||||||
Ok(records) => records,
|
Ok(records) => records,
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
@ -107,9 +107,8 @@ pub fn can_access_resource(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if !access_records.is_empty() {
|
println!("Access records: {:#?}", access_records);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false // Default to deny if no grant is found
|
// if circle_pk is in access records true
|
||||||
|
return access_records.iter().any(|record| record.circle_pk == public_key)
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,11 @@ impl Image {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the ID of the image.
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the title of the image.
|
/// Sets the title of the image.
|
||||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
@ -107,6 +112,11 @@ impl Pdf {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the ID of the image.
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the title of the PDF.
|
/// Sets the title of the PDF.
|
||||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
@ -134,7 +144,7 @@ impl Pdf {
|
|||||||
|
|
||||||
/// Represents a Markdown document library item.
|
/// Represents a Markdown document library item.
|
||||||
#[model]
|
#[model]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
pub struct Markdown {
|
pub struct Markdown {
|
||||||
/// Base model data
|
/// Base model data
|
||||||
pub base_data: BaseModelData,
|
pub base_data: BaseModelData,
|
||||||
@ -147,23 +157,17 @@ pub struct Markdown {
|
|||||||
pub content: String,
|
pub content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Markdown {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
base_data: BaseModelData::new(),
|
|
||||||
title: String::new(),
|
|
||||||
description: None,
|
|
||||||
content: String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Markdown {
|
impl Markdown {
|
||||||
/// Creates a new `Markdown` document with default values.
|
/// Creates a new `Markdown` document with default values.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the ID of the image.
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the title of the document.
|
/// Sets the title of the document.
|
||||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
@ -184,7 +188,7 @@ impl Markdown {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a table of contents entry for a book.
|
/// Represents a table of contents entry for a book.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
pub struct TocEntry {
|
pub struct TocEntry {
|
||||||
/// Title of the chapter/section
|
/// Title of the chapter/section
|
||||||
pub title: String,
|
pub title: String,
|
||||||
@ -194,16 +198,6 @@ pub struct TocEntry {
|
|||||||
pub subsections: Vec<TocEntry>,
|
pub subsections: Vec<TocEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TocEntry {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
title: String::new(),
|
|
||||||
page: 0,
|
|
||||||
subsections: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TocEntry {
|
impl TocEntry {
|
||||||
/// Creates a new `TocEntry` with default values.
|
/// Creates a new `TocEntry` with default values.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
@ -231,7 +225,7 @@ impl TocEntry {
|
|||||||
|
|
||||||
/// Represents a Book library item (collection of markdown pages with TOC).
|
/// Represents a Book library item (collection of markdown pages with TOC).
|
||||||
#[model]
|
#[model]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
pub struct Book {
|
pub struct Book {
|
||||||
/// Base model data
|
/// Base model data
|
||||||
pub base_data: BaseModelData,
|
pub base_data: BaseModelData,
|
||||||
@ -246,24 +240,17 @@ pub struct Book {
|
|||||||
pub pages: Vec<String>,
|
pub pages: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Book {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
base_data: BaseModelData::new(),
|
|
||||||
title: String::new(),
|
|
||||||
description: None,
|
|
||||||
table_of_contents: Vec::new(),
|
|
||||||
pages: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Book {
|
impl Book {
|
||||||
/// Creates a new `Book` with default values.
|
/// Creates a new `Book` with default values.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the ID of the book.
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the title of the book.
|
/// Sets the title of the book.
|
||||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
@ -303,7 +290,7 @@ impl Book {
|
|||||||
|
|
||||||
/// Represents a Slides library item (collection of images for slideshow).
|
/// Represents a Slides library item (collection of images for slideshow).
|
||||||
#[model]
|
#[model]
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
pub struct Slides {
|
pub struct Slides {
|
||||||
/// Base model data
|
/// Base model data
|
||||||
pub base_data: BaseModelData,
|
pub base_data: BaseModelData,
|
||||||
@ -318,24 +305,17 @@ pub struct Slides {
|
|||||||
pub slide_titles: Vec<Option<String>>,
|
pub slide_titles: Vec<Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Slides {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
base_data: BaseModelData::new(),
|
|
||||||
title: String::new(),
|
|
||||||
description: None,
|
|
||||||
slide_urls: Vec::new(),
|
|
||||||
slide_titles: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Slides {
|
impl Slides {
|
||||||
/// Creates a new `Slides` with default values.
|
/// Creates a new `Slides` with default values.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the ID of the slideshow.
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the title of the slideshow.
|
/// Sets the title of the slideshow.
|
||||||
pub fn title(mut self, title: impl Into<String>) -> Self {
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
||||||
self.title = title.into();
|
self.title = title.into();
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
pub mod collection;
|
pub mod collection;
|
||||||
pub mod items;
|
pub mod items;
|
||||||
pub mod rhai;
|
|
||||||
pub use rhai::register_library_rhai_module;
|
|
||||||
|
3
heromodels/src/models/log/README.md
Normal file
3
heromodels/src/models/log/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## Object Model
|
||||||
|
|
||||||
|
This is a generic object model mostly used for testing purposes.
|
60
heromodels/src/models/log/log.rs
Normal file
60
heromodels/src/models/log/log.rs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::db::{hero::OurDB, Collection, Db};
|
||||||
|
use heromodels_core::BaseModelData;
|
||||||
|
use heromodels_derive::model;
|
||||||
|
// Temporarily removed to fix compilation issues
|
||||||
|
// use rhai_autobind_macros::rhai_model_export;
|
||||||
|
use rhai::{CustomType, TypeBuilder};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Represents an event in a contact
|
||||||
|
#[model]
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
|
pub struct Log {
|
||||||
|
/// Base model data
|
||||||
|
pub base_data: BaseModelData,
|
||||||
|
#[index]
|
||||||
|
pub title: String,
|
||||||
|
pub description: String,
|
||||||
|
#[index]
|
||||||
|
pub subject_pk: String,
|
||||||
|
#[index]
|
||||||
|
pub object_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Log {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Log {
|
||||||
|
title: String::new(),
|
||||||
|
base_data: BaseModelData::new(),
|
||||||
|
description: String::new(),
|
||||||
|
subject_pk: String::new(),
|
||||||
|
object_id: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn title(mut self, title: String) -> Self {
|
||||||
|
self.title = title;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn description(mut self, description: String) -> Self {
|
||||||
|
self.description = description;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn subject_pk(mut self, subject_pk: String) -> Self {
|
||||||
|
self.subject_pk = subject_pk;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn object_id(mut self, object_id: u32) -> Self {
|
||||||
|
self.object_id = object_id;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
5
heromodels/src/models/log/mod.rs
Normal file
5
heromodels/src/models/log/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Export contact module
|
||||||
|
pub mod log;
|
||||||
|
|
||||||
|
// Re-export contact, Group from the inner contact module (contact.rs) within src/models/contact/mod.rs
|
||||||
|
pub use self::log::Log;
|
@ -12,6 +12,7 @@ pub mod flow;
|
|||||||
pub mod governance;
|
pub mod governance;
|
||||||
pub mod legal;
|
pub mod legal;
|
||||||
pub mod library;
|
pub mod library;
|
||||||
|
pub mod object;
|
||||||
pub mod projects;
|
pub mod projects;
|
||||||
|
|
||||||
// Re-export key types for convenience
|
// Re-export key types for convenience
|
||||||
@ -38,6 +39,4 @@ pub use circle::register_circle_rhai_module;
|
|||||||
pub use flow::register_flow_rhai_module;
|
pub use flow::register_flow_rhai_module;
|
||||||
pub use legal::register_legal_rhai_module;
|
pub use legal::register_legal_rhai_module;
|
||||||
#[cfg(feature = "rhai")]
|
#[cfg(feature = "rhai")]
|
||||||
pub use library::register_library_rhai_module;
|
|
||||||
#[cfg(feature = "rhai")]
|
|
||||||
pub use projects::register_projects_rhai_module;
|
pub use projects::register_projects_rhai_module;
|
||||||
|
3
heromodels/src/models/object/README.md
Normal file
3
heromodels/src/models/object/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
## Object Model
|
||||||
|
|
||||||
|
This is a generic object model mostly used for testing purposes.
|
5
heromodels/src/models/object/mod.rs
Normal file
5
heromodels/src/models/object/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Export contact module
|
||||||
|
pub mod object;
|
||||||
|
|
||||||
|
// Re-export contact, Group from the inner contact module (contact.rs) within src/models/contact/mod.rs
|
||||||
|
pub use self::object::Object;
|
44
heromodels/src/models/object/object.rs
Normal file
44
heromodels/src/models/object/object.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::db::{hero::OurDB, Collection, Db};
|
||||||
|
use heromodels_core::BaseModelData;
|
||||||
|
use heromodels_derive::model;
|
||||||
|
// Temporarily removed to fix compilation issues
|
||||||
|
// use rhai_autobind_macros::rhai_model_export;
|
||||||
|
use rhai::{CustomType, TypeBuilder};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Represents an event in a contact
|
||||||
|
#[model]
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
||||||
|
pub struct Object {
|
||||||
|
/// Base model data
|
||||||
|
pub base_data: BaseModelData,
|
||||||
|
#[index]
|
||||||
|
pub title: String,
|
||||||
|
pub description: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Object {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Object {
|
||||||
|
title: String::new(),
|
||||||
|
base_data: BaseModelData::new(),
|
||||||
|
description: String::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.base_data.id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn title(mut self, title: String) -> Self {
|
||||||
|
self.title = title;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn description(mut self, description: String) -> Self {
|
||||||
|
self.description = description;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user