diff options
Diffstat (limited to 'src/nostr/policy/deletion.rs')
| -rw-r--r-- | src/nostr/policy/deletion.rs | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/nostr/policy/deletion.rs b/src/nostr/policy/deletion.rs index 6457c90..c5a52d4 100644 --- a/src/nostr/policy/deletion.rs +++ b/src/nostr/policy/deletion.rs | |||
| @@ -155,7 +155,9 @@ impl DeletionPolicy { | |||
| 155 | author = %author.to_hex(), | 155 | author = %author.to_hex(), |
| 156 | "Deletion request: removing purgatory state event by event ID" | 156 | "Deletion request: removing purgatory state event by event ID" |
| 157 | ); | 157 | ); |
| 158 | self.ctx.purgatory.remove_state_event(&identifier, &entry.event.id); | 158 | self.ctx |
| 159 | .purgatory | ||
| 160 | .remove_state_event(&identifier, &entry.event.id); | ||
| 159 | return; // event IDs are unique | 161 | return; // event IDs are unique |
| 160 | } | 162 | } |
| 161 | } | 163 | } |
| @@ -223,7 +225,9 @@ impl DeletionPolicy { | |||
| 223 | if entry.author == *author | 225 | if entry.author == *author |
| 224 | && entry.event.created_at.as_secs() <= deletion_created_at | 226 | && entry.event.created_at.as_secs() <= deletion_created_at |
| 225 | { | 227 | { |
| 226 | self.ctx.purgatory.remove_state_event(identifier, &entry.event.id); | 228 | self.ctx |
| 229 | .purgatory | ||
| 230 | .remove_state_event(identifier, &entry.event.id); | ||
| 227 | removed += 1; | 231 | removed += 1; |
| 228 | } | 232 | } |
| 229 | } | 233 | } |
| @@ -306,7 +310,10 @@ mod tests { | |||
| 306 | EventBuilder::new(Kind::GitRepoAnnouncement, "") | 310 | EventBuilder::new(Kind::GitRepoAnnouncement, "") |
| 307 | .tags(vec![ | 311 | .tags(vec![ |
| 308 | Tag::identifier(identifier), | 312 | Tag::identifier(identifier), |
| 309 | Tag::custom(TagKind::custom("clone"), vec!["https://example.com/repo.git"]), | 313 | Tag::custom( |
| 314 | TagKind::custom("clone"), | ||
| 315 | vec!["https://example.com/repo.git"], | ||
| 316 | ), | ||
| 310 | ]) | 317 | ]) |
| 311 | .sign_with_keys(keys) | 318 | .sign_with_keys(keys) |
| 312 | .unwrap() | 319 | .unwrap() |
| @@ -331,7 +338,9 @@ mod tests { | |||
| 331 | let announcement = make_announcement_event(&keys, identifier); | 338 | let announcement = make_announcement_event(&keys, identifier); |
| 332 | add_to_purgatory(&ctx, &announcement, identifier); | 339 | add_to_purgatory(&ctx, &announcement, identifier); |
| 333 | 340 | ||
| 334 | assert!(ctx.purgatory.has_purgatory_announcement(&keys.public_key(), identifier)); | 341 | assert!(ctx |
| 342 | .purgatory | ||
| 343 | .has_purgatory_announcement(&keys.public_key(), identifier)); | ||
| 335 | 344 | ||
| 336 | // Build kind 5 deletion event referencing the announcement by event ID | 345 | // Build kind 5 deletion event referencing the announcement by event ID |
| 337 | let deletion = EventBuilder::new(Kind::EventDeletion, "") | 346 | let deletion = EventBuilder::new(Kind::EventDeletion, "") |
| @@ -347,7 +356,8 @@ mod tests { | |||
| 347 | 356 | ||
| 348 | assert!(matches!(result, WritePolicyResult::Accept)); | 357 | assert!(matches!(result, WritePolicyResult::Accept)); |
| 349 | assert!( | 358 | assert!( |
| 350 | !ctx.purgatory.has_purgatory_announcement(&keys.public_key(), identifier), | 359 | !ctx.purgatory |
| 360 | .has_purgatory_announcement(&keys.public_key(), identifier), | ||
| 351 | "Purgatory entry should have been removed" | 361 | "Purgatory entry should have been removed" |
| 352 | ); | 362 | ); |
| 353 | } | 363 | } |
| @@ -361,7 +371,9 @@ mod tests { | |||
| 361 | let announcement = make_announcement_event(&keys, identifier); | 371 | let announcement = make_announcement_event(&keys, identifier); |
| 362 | add_to_purgatory(&ctx, &announcement, identifier); | 372 | add_to_purgatory(&ctx, &announcement, identifier); |
| 363 | 373 | ||
| 364 | assert!(ctx.purgatory.has_purgatory_announcement(&keys.public_key(), identifier)); | 374 | assert!(ctx |
| 375 | .purgatory | ||
| 376 | .has_purgatory_announcement(&keys.public_key(), identifier)); | ||
| 365 | 377 | ||
| 366 | // Build kind 5 deletion event referencing the announcement by coordinate | 378 | // Build kind 5 deletion event referencing the announcement by coordinate |
| 367 | let coord = format!("30617:{}:{}", keys.public_key().to_hex(), identifier); | 379 | let coord = format!("30617:{}:{}", keys.public_key().to_hex(), identifier); |
| @@ -378,7 +390,8 @@ mod tests { | |||
| 378 | 390 | ||
| 379 | assert!(matches!(result, WritePolicyResult::Accept)); | 391 | assert!(matches!(result, WritePolicyResult::Accept)); |
| 380 | assert!( | 392 | assert!( |
| 381 | !ctx.purgatory.has_purgatory_announcement(&keys.public_key(), identifier), | 393 | !ctx.purgatory |
| 394 | .has_purgatory_announcement(&keys.public_key(), identifier), | ||
| 382 | "Purgatory entry should have been removed" | 395 | "Purgatory entry should have been removed" |
| 383 | ); | 396 | ); |
| 384 | } | 397 | } |
| @@ -407,7 +420,8 @@ mod tests { | |||
| 407 | 420 | ||
| 408 | assert!(matches!(result, WritePolicyResult::Accept)); | 421 | assert!(matches!(result, WritePolicyResult::Accept)); |
| 409 | assert!( | 422 | assert!( |
| 410 | ctx.purgatory.has_purgatory_announcement(&owner_keys.public_key(), identifier), | 423 | ctx.purgatory |
| 424 | .has_purgatory_announcement(&owner_keys.public_key(), identifier), | ||
| 411 | "Purgatory entry should NOT have been removed by wrong author" | 425 | "Purgatory entry should NOT have been removed by wrong author" |
| 412 | ); | 426 | ); |
| 413 | } | 427 | } |
| @@ -438,7 +452,8 @@ mod tests { | |||
| 438 | 452 | ||
| 439 | assert!(matches!(result, WritePolicyResult::Accept)); | 453 | assert!(matches!(result, WritePolicyResult::Accept)); |
| 440 | assert!( | 454 | assert!( |
| 441 | ctx.purgatory.has_purgatory_announcement(&owner_keys.public_key(), identifier), | 455 | ctx.purgatory |
| 456 | .has_purgatory_announcement(&owner_keys.public_key(), identifier), | ||
| 442 | "Purgatory entry should NOT have been removed by wrong author" | 457 | "Purgatory entry should NOT have been removed by wrong author" |
| 443 | ); | 458 | ); |
| 444 | } | 459 | } |
| @@ -450,11 +465,10 @@ mod tests { | |||
| 450 | 465 | ||
| 451 | // No purgatory entry exists — deletion should still be accepted | 466 | // No purgatory entry exists — deletion should still be accepted |
| 452 | let deletion = EventBuilder::new(Kind::EventDeletion, "") | 467 | let deletion = EventBuilder::new(Kind::EventDeletion, "") |
| 453 | .tags(vec![ | 468 | .tags(vec![Tag::custom( |
| 454 | Tag::custom(TagKind::custom("a"), vec![ | 469 | TagKind::custom("a"), |
| 455 | format!("30617:{}:nonexistent", keys.public_key().to_hex()) | 470 | vec![format!("30617:{}:nonexistent", keys.public_key().to_hex())], |
| 456 | ]), | 471 | )]) |
| 457 | ]) | ||
| 458 | .sign_with_keys(&keys) | 472 | .sign_with_keys(&keys) |
| 459 | .unwrap(); | 473 | .unwrap(); |
| 460 | 474 | ||
| @@ -491,7 +505,8 @@ mod tests { | |||
| 491 | 505 | ||
| 492 | assert!(matches!(result, WritePolicyResult::Accept)); | 506 | assert!(matches!(result, WritePolicyResult::Accept)); |
| 493 | assert!( | 507 | assert!( |
| 494 | ctx.purgatory.has_purgatory_announcement(&keys.public_key(), identifier), | 508 | ctx.purgatory |
| 509 | .has_purgatory_announcement(&keys.public_key(), identifier), | ||
| 495 | "Purgatory entry should NOT be removed: entry is newer than deletion request" | 510 | "Purgatory entry should NOT be removed: entry is newer than deletion request" |
| 496 | ); | 511 | ); |
| 497 | } | 512 | } |