Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This changelog covers all five packages, as they are (for now) updated as a whol
- Moved the resource context menu to the top of the page.
- [#861](https://github.com/atomicdata-dev/atomic-server/issues/861) Fix long usernames overflowing on the share page.
- [#906](https://github.com/atomicdata-dev/atomic-server/issues/906) Reset changes after clicking the cancel button in a form or navigating away.
- [#914](https://github.com/atomicdata-dev/atomic-server/issues/914) Fix an issue where changing the subject in a new resource form could update the parent of existing resources if their subject matched the new subject.

### @tomic/lib

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const useNewForm = (args: UseNewForm) => {
// When the resource is created or updated, make sure that the parent and class are present
useEffect(() => {
(async () => {
if (!resource.new) {
// The resource we are trying to create already exists, don't update any values.
return;
}

if (parentVal !== parent) {
await resource.set(core.properties.parent, parent);
}
Expand Down
17 changes: 17 additions & 0 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl Commit {
if opts.validate_timestamp {
check_timestamp(self.created_at)?;
}

self.check_for_circular_parents()?;

let commit_resource: Resource = self.into_resource(store)?;
let mut is_new = false;
// Create a new resource if it doens't exist yet
Expand Down Expand Up @@ -263,6 +266,20 @@ impl Commit {
Ok(commit_response)
}

fn check_for_circular_parents(&self) -> AtomicResult<()> {
// Check if the set hashset has a parent property and if it matches with this subject.
if let Some(set) = self.set.clone() {
if let Some(parent) = set.get(urls::PARENT) {
if parent.to_string() == self.subject {
return Err("Circular parent reference".into());
}
}
}

// TODO: Check for circular parents by going up the parent tree.
Ok(())
}

/// Updates the values in the Resource according to the `set`, `remove`, `push`, and `destroy` attributes in the Commit.
/// Optionally also updates the index in the Store.
/// The Old Resource is only needed when `update_index` is true, and is used for checking
Expand Down