1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/// Policy module for NIP-34 write policies
///
/// This module splits the large Nip34WritePolicy into focused sub-policies:
/// - `AnnouncementPolicy` - Repository announcement validation
/// - `StatePolicy` - State event validation + ref alignment
/// - `PrEventPolicy` - PR/PR Update validation
/// - `RelatedEventPolicy` - Forward/backward reference checking
mod announcement;
mod deletion;
mod pr_event;
mod related;
mod state;
pub use announcement::{AnnouncementPolicy, AnnouncementResult};
pub use deletion::DeletionPolicy;
pub use pr_event::PrEventPolicy;
pub use related::{ReferenceResult, RelatedEventPolicy};
pub use state::{StatePolicy, StateResult};
// Re-export AlignmentResult from git::sync (canonical location)
pub use crate::git::sync::AlignmentResult;
use super::SharedDatabase;
use crate::purgatory::Purgatory;
use nostr_relay_builder::LocalRelay;
use std::sync::Arc;
/// Shared context for all sub-policies
#[derive(Clone)]
pub struct PolicyContext {
pub domain: String,
pub database: SharedDatabase,
pub git_data_path: std::path::PathBuf,
pub purgatory: Arc<Purgatory>,
/// Local relay for notifying WebSocket subscribers (set after relay creation)
pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>,
/// Configuration reference for policy settings (includes blacklists)
pub config: crate::config::Config,
}
impl PolicyContext {
pub fn new(
domain: impl Into<String>,
database: SharedDatabase,
git_data_path: impl Into<std::path::PathBuf>,
purgatory: Arc<Purgatory>,
config: crate::config::Config,
) -> Self {
Self {
domain: domain.into(),
database,
git_data_path: git_data_path.into(),
purgatory,
local_relay: Arc::new(std::sync::RwLock::new(None)),
config,
}
}
/// Set the local relay after it's been created.
///
/// This is called after the relay is built since the relay depends on the policy
/// but the policy needs the relay for purgatory notifications.
pub fn set_local_relay(&self, relay: LocalRelay) {
let mut guard = self.local_relay.write().unwrap();
*guard = Some(relay);
}
/// Get a clone of the local relay if it's been set.
pub fn get_local_relay(&self) -> Option<LocalRelay> {
let guard = self.local_relay.read().unwrap();
guard.clone()
}
}
|