diff --git a/lib/defaults/default_store.json b/lib/defaults/default_store.json index 9cac5a473..9c337a228 100644 --- a/lib/defaults/default_store.json +++ b/lib/defaults/default_store.json @@ -67,7 +67,6 @@ "@id": "https://atomicdata.dev/properties/isDynamic", "https://atomicdata.dev/properties/datatype": "https://atomicdata.dev/datatypes/boolean", "https://atomicdata.dev/properties/description": "If this is true, a Property is calculated server side and should therefore not appear in forms.", - "https://atomicdata.dev/properties/parent": "https://atomicdata.dev/properties", "https://atomicdata.dev/properties/isA": [ "https://atomicdata.dev/classes/Property" ], diff --git a/lib/src/agents.rs b/lib/src/agents.rs index ed261e079..aacd90925 100644 --- a/lib/src/agents.rs +++ b/lib/src/agents.rs @@ -2,7 +2,7 @@ //! Agents are actors (such as users) that can edit content. //! https://docs.atomicdata.dev/commits/concepts.html -use crate::{errors::AtomicResult, urls, Resource, Storelike}; +use crate::{errors::AtomicResult, urls, Resource, Storelike, Value}; #[derive(Clone, Debug)] pub struct Agent { @@ -19,21 +19,24 @@ pub struct Agent { impl Agent { /// Converts Agent to Resource. /// Does not include private key, only public. - pub fn to_resource(&self, store: &impl Storelike) -> AtomicResult { - let mut agent = Resource::new_instance(urls::AGENT, store)?; - agent.set_subject(self.subject.clone()); + pub fn to_resource(&self) -> AtomicResult { + let mut resource = Resource::new(self.subject.clone()); + resource.set_class(urls::AGENT)?; + resource.set_subject(self.subject.clone()); if let Some(name) = &self.name { - agent.set_propval_string(crate::urls::NAME.into(), name, store)?; + resource.set_propval_unsafe(crate::urls::NAME.into(), Value::String(name.into())); } - agent.set_propval_string(crate::urls::PUBLIC_KEY.into(), &self.public_key, store)?; + resource.set_propval_unsafe( + crate::urls::PUBLIC_KEY.into(), + Value::String(self.public_key.clone()), + ); // Agents must be read by anyone when validating their keys - agent.push_propval(crate::urls::READ, urls::PUBLIC_AGENT.into(), true, store)?; - agent.set_propval_string( + resource.push_propval(crate::urls::READ, urls::PUBLIC_AGENT.into(), true)?; + resource.set_propval_unsafe( crate::urls::CREATED_AT.into(), - &self.created_at.to_string(), - store, - )?; - Ok(agent) + Value::Timestamp(self.created_at), + ); + Ok(resource) } /// Creates a new Agent, generates a new Keypair. diff --git a/lib/src/client.rs b/lib/src/client.rs index 1af08d8b8..25bac42c3 100644 --- a/lib/src/client.rs +++ b/lib/src/client.rs @@ -45,6 +45,7 @@ pub fn get_authentication_headers(url: &str, agent: &Agent) -> AtomicResult) -> AtomicResult { + println!("fetching body of {}", url); if !url.starts_with("http") { return Err(format!("Could not fetch url '{}', must start with http.", url).into()); } diff --git a/lib/src/collections.rs b/lib/src/collections.rs index b878db386..233b9261e 100644 --- a/lib/src/collections.rs +++ b/lib/src/collections.rs @@ -47,7 +47,7 @@ impl CollectionBuilder { /// If that is what you need, use `.into_resource` pub fn to_resource(&self, store: &impl Storelike) -> AtomicResult { let mut resource = store.get_resource_new(&self.subject); - resource.set_class(urls::COLLECTION, store)?; + resource.set_class(urls::COLLECTION)?; if let Some(val) = &self.property { resource.set_propval_string(crate::urls::COLLECTION_PROPERTY.into(), val, store)?; } diff --git a/lib/src/commit.rs b/lib/src/commit.rs index db4ed26fb..bef0f4bba 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -752,9 +752,7 @@ mod test { &agent.subject, "http://localhost/agents/7LsjMW5gOfDdJzK/atgjQ1t20J/rw8MjVg6xwqm+h8U=" ); - store - .add_resource(&agent.to_resource(&store).unwrap()) - .unwrap(); + store.add_resource(&agent.to_resource().unwrap()).unwrap(); let subject = "https://localhost/new_thing"; let mut commitbuilder = crate::commit::CommitBuilder::new(subject.into()); let property1 = crate::urls::DESCRIPTION; @@ -785,6 +783,7 @@ mod test { fn invalid_subjects() { let store = crate::Store::init().unwrap(); + store.populate().unwrap(); let agent = store.create_agent(Some("test_actor")).unwrap(); let resource = Resource::new("https://localhost/test_resource".into()); diff --git a/lib/src/db/test.rs b/lib/src/db/test.rs index 5d3d91205..8391cfe0a 100644 --- a/lib/src/db/test.rs +++ b/lib/src/db/test.rs @@ -146,7 +146,7 @@ fn destroy_resource_and_check_collection_and_commits() { // Create a new agent, check if it is added to the new Agents collection as a Member. let mut resource = crate::agents::Agent::new(None, &store) .unwrap() - .to_resource(&store) + .to_resource() .unwrap(); let _res = resource.save_locally(&store).unwrap(); let agents_collection_2 = store diff --git a/lib/src/plugins/invite.rs b/lib/src/plugins/invite.rs index eef9c6cc9..8c4529b29 100644 --- a/lib/src/plugins/invite.rs +++ b/lib/src/plugins/invite.rs @@ -32,7 +32,7 @@ pub fn construct_invite_redirect( match store.get_resource(&public_key) { Ok(_found) => {} Err(_) => { - new_agent.to_resource(store)?.save_locally(store)?; + new_agent.to_resource()?.save_locally(store)?; } }; diff --git a/lib/src/populate.rs b/lib/src/populate.rs index 80659e254..7bd0b7df6 100644 --- a/lib/src/populate.rs +++ b/lib/src/populate.rs @@ -155,7 +155,7 @@ pub fn create_drive(store: &impl Storelike) -> AtomicResult<()> { .get_self_url() .ok_or("No self_url set, cannot populate store with Drive")?; let mut drive = store.get_resource_new(&self_url); - drive.set_class(urls::DRIVE, store)?; + drive.set_class(urls::DRIVE)?; let server_url = url::Url::parse(store.get_server_url())?; drive.set_propval_string( urls::NAME.into(), @@ -173,10 +173,10 @@ pub fn set_drive_rights(store: &impl Storelike, public_read: bool) -> AtomicResu let write_agent = store.get_default_agent()?.subject; let read_agent = write_agent.clone(); - drive.push_propval(urls::WRITE, write_agent.into(), true, store)?; - drive.push_propval(urls::READ, read_agent.into(), true, store)?; + drive.push_propval(urls::WRITE, write_agent.into(), true)?; + drive.push_propval(urls::READ, read_agent.into(), true)?; if public_read { - drive.push_propval(urls::READ, urls::PUBLIC_AGENT.into(), true, store)?; + drive.push_propval(urls::READ, urls::PUBLIC_AGENT.into(), true)?; } if let Err(_no_description) = drive.get(urls::DESCRIPTION) { diff --git a/lib/src/resources.rs b/lib/src/resources.rs index 0f24fdd21..df909b129 100644 --- a/lib/src/resources.rs +++ b/lib/src/resources.rs @@ -194,8 +194,6 @@ impl Resource { property: &str, value: SubResource, skip_existing: bool, - // TODO: Use Store to validate datatype - _store: &impl Storelike, ) -> AtomicResult<()> { let mut vec = match self.propvals.get(property) { Some(some) => match some { @@ -348,12 +346,11 @@ impl Resource { } /// Overwrites the is_a (Class) of the Resource. - pub fn set_class(&mut self, is_a: &str, store: &impl Storelike) -> AtomicResult<()> { - self.set_propval( + pub fn set_class(&mut self, is_a: &str) -> AtomicResult<()> { + self.set_propval_unsafe( crate::urls::IS_A.into(), Value::ResourceArray([is_a.into()].into()), - store, - )?; + ); Ok(()) } @@ -711,7 +708,7 @@ mod test { let append_value = "http://localhost/someURL"; let mut resource = Resource::new_generate_subject(&store); resource - .push_propval(&property, append_value.into(), false, &store) + .push_propval(&property, append_value.into(), false) .unwrap(); let vec = resource.get(&property).unwrap().to_subjects(None).unwrap(); assert_eq!( diff --git a/lib/src/storelike.rs b/lib/src/storelike.rs index 2d0958b7c..06ad1b144 100644 --- a/lib/src/storelike.rs +++ b/lib/src/storelike.rs @@ -101,7 +101,7 @@ pub trait Storelike: Sized { /// Does not create a Commit - the recommended way is to use `agent.to_resource().save_locally()`. fn create_agent(&self, name: Option<&str>) -> AtomicResult { let agent = Agent::new(name, self)?; - self.add_resource(&agent.to_resource(self)?)?; + self.add_resource(&agent.to_resource()?)?; Ok(agent) } diff --git a/server/src/appstate.rs b/server/src/appstate.rs index d3c95f0ef..004c6619d 100644 --- a/server/src/appstate.rs +++ b/server/src/appstate.rs @@ -114,7 +114,7 @@ fn set_default_agent(config: &Config, store: &impl Storelike) -> AtomicServerRes store, &agent_config.private_key, ); - store.add_resource(&recreated_agent.to_resource(store)?)?; + store.add_resource(&recreated_agent.to_resource()?)?; agent_config } else { return Err(format!( @@ -158,7 +158,7 @@ fn set_up_initial_invite(store: &impl Storelike) -> AtomicServerResult<()> { let subject = format!("{}/setup", store.get_server_url()); tracing::info!("Creating initial Invite at {}", subject); let mut invite = store.get_resource_new(&subject); - invite.set_class(atomic_lib::urls::INVITE, store)?; + invite.set_class(atomic_lib::urls::INVITE)?; invite.set_subject(subject); // This invite can be used only once invite.set_propval( diff --git a/server/src/handlers/upload.rs b/server/src/handlers/upload.rs index cf87dc4f5..712cb1e55 100644 --- a/server/src/handlers/upload.rs +++ b/server/src/handlers/upload.rs @@ -111,7 +111,7 @@ pub async fn upload_handler( let mut parent = store.get_resource(&query.parent)?; // parent.append_subjects(urls::ATTACHMENTS, created_file_subjects, false, store)?; for created in created_file_subjects { - parent.push_propval(urls::ATTACHMENTS, created.into(), false, store)?; + parent.push_propval(urls::ATTACHMENTS, created.into(), false)?; } commit_responses.push(parent.save(store)?);