Skip to content

Commit

Permalink
Lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Feb 29, 2024
1 parent 57f87f2 commit 7cea1ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 35 deletions.
56 changes: 27 additions & 29 deletions dnas/trusted/zomes/integrity/trusted/src/key_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,61 +221,59 @@ pub fn validate_delete_key_collection_to_gpg_key_dist_link(
let action: Action = action.clone().into();
hash_action(action)?
};
let activity = must_get_agent_activity(action.author, ChainFilter::new(action_hash).until(original_action_hash))?;
let activity = must_get_agent_activity(
action.author,
ChainFilter::new(action_hash).until(original_action_hash),
)?;


// Look for the reverse create link, needed to find the associated delete.
let reverse_link_type = {
let scoped_link_type: ScopedLinkType = LinkTypes::GpgKeyDistToKeyCollection.try_into()?;
scoped_link_type.zome_type
};
let matched_gpg_key_dist_to_collection_creates = activity.iter().filter(|agent_activity| {
match agent_activity.action.action() {
Action::CreateLink(CreateLink {
link_type,
tag,
..
}) if *link_type == reverse_link_type && *tag == original_action.tag => true,
_ => false,
}
}).collect::<Vec<_>>();
let matched_gpg_key_dist_to_collection_creates = activity
.iter()
.filter(|agent_activity| matches!(agent_activity.action.action(), Action::CreateLink(CreateLink { link_type, tag, .. }) if *link_type == reverse_link_type && *tag == original_action.tag))
.collect::<Vec<_>>();

if matched_gpg_key_dist_to_collection_creates.len() > 1 {
return Ok(ValidateCallbackResult::Invalid(
"Found duplicate create links to delete, this should have been prevented on create".to_string(),
"Found duplicate create links to delete, this should have been prevented on create"
.to_string(),
));
}

if matched_gpg_key_dist_to_collection_creates.len() == 0 {
if matched_gpg_key_dist_to_collection_creates.is_empty() {
return Ok(ValidateCallbackResult::Invalid(
"The create link to delete does not exist".to_string(),
));
}

let reverse_create = matched_gpg_key_dist_to_collection_creates.first().ok_or_else(|| {
wasm_error!(WasmErrorInner::Guest(
"The create link to delete does not exist".to_string()
))
})?;
let reverse_create = matched_gpg_key_dist_to_collection_creates
.first()
.ok_or_else(|| {
wasm_error!(WasmErrorInner::Guest(
"The create link to delete does not exist".to_string()
))
})?;

let reverse_create_hash = reverse_create.action.as_hash();
let match_gpg_key_dist_to_collection_deletes = activity.iter().filter(|agent_activity| {
match agent_activity.action.action() {
Action::DeleteLink(DeleteLink {
link_add_address,
..
}) if link_add_address == reverse_create_hash => true,
_ => false,
}
}).collect::<Vec<_>>();
let match_gpg_key_dist_to_collection_deletes = activity
.iter()
.filter(|agent_activity| {
matches!(agent_activity.action.action(), Action::DeleteLink(DeleteLink {
link_add_address, ..
}) if link_add_address == reverse_create_hash)
})
.collect::<Vec<_>>();

if match_gpg_key_dist_to_collection_deletes.len() > 1 {
return Ok(ValidateCallbackResult::Invalid(
"Found duplicate delete links, this is pointless".to_string(),
));
}

if match_gpg_key_dist_to_collection_deletes.len() == 0 {
if match_gpg_key_dist_to_collection_deletes.is_empty() {
return Ok(ValidateCallbackResult::Invalid(
"Missing associated reverse deletion".to_string(),
));
Expand Down
14 changes: 11 additions & 3 deletions dnas/trusted/zomes/integrity/trusted/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
)
}
},
FlatOp::RegisterDeleteLink { link_type, original_action, action, .. } => match link_type {
FlatOp::RegisterDeleteLink {
link_type,
original_action,
action,
..
} => match link_type {
LinkTypes::GpgKeyDistToKeyCollection => {
key_collection::validate_delete_gpg_key_dist_to_key_collection_link(
original_action,
Expand All @@ -174,7 +179,10 @@ pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
action,
)
}
lt => Ok(ValidateCallbackResult::Invalid(format!("Link type [{:?}] cannot be deleted", lt))),
lt => Ok(ValidateCallbackResult::Invalid(format!(
"Link type [{:?}] cannot be deleted",
lt
))),
},
FlatOp::StoreRecord(store_record) => {
match store_record {
Expand Down Expand Up @@ -349,7 +357,7 @@ pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
// Complementary validation to the `RegisterDeleteLink` Op, in which the record itself is validated
// If you want to optimize performance, you can remove the validation for an entry type here and keep it in `RegisterDeleteLink`
// Notice that doing so will cause `must_get_valid_record` for this record to return a valid record even if the `RegisterDeleteLink` validation failed
OpRecord::DeleteLink { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::DeleteLink { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::CreatePrivateEntry { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::UpdatePrivateEntry { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::CreateCapClaim { .. } => Ok(ValidateCallbackResult::Valid),
Expand Down
2 changes: 0 additions & 2 deletions ui/src/component/LoadingSpinner.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup lang="ts">
defineProps<{
loading: boolean;
}>();
</script>

<template>
Expand Down
7 changes: 6 additions & 1 deletion ui/src/trusted/trusted/KeyCollections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const { loading, keyCollections } = storeToRefs(useKeyCollectionsStore());
<div>
<!-- Single root for loading transition -->
<div v-if="keyCollections.length === 0" class="ms-5 italic">
<p>You don't have any key collections yet. <router-link to="/search" class="link link-neutral">Search for one to add</router-link>?</p>
<p>
You don't have any key collections yet.
<router-link to="/search" class="link link-neutral"
>Search for one to add</router-link
>?
</p>
</div>
<template v-else>
<div v-for="c in keyCollections" v-bind:key="c.name" class="mt-3">
Expand Down

0 comments on commit 7cea1ce

Please sign in to comment.