Skip to content

Commit

Permalink
#13 add read write at drive by default, check public agent
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Nov 21, 2021
1 parent 673a57f commit f0ec2b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions lib/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ pub fn check_rights(
for_agent: &str,
right: Right,
) -> AtomicResult<bool> {
// Check if the resource's write rights explicitly refers to the agent
// Check if the resource's write rights explicitly refers to the agent or the public agent
if let Ok(arr_val) = resource.get(&right.to_string()) {
if arr_val.to_subjects(None)?.iter().any(|s| s == for_agent) {
if arr_val.to_subjects(None)?.iter().any(|s| match s.as_str() {
urls::PUBLIC_AGENT => true,
for_agent => s == for_agent,
}) {
return Ok(true);
};
}
}
// Try the parents recursively
if let Ok(val) = resource.get(urls::PARENT) {
Expand Down
12 changes: 7 additions & 5 deletions lib/src/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ pub fn populate_hierarchy(store: &impl Storelike) -> AtomicResult<()> {
Ok(())
}

/// Get the Drive resource (base URL), set agent as the Root user, provide write and read access
/// Get the Drive resource (base URL), set agent as the Root user, provide write and read access to the Root user. Also, by default, makes the Root publicly visible.
pub fn set_up_drive(store: &impl Storelike) -> AtomicResult<()> {
// Now let's add the agent as the Root user and provide write access
let mut drive = store.get_resource(store.get_base_url())?;
let agents = vec![store.get_default_agent()?.subject];
// TODO: add read rights to public, maybe
drive.set_propval(urls::WRITE.into(), agents.clone().into(), store)?;
drive.set_propval(urls::READ.into(), agents.into(), store)?;
let write_agents = vec![store.get_default_agent()?.subject];
let mut read_agents = write_agents.clone();
read_agents.push(urls::PUBLIC_AGENT.into());

drive.set_propval(urls::WRITE.into(), write_agents.into(), store)?;
drive.set_propval(urls::READ.into(), read_agents.into(), store)?;
drive.set_propval_string(urls::DESCRIPTION.into(), &format!("Welcome to your Atomic-Server! Register your User by visiting [`/setup`]({}/setup). After that, edit this page by pressing `edit` in the navigation bar menu.", store.get_base_url()), store)?;
drive.save_locally(store)?;
Ok(())
Expand Down

0 comments on commit f0ec2b5

Please sign in to comment.