merge branches and cleanup db
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
use crate::db::{Collection, Db, hero::OurDB};
|
||||
use crate::models::Circle;
|
||||
use crate::db::{hero::OurDB, Collection, Db};
|
||||
use heromodels_core::BaseModelData;
|
||||
use heromodels_derive::model;
|
||||
use std::sync::Arc;
|
||||
// Temporarily removed to fix compilation issues
|
||||
// use rhai_autobind_macros::rhai_model_export;
|
||||
use rhai::{CustomType, TypeBuilder};
|
||||
@@ -71,17 +71,16 @@ impl Access {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Checks if a caller has permission to access a specific resource.
|
||||
/// Access is granted if the caller is a super admin or if an `Access` record exists
|
||||
/// granting them `can_access = true` for the given resource type and ID.
|
||||
///
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `db`: An `Arc<OurDB>` for database interaction.
|
||||
/// * `public_key`: The public key of the caller.
|
||||
/// * `_resource_id_to_check`: The ID of the resource being accessed (now unused).
|
||||
/// * `_resource_type_to_check`: The type of the resource (e.g., "Collection", "Image") (now unused).
|
||||
///
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns `Err(EvalAltResult::ErrorRuntime)` if there's a database error during the check.
|
||||
pub fn can_access_resource(
|
||||
@@ -94,7 +93,8 @@ pub fn can_access_resource(
|
||||
.collection::<Circle>()
|
||||
.expect("Failed to get Circle collection")
|
||||
.get_all()
|
||||
.unwrap()[0].clone();
|
||||
.unwrap()[0]
|
||||
.clone();
|
||||
|
||||
// Circle members can access everything
|
||||
if circle.members.contains(&public_key.to_string()) {
|
||||
@@ -121,18 +121,18 @@ pub fn can_access_resource(
|
||||
println!("Access records: {:#?}", access_records);
|
||||
|
||||
// if circle_pk is in access records true
|
||||
return access_records.iter().any(|record| record.circle_pk == public_key)
|
||||
return access_records
|
||||
.iter()
|
||||
.any(|record| record.circle_pk == public_key);
|
||||
}
|
||||
|
||||
pub fn is_circle_member(
|
||||
db: Arc<OurDB>,
|
||||
public_key: &str,
|
||||
) -> bool {
|
||||
pub fn is_circle_member(db: Arc<OurDB>, public_key: &str) -> bool {
|
||||
let circle = db
|
||||
.collection::<Circle>()
|
||||
.expect("Failed to get Circle collection")
|
||||
.get_all()
|
||||
.unwrap()[0].clone();
|
||||
.unwrap()[0]
|
||||
.clone();
|
||||
|
||||
// Circle members can access everything
|
||||
if circle.members.contains(&public_key.to_string()) {
|
||||
|
Reference in New Issue
Block a user