state-res: Remove unstable-spec feature

Everything that was gated behind it was stabilized with Matrix v1.2.
This commit is contained in:
Jonas Platte 2022-02-02 23:19:46 +01:00
parent 71a7dbdc43
commit a55df1ef9d
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 6 additions and 39 deletions

View File

@ -17,10 +17,9 @@ all-features = true
[features]
compat = []
unstable-exhaustive-types = []
unstable-spec = []
# Private, only used in test / benchmarking code
__unstable-pre-spec = ["ruma-events/unstable-pre-spec", "unstable-spec"]
__unstable-pre-spec = ["ruma-events/unstable-pre-spec"]
[dependencies]
itertools = "0.10.0"

View File

@ -28,7 +28,6 @@ struct GetMembership {
#[derive(Deserialize)]
struct RoomMemberContentFields {
membership: Option<Raw<MembershipState>>,
#[cfg(feature = "unstable-spec")]
join_authorised_via_users_server: Option<Raw<Box<UserId>>>,
}
@ -242,10 +241,8 @@ pub fn auth_check<E: Event>(
let target_user =
<&UserId>::try_from(state_key).map_err(|e| Error::InvalidPdu(format!("{}", e)))?;
#[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-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::<GetMembership>(mem.content().get()).ok())
@ -264,9 +261,7 @@ pub fn auth_check<E: Event>(
current_third_party_invite,
power_levels_event.as_ref(),
fetch_state(&EventType::RoomJoinRules, "").as_ref(),
#[cfg(feature = "unstable-spec")]
join_authed_user.as_deref(),
#[cfg(feature = "unstable-spec")]
join_authed_user_membership,
)? {
return Ok(false);
@ -409,8 +404,8 @@ fn valid_membership_change(
current_third_party_invite: Option<impl Event>,
power_levels_event: Option<impl Event>,
join_rules_event: Option<impl Event>,
#[cfg(feature = "unstable-spec")] authed_user_id: Option<&UserId>,
#[cfg(feature = "unstable-spec")] auth_user_membership: Option<MembershipState>,
authed_user_id: Option<&UserId>,
auth_user_membership: Option<MembershipState>,
) -> Result<bool> {
#[derive(Deserialize)]
struct GetThirdPartyInvite {
@ -462,26 +457,15 @@ 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-spec"))]
let restricted = false;
#[cfg(not(feature = "unstable-spec"))]
let allow_based_on_membership = false;
#[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-spec")]
let restricted = matches!(join_rules, JoinRule::Restricted(_));
#[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-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 {
@ -948,21 +932,16 @@ mod tests {
use crate::{
event_auth::valid_membership_change,
test_utils::{
alice, charlie, ella, event_id, member_content_ban, to_pdu_event, StateEvent,
INITIAL_EVENTS,
alice, bob, charlie, ella, event_id, member_content_ban, room_id, to_pdu_event,
StateEvent, INITIAL_EVENTS,
},
Event, RoomVersion, StateMap,
};
use ruma_events::room::{
join_rules::{JoinRule, RoomJoinRulesEventContent},
join_rules::{AllowRule, JoinRule, Restricted, RoomJoinRulesEventContent, RoomMembership},
member::{MembershipState, RoomMemberEventContent},
};
use serde_json::value::to_raw_value as to_raw_json_value;
#[cfg(feature = "unstable-spec")]
use {
crate::test_utils::{bob, room_id},
ruma_events::room::join_rules::{AllowRule, Restricted, RoomMembership},
};
use ruma_events::EventType;
@ -1007,9 +986,7 @@ mod tests {
None::<StateEvent>,
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
fetch_state(EventType::RoomJoinRules, "".to_owned()),
#[cfg(feature = "unstable-spec")]
None,
#[cfg(feature = "unstable-spec")]
None,
)
.unwrap());
@ -1056,15 +1033,12 @@ mod tests {
None::<StateEvent>,
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
fetch_state(EventType::RoomJoinRules, "".to_owned()),
#[cfg(feature = "unstable-spec")]
None,
#[cfg(feature = "unstable-spec")]
None,
)
.unwrap());
}
#[cfg(feature = "unstable-spec")]
#[test]
fn test_restricted_join_rule() {
let _ =
@ -1207,9 +1181,7 @@ mod tests {
None::<StateEvent>,
fetch_state(EventType::RoomPowerLevels, "".to_owned()),
fetch_state(EventType::RoomJoinRules, "".to_owned()),
#[cfg(feature = "unstable-spec")]
None,
#[cfg(feature = "unstable-spec")]
None,
)
.unwrap());

View File

@ -105,10 +105,8 @@ impl RoomVersion {
..Self::V6
};
#[cfg(feature = "unstable-spec")]
pub const V8: Self = Self { restricted_join_rules: true, ..Self::V7 };
#[cfg(feature = "unstable-spec")]
pub const V9: Self = Self::V8;
pub fn new(version: &RoomVersionId) -> Result<Self> {
@ -120,9 +118,7 @@ impl RoomVersion {
RoomVersionId::V5 => Self::V5,
RoomVersionId::V6 => Self::V6,
RoomVersionId::V7 => Self::V7,
#[cfg(feature = "unstable-spec")]
RoomVersionId::V8 => Self::V8,
#[cfg(feature = "unstable-spec")]
RoomVersionId::V9 => Self::V9,
ver => return Err(Error::Unsupported(format!("found version `{}`", ver.as_str()))),
})