mirror of
https://github.com/block/buzz.git
synced 2026-11-29 04:32:08 +00:00
Allow Project admins to manage related channels
Signed-off-by: John Tennant <jtennant@squareup.com>
This commit is contained in:
@@ -630,6 +630,11 @@ pub const KIND_GIT_STATUS_DRAFT: u32 = 1633;
|
||||
/// authority over any member: push policy reads the repository's own
|
||||
/// announcement, never a project. See `docs/nips/NIP-MP.md`.
|
||||
pub const KIND_PROJECT: u32 = 30621;
|
||||
/// Actor-signed transactional change command for collaborative Project state.
|
||||
///
|
||||
/// Version 1 changes only add or remove related channels. See
|
||||
/// `docs/nips/NIP-PC.md`.
|
||||
pub const KIND_PROJECT_CHANGE: u32 = 47010;
|
||||
/// Relay-signed addressable effective-state projection for a Project.
|
||||
///
|
||||
/// The owner-signed [`KIND_PROJECT`] remains the Project identity and recovery
|
||||
@@ -769,6 +774,7 @@ pub const ALL_KINDS: &[u32] = &[
|
||||
KIND_GIT_STATUS_CLOSED,
|
||||
KIND_GIT_STATUS_DRAFT,
|
||||
KIND_PROJECT,
|
||||
KIND_PROJECT_CHANGE,
|
||||
KIND_PROJECT_STATE,
|
||||
];
|
||||
|
||||
@@ -829,6 +835,7 @@ pub const fn is_command_kind(kind: u32) -> bool {
|
||||
| KIND_WORKFLOW_TRIGGER
|
||||
| KIND_APPROVAL_GRANT
|
||||
| KIND_APPROVAL_DENY
|
||||
| KIND_PROJECT_CHANGE
|
||||
)
|
||||
}
|
||||
|
||||
@@ -871,6 +878,7 @@ const _: () = assert!(is_parameterized_replaceable(KIND_EVENT_REMINDER)); // 303
|
||||
const _: () = assert!(is_parameterized_replaceable(KIND_DM_VISIBILITY)); // 30622 ∈ 30000–39999
|
||||
const _: () = assert!(is_parameterized_replaceable(KIND_PROJECT)); // 30621 ∈ 30000–39999
|
||||
const _: () = assert!(is_parameterized_replaceable(KIND_PROJECT_STATE)); // 30623 ∈ 30000–39999
|
||||
const _: () = assert!(is_command_kind(KIND_PROJECT_CHANGE));
|
||||
const _: () = assert!(is_parameterized_replaceable(KIND_THREAD_SUMMARY)); // 39005 ∈ 30000–39999
|
||||
const _: () = assert!(is_parameterized_replaceable(KIND_WINDOW_BOUNDS)); // 39006 ∈ 30000–39999
|
||||
const _: () = assert!(is_relay_only_kind(KIND_PROJECT_STATE));
|
||||
@@ -925,6 +933,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn project_collaboration_kinds_have_distinct_routing() {
|
||||
assert!(is_command_kind(KIND_PROJECT_CHANGE));
|
||||
assert!(!is_relay_only_kind(KIND_PROJECT_CHANGE));
|
||||
assert!(!is_parameterized_replaceable(KIND_PROJECT_CHANGE));
|
||||
assert!(is_parameterized_replaceable(KIND_PROJECT_STATE));
|
||||
assert!(is_relay_only_kind(KIND_PROJECT_STATE));
|
||||
assert!(!is_command_kind(KIND_PROJECT_STATE));
|
||||
|
||||
@@ -113,7 +113,7 @@ struct ProjectionBody {
|
||||
project_tags: Vec<Vec<String>>,
|
||||
}
|
||||
|
||||
/// Validate a relay-authored Project State event.
|
||||
/// Validate a relay-authored Project State event and return its CAS revision.
|
||||
///
|
||||
/// This checks the event signature and advertised relay author, the requested
|
||||
/// Project coordinate, a canonical positive revision, and the strict version-1
|
||||
@@ -123,7 +123,7 @@ pub fn validate_project_state_projection(
|
||||
event: &Event,
|
||||
relay_pubkey: &PublicKey,
|
||||
coordinate: &str,
|
||||
) -> Result<(), ProjectStateError> {
|
||||
) -> Result<u64, ProjectStateError> {
|
||||
parse_project_coordinate(coordinate)?;
|
||||
event
|
||||
.verify()
|
||||
@@ -166,6 +166,9 @@ pub fn validate_project_state_projection(
|
||||
"projection revision is not canonical".into(),
|
||||
));
|
||||
}
|
||||
let revision = revision
|
||||
.parse::<u64>()
|
||||
.map_err(|error| ProjectStateError(format!("invalid projection revision: {error}")))?;
|
||||
let body: ProjectionBody = serde_json::from_str(&event.content)
|
||||
.map_err(|error| ProjectStateError(format!("invalid projection JSON: {error}")))?;
|
||||
if body.v != 1 {
|
||||
@@ -173,7 +176,7 @@ pub fn validate_project_state_projection(
|
||||
"projection JSON is not supported version 1".into(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
Ok(revision)
|
||||
}
|
||||
|
||||
fn canonical_positive_i64(value: &str) -> bool {
|
||||
@@ -488,7 +491,7 @@ mod tests {
|
||||
let event = signed_projection(&relay, &template);
|
||||
assert_eq!(
|
||||
validate_project_state_projection(&event, &relay.public_key(), &coordinate),
|
||||
Ok(())
|
||||
Ok(7)
|
||||
);
|
||||
|
||||
let mut reordered = template.clone();
|
||||
@@ -499,7 +502,7 @@ mod tests {
|
||||
&relay.public_key(),
|
||||
&coordinate,
|
||||
),
|
||||
Ok(())
|
||||
Ok(7)
|
||||
);
|
||||
|
||||
let impostor = Keys::generate();
|
||||
|
||||
Reference in New Issue
Block a user