use proper redacts field
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
9d1db7d171
commit
6c461025e5
2 changed files with 80 additions and 20 deletions
|
@ -19,7 +19,9 @@ use ruma::{
|
||||||
federation::event::{get_event, get_room_state_ids},
|
federation::event::{get_event, get_room_state_ids},
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
room::{create::RoomCreateEventContent, server_acl::RoomServerAclEventContent},
|
room::{
|
||||||
|
create::RoomCreateEventContent, redaction::RoomRedactionEventContent, server_acl::RoomServerAclEventContent,
|
||||||
|
},
|
||||||
StateEventType, TimelineEventType,
|
StateEventType, TimelineEventType,
|
||||||
},
|
},
|
||||||
int,
|
int,
|
||||||
|
@ -531,17 +533,45 @@ impl Service {
|
||||||
auth_events.get(&(k.clone(), s.to_owned()))
|
auth_events.get(&(k.clone(), s.to_owned()))
|
||||||
})
|
})
|
||||||
.map_err(|_e| Error::BadRequest(ErrorKind::forbidden(), "Auth check failed."))?
|
.map_err(|_e| Error::BadRequest(ErrorKind::forbidden(), "Auth check failed."))?
|
||||||
|| if let Some(redact_id) = &incoming_pdu.redacts {
|
|| incoming_pdu.kind == TimelineEventType::RoomRedaction
|
||||||
incoming_pdu.kind == TimelineEventType::RoomRedaction
|
&& match room_version_id {
|
||||||
&& !services().rooms.state_accessor.user_can_redact(
|
RoomVersionId::V1
|
||||||
redact_id,
|
| RoomVersionId::V2
|
||||||
&incoming_pdu.sender,
|
| RoomVersionId::V3
|
||||||
&incoming_pdu.room_id,
|
| RoomVersionId::V4
|
||||||
true,
|
| RoomVersionId::V5
|
||||||
)?
|
| RoomVersionId::V6
|
||||||
} else {
|
| RoomVersionId::V7
|
||||||
false
|
| RoomVersionId::V8
|
||||||
};
|
| RoomVersionId::V9
|
||||||
|
| RoomVersionId::V10 => {
|
||||||
|
if let Some(redact_id) = &incoming_pdu.redacts {
|
||||||
|
!services().rooms.state_accessor.user_can_redact(
|
||||||
|
redact_id,
|
||||||
|
&incoming_pdu.sender,
|
||||||
|
&incoming_pdu.room_id,
|
||||||
|
true,
|
||||||
|
)?
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
let content = serde_json::from_str::<RoomRedactionEventContent>(incoming_pdu.content.get())
|
||||||
|
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
||||||
|
|
||||||
|
if let Some(redact_id) = &content.redacts {
|
||||||
|
!services().rooms.state_accessor.user_can_redact(
|
||||||
|
redact_id,
|
||||||
|
&incoming_pdu.sender,
|
||||||
|
&incoming_pdu.room_id,
|
||||||
|
true,
|
||||||
|
)?
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// 13. Use state resolution to find new room state
|
// 13. Use state resolution to find new room state
|
||||||
|
|
||||||
|
|
|
@ -860,14 +860,44 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If redaction event is not authorized, do not append it to the timeline
|
// If redaction event is not authorized, do not append it to the timeline
|
||||||
if let Some(redact_id) = &pdu.redacts {
|
if pdu.kind == TimelineEventType::RoomRedaction {
|
||||||
if pdu.kind == TimelineEventType::RoomRedaction
|
match services().rooms.state.get_room_version(&pdu.room_id)? {
|
||||||
&& !services()
|
RoomVersionId::V1
|
||||||
.rooms
|
| RoomVersionId::V2
|
||||||
.state_accessor
|
| RoomVersionId::V3
|
||||||
.user_can_redact(redact_id, &pdu.sender, &pdu.room_id, false)?
|
| RoomVersionId::V4
|
||||||
{
|
| RoomVersionId::V5
|
||||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "User cannot redact this event"));
|
| RoomVersionId::V6
|
||||||
|
| RoomVersionId::V7
|
||||||
|
| RoomVersionId::V8
|
||||||
|
| RoomVersionId::V9
|
||||||
|
| RoomVersionId::V10 => {
|
||||||
|
if let Some(redact_id) = &pdu.redacts {
|
||||||
|
if !services().rooms.state_accessor.user_can_redact(
|
||||||
|
redact_id,
|
||||||
|
&pdu.sender,
|
||||||
|
&pdu.room_id,
|
||||||
|
false,
|
||||||
|
)? {
|
||||||
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "User cannot redact this event."));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
let content = serde_json::from_str::<RoomRedactionEventContent>(pdu.content.get())
|
||||||
|
.map_err(|_| Error::bad_database("Invalid content in redaction pdu."))?;
|
||||||
|
|
||||||
|
if let Some(redact_id) = &content.redacts {
|
||||||
|
if !services().rooms.state_accessor.user_can_redact(
|
||||||
|
redact_id,
|
||||||
|
&pdu.sender,
|
||||||
|
&pdu.room_id,
|
||||||
|
false,
|
||||||
|
)? {
|
||||||
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "User cannot redact this event."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue