diff --git a/crates/ruma-state-res/Cargo.toml b/crates/ruma-state-res/Cargo.toml index e981e969..038fff43 100644 --- a/crates/ruma-state-res/Cargo.toml +++ b/crates/ruma-state-res/Cargo.toml @@ -16,8 +16,11 @@ all-features = true [features] compat = [] -unstable-pre-spec = ["ruma-events/unstable-pre-spec", "ruma-identifiers/unstable-spec"] unstable-exhaustive-types = [] +unstable-spec = ["ruma-events/unstable-spec", "ruma-identifiers/unstable-spec"] + +# Private, only used in test / benchmarking code +__unstable-pre-spec = ["ruma-events/unstable-pre-spec", "unstable-spec"] [dependencies] itertools = "0.10.0" diff --git a/crates/ruma-state-res/benches/state_res_bench.rs b/crates/ruma-state-res/benches/state_res_bench.rs index 1fc97e3e..ec269355 100644 --- a/crates/ruma-state-res/benches/state_res_bench.rs +++ b/crates/ruma-state-res/benches/state_res_bench.rs @@ -394,7 +394,7 @@ where content, redacts: None, unsigned: btreemap! {}, - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "__unstable-pre-spec"))] origin: "foo".into(), auth_events, prev_events, diff --git a/crates/ruma-state-res/src/event_auth.rs b/crates/ruma-state-res/src/event_auth.rs index 46719fae..69c0b416 100644 --- a/crates/ruma-state-res/src/event_auth.rs +++ b/crates/ruma-state-res/src/event_auth.rs @@ -28,7 +28,7 @@ struct GetMembership { #[derive(Deserialize)] struct RoomMemberContentFields { membership: Option>, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] join_authorised_via_users_server: Option>>, } @@ -242,10 +242,10 @@ pub fn auth_check( let target_user = <&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?; - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] let join_authed_user = content.join_authorised_via_users_server.as_ref().and_then(|u| u.deserialize().ok()); - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] let join_authed_user_membership = if let Some(auth_user) = &join_authed_user { fetch_state(&EventType::RoomMember, auth_user.as_str()) .and_then(|mem| from_json_str::(mem.content().get()).ok()) @@ -264,9 +264,9 @@ pub fn auth_check( current_third_party_invite, power_levels_event.as_ref(), fetch_state(&EventType::RoomJoinRules, "").as_ref(), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] join_authed_user.as_deref(), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] join_authed_user_membership, )? { return Ok(false); @@ -409,8 +409,8 @@ fn valid_membership_change( current_third_party_invite: Option, power_levels_event: Option, join_rules_event: Option, - #[cfg(feature = "unstable-pre-spec")] authed_user_id: Option<&UserId>, - #[cfg(feature = "unstable-pre-spec")] auth_user_membership: Option, + #[cfg(feature = "unstable-spec")] authed_user_id: Option<&UserId>, + #[cfg(feature = "unstable-spec")] auth_user_membership: Option, ) -> Result { #[derive(Deserialize)] struct GetThirdPartyInvite { @@ -462,26 +462,26 @@ fn valid_membership_change( let target_user_membership_event_id = target_user_membership_event.as_ref().map(|e| e.event_id()); - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "unstable-spec"))] let restricted = false; - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "unstable-spec"))] let allow_based_on_membership = false; - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "unstable-spec"))] let restricted_join_rules_auth = false; // FIXME: `JoinRule::Restricted(_)` can contain conditions that allow a user to join if // they are met. So far the spec talks about roomId based auth inheritance, the problem with // this is that ruma-state-res can only request events from one room at a time :( - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] let restricted = matches!(join_rules, JoinRule::Restricted(_)); - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] let allow_based_on_membership = matches!(target_user_current_membership, MembershipState::Invite | MembershipState::Join) || authed_user_id.is_none(); - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] let restricted_join_rules_auth = if let Some(authed_user_id) = authed_user_id { // Is the authorised user allowed to invite users into this rooom let (auth_user_pl, invite_level) = if let Some(pl) = &power_levels_event { @@ -958,7 +958,7 @@ mod tests { member::{MembershipState, RoomMemberEventContent}, }; use serde_json::value::to_raw_value as to_raw_json_value; - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] use { crate::test_utils::{bob, room_id}, ruma_events::room::join_rules::{AllowRule, Restricted, RoomMembership}, @@ -966,7 +966,6 @@ mod tests { use ruma_events::EventType; - // #[cfg(not(feature = "unstable-pre-spec"))] #[test] fn test_ban_pass() { let _ = @@ -1008,15 +1007,14 @@ mod tests { None::, fetch_state(EventType::RoomPowerLevels, "".to_owned()), fetch_state(EventType::RoomJoinRules, "".to_owned()), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, ) .unwrap()); } - // #[cfg(not(feature = "unstable-pre-spec"))] #[test] fn test_ban_fail() { let _ = @@ -1058,15 +1056,15 @@ mod tests { None::, fetch_state(EventType::RoomPowerLevels, "".to_owned()), fetch_state(EventType::RoomJoinRules, "".to_owned()), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, ) .unwrap()); } - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] #[test] fn test_restricted_join_rule() { let _ = @@ -1209,9 +1207,9 @@ mod tests { None::, fetch_state(EventType::RoomPowerLevels, "".to_owned()), fetch_state(EventType::RoomJoinRules, "".to_owned()), - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] None, ) .unwrap()); diff --git a/crates/ruma-state-res/src/room_version.rs b/crates/ruma-state-res/src/room_version.rs index 1317533f..232dd0b4 100644 --- a/crates/ruma-state-res/src/room_version.rs +++ b/crates/ruma-state-res/src/room_version.rs @@ -105,10 +105,10 @@ impl RoomVersion { ..Self::V6 }; - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] pub const V8: Self = Self { restricted_join_rules: true, ..Self::V7 }; - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] pub const V9: Self = Self::V8; pub fn new(version: &RoomVersionId) -> Result { @@ -120,9 +120,9 @@ impl RoomVersion { RoomVersionId::V5 => Self::V5, RoomVersionId::V6 => Self::V6, RoomVersionId::V7 => Self::V7, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] RoomVersionId::V8 => Self::V8, - #[cfg(feature = "unstable-pre-spec")] + #[cfg(feature = "unstable-spec")] RoomVersionId::V9 => Self::V9, ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))), }) diff --git a/crates/ruma-state-res/src/test_utils.rs b/crates/ruma-state-res/src/test_utils.rs index 0fd08e9c..b30696d9 100644 --- a/crates/ruma-state-res/src/test_utils.rs +++ b/crates/ruma-state-res/src/test_utils.rs @@ -401,7 +401,7 @@ pub fn to_init_pdu_event( content, redacts: None, unsigned: BTreeMap::new(), - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "__unstable-pre-spec"))] origin: "foo".into(), auth_events: vec![], prev_events: vec![], @@ -441,7 +441,7 @@ where content, redacts: None, unsigned: BTreeMap::new(), - #[cfg(not(feature = "unstable-pre-spec"))] + #[cfg(not(feature = "__unstable-pre-spec"))] origin: "foo".into(), auth_events, prev_events, diff --git a/crates/ruma/Cargo.toml b/crates/ruma/Cargo.toml index 080324ac..2a9aca80 100644 --- a/crates/ruma/Cargo.toml +++ b/crates/ruma/Cargo.toml @@ -114,7 +114,7 @@ unstable-pre-spec = [ "ruma-events/unstable-pre-spec", "ruma-federation-api/unstable-pre-spec", "ruma-signatures/unstable-pre-spec", - "ruma-state-res/unstable-pre-spec", + "ruma-state-res/__unstable-pre-spec", # for tests # If you enable bleeding-edge pre-spec features, you # probably want things from the unstable spec too "unstable-spec",