state-res: Move room version 8, 9 logic from unstable-pre-spec to unstable-spec
This commit is contained in:
parent
760cbb94fc
commit
2706f24688
@ -16,8 +16,11 @@ all-features = true
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
compat = []
|
compat = []
|
||||||
unstable-pre-spec = ["ruma-events/unstable-pre-spec", "ruma-identifiers/unstable-spec"]
|
|
||||||
unstable-exhaustive-types = []
|
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]
|
[dependencies]
|
||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
|
@ -394,7 +394,7 @@ where
|
|||||||
content,
|
content,
|
||||||
redacts: None,
|
redacts: None,
|
||||||
unsigned: btreemap! {},
|
unsigned: btreemap! {},
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "__unstable-pre-spec"))]
|
||||||
origin: "foo".into(),
|
origin: "foo".into(),
|
||||||
auth_events,
|
auth_events,
|
||||||
prev_events,
|
prev_events,
|
||||||
|
@ -28,7 +28,7 @@ struct GetMembership {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct RoomMemberContentFields {
|
struct RoomMemberContentFields {
|
||||||
membership: Option<Raw<MembershipState>>,
|
membership: Option<Raw<MembershipState>>,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
join_authorised_via_users_server: Option<Raw<Box<UserId>>>,
|
join_authorised_via_users_server: Option<Raw<Box<UserId>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,10 +242,10 @@ pub fn auth_check<E: Event>(
|
|||||||
let target_user =
|
let target_user =
|
||||||
<&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
|
<&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 =
|
let join_authed_user =
|
||||||
content.join_authorised_via_users_server.as_ref().and_then(|u| u.deserialize().ok());
|
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 {
|
let join_authed_user_membership = if let Some(auth_user) = &join_authed_user {
|
||||||
fetch_state(&EventType::RoomMember, auth_user.as_str())
|
fetch_state(&EventType::RoomMember, auth_user.as_str())
|
||||||
.and_then(|mem| from_json_str::<GetMembership>(mem.content().get()).ok())
|
.and_then(|mem| from_json_str::<GetMembership>(mem.content().get()).ok())
|
||||||
@ -264,9 +264,9 @@ pub fn auth_check<E: Event>(
|
|||||||
current_third_party_invite,
|
current_third_party_invite,
|
||||||
power_levels_event.as_ref(),
|
power_levels_event.as_ref(),
|
||||||
fetch_state(&EventType::RoomJoinRules, "").as_ref(),
|
fetch_state(&EventType::RoomJoinRules, "").as_ref(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
join_authed_user.as_deref(),
|
join_authed_user.as_deref(),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
join_authed_user_membership,
|
join_authed_user_membership,
|
||||||
)? {
|
)? {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@ -409,8 +409,8 @@ fn valid_membership_change(
|
|||||||
current_third_party_invite: Option<impl Event>,
|
current_third_party_invite: Option<impl Event>,
|
||||||
power_levels_event: Option<impl Event>,
|
power_levels_event: Option<impl Event>,
|
||||||
join_rules_event: Option<impl Event>,
|
join_rules_event: Option<impl Event>,
|
||||||
#[cfg(feature = "unstable-pre-spec")] authed_user_id: Option<&UserId>,
|
#[cfg(feature = "unstable-spec")] authed_user_id: Option<&UserId>,
|
||||||
#[cfg(feature = "unstable-pre-spec")] auth_user_membership: Option<MembershipState>,
|
#[cfg(feature = "unstable-spec")] auth_user_membership: Option<MembershipState>,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct GetThirdPartyInvite {
|
struct GetThirdPartyInvite {
|
||||||
@ -462,26 +462,26 @@ fn valid_membership_change(
|
|||||||
let target_user_membership_event_id =
|
let target_user_membership_event_id =
|
||||||
target_user_membership_event.as_ref().map(|e| e.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;
|
let restricted = false;
|
||||||
|
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "unstable-spec"))]
|
||||||
let allow_based_on_membership = false;
|
let allow_based_on_membership = false;
|
||||||
|
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "unstable-spec"))]
|
||||||
let restricted_join_rules_auth = false;
|
let restricted_join_rules_auth = false;
|
||||||
// FIXME: `JoinRule::Restricted(_)` can contain conditions that allow a user to join if
|
// 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
|
// 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 :(
|
// 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(_));
|
let restricted = matches!(join_rules, JoinRule::Restricted(_));
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
let allow_based_on_membership =
|
let allow_based_on_membership =
|
||||||
matches!(target_user_current_membership, MembershipState::Invite | MembershipState::Join)
|
matches!(target_user_current_membership, MembershipState::Invite | MembershipState::Join)
|
||||||
|| authed_user_id.is_none();
|
|| 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 {
|
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
|
// Is the authorised user allowed to invite users into this rooom
|
||||||
let (auth_user_pl, invite_level) = if let Some(pl) = &power_levels_event {
|
let (auth_user_pl, invite_level) = if let Some(pl) = &power_levels_event {
|
||||||
@ -958,7 +958,7 @@ mod tests {
|
|||||||
member::{MembershipState, RoomMemberEventContent},
|
member::{MembershipState, RoomMemberEventContent},
|
||||||
};
|
};
|
||||||
use serde_json::value::to_raw_value as to_raw_json_value;
|
use serde_json::value::to_raw_value as to_raw_json_value;
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
use {
|
use {
|
||||||
crate::test_utils::{bob, room_id},
|
crate::test_utils::{bob, room_id},
|
||||||
ruma_events::room::join_rules::{AllowRule, Restricted, RoomMembership},
|
ruma_events::room::join_rules::{AllowRule, Restricted, RoomMembership},
|
||||||
@ -966,7 +966,6 @@ mod tests {
|
|||||||
|
|
||||||
use ruma_events::EventType;
|
use ruma_events::EventType;
|
||||||
|
|
||||||
// #[cfg(not(feature = "unstable-pre-spec"))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ban_pass() {
|
fn test_ban_pass() {
|
||||||
let _ =
|
let _ =
|
||||||
@ -1008,15 +1007,14 @@ mod tests {
|
|||||||
None::<StateEvent>,
|
None::<StateEvent>,
|
||||||
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
||||||
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(not(feature = "unstable-pre-spec"))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ban_fail() {
|
fn test_ban_fail() {
|
||||||
let _ =
|
let _ =
|
||||||
@ -1058,15 +1056,15 @@ mod tests {
|
|||||||
None::<StateEvent>,
|
None::<StateEvent>,
|
||||||
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
||||||
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_restricted_join_rule() {
|
fn test_restricted_join_rule() {
|
||||||
let _ =
|
let _ =
|
||||||
@ -1209,9 +1207,9 @@ mod tests {
|
|||||||
None::<StateEvent>,
|
None::<StateEvent>,
|
||||||
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
|
||||||
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
fetch_state(EventType::RoomJoinRules, "".to_owned()),
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap());
|
.unwrap());
|
||||||
|
@ -105,10 +105,10 @@ impl RoomVersion {
|
|||||||
..Self::V6
|
..Self::V6
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
pub const V8: Self = Self { restricted_join_rules: true, ..Self::V7 };
|
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 const V9: Self = Self::V8;
|
||||||
|
|
||||||
pub fn new(version: &RoomVersionId) -> Result<Self> {
|
pub fn new(version: &RoomVersionId) -> Result<Self> {
|
||||||
@ -120,9 +120,9 @@ impl RoomVersion {
|
|||||||
RoomVersionId::V5 => Self::V5,
|
RoomVersionId::V5 => Self::V5,
|
||||||
RoomVersionId::V6 => Self::V6,
|
RoomVersionId::V6 => Self::V6,
|
||||||
RoomVersionId::V7 => Self::V7,
|
RoomVersionId::V7 => Self::V7,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
RoomVersionId::V8 => Self::V8,
|
RoomVersionId::V8 => Self::V8,
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-spec")]
|
||||||
RoomVersionId::V9 => Self::V9,
|
RoomVersionId::V9 => Self::V9,
|
||||||
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
|
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
|
||||||
})
|
})
|
||||||
|
@ -401,7 +401,7 @@ pub fn to_init_pdu_event(
|
|||||||
content,
|
content,
|
||||||
redacts: None,
|
redacts: None,
|
||||||
unsigned: BTreeMap::new(),
|
unsigned: BTreeMap::new(),
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "__unstable-pre-spec"))]
|
||||||
origin: "foo".into(),
|
origin: "foo".into(),
|
||||||
auth_events: vec![],
|
auth_events: vec![],
|
||||||
prev_events: vec![],
|
prev_events: vec![],
|
||||||
@ -441,7 +441,7 @@ where
|
|||||||
content,
|
content,
|
||||||
redacts: None,
|
redacts: None,
|
||||||
unsigned: BTreeMap::new(),
|
unsigned: BTreeMap::new(),
|
||||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
#[cfg(not(feature = "__unstable-pre-spec"))]
|
||||||
origin: "foo".into(),
|
origin: "foo".into(),
|
||||||
auth_events,
|
auth_events,
|
||||||
prev_events,
|
prev_events,
|
||||||
|
@ -114,7 +114,7 @@ unstable-pre-spec = [
|
|||||||
"ruma-events/unstable-pre-spec",
|
"ruma-events/unstable-pre-spec",
|
||||||
"ruma-federation-api/unstable-pre-spec",
|
"ruma-federation-api/unstable-pre-spec",
|
||||||
"ruma-signatures/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
|
# If you enable bleeding-edge pre-spec features, you
|
||||||
# probably want things from the unstable spec too
|
# probably want things from the unstable spec too
|
||||||
"unstable-spec",
|
"unstable-spec",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user