add workaround for matrix-appservice-irc using historical localparts
see https://github.com/matrix-org/matrix-appservice-irc/issues/1780 Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
6f37a251fb
commit
0387871063
1 changed files with 21 additions and 2 deletions
|
@ -48,10 +48,19 @@ pub(crate) async fn get_register_available_route(
|
||||||
State(services): State<crate::State>, InsecureClientIp(client): InsecureClientIp,
|
State(services): State<crate::State>, InsecureClientIp(client): InsecureClientIp,
|
||||||
body: Ruma<get_username_availability::v3::Request>,
|
body: Ruma<get_username_availability::v3::Request>,
|
||||||
) -> Result<get_username_availability::v3::Response> {
|
) -> Result<get_username_availability::v3::Response> {
|
||||||
|
// workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue
|
||||||
|
let is_matrix_appservice_irc = body.appservice_info.as_ref().is_some_and(|appservice| {
|
||||||
|
appservice.registration.id == "irc"
|
||||||
|
|| appservice.registration.id.contains("matrix-appservice-irc")
|
||||||
|
|| appservice.registration.id.contains("matrix_appservice_irc")
|
||||||
|
});
|
||||||
|
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = UserId::parse_with_server_name(body.username.to_lowercase(), services.globals.server_name())
|
let user_id = UserId::parse_with_server_name(body.username.to_lowercase(), services.globals.server_name())
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|user_id| !user_id.is_historical() && services.globals.user_is_local(user_id))
|
.filter(|user_id| {
|
||||||
|
(!user_id.is_historical() || is_matrix_appservice_irc) && services.globals.user_is_local(user_id)
|
||||||
|
})
|
||||||
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
|
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
|
||||||
|
|
||||||
// Check if username is creative enough
|
// Check if username is creative enough
|
||||||
|
@ -134,12 +143,22 @@ pub(crate) async fn register_route(
|
||||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "Registration temporarily disabled."));
|
return Err(Error::BadRequest(ErrorKind::forbidden(), "Registration temporarily disabled."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue
|
||||||
|
let is_matrix_appservice_irc = body.appservice_info.as_ref().is_some_and(|appservice| {
|
||||||
|
appservice.registration.id == "irc"
|
||||||
|
|| appservice.registration.id.contains("matrix-appservice-irc")
|
||||||
|
|| appservice.registration.id.contains("matrix_appservice_irc")
|
||||||
|
});
|
||||||
|
|
||||||
let user_id = match (&body.username, is_guest) {
|
let user_id = match (&body.username, is_guest) {
|
||||||
(Some(username), false) => {
|
(Some(username), false) => {
|
||||||
let proposed_user_id =
|
let proposed_user_id =
|
||||||
UserId::parse_with_server_name(username.to_lowercase(), services.globals.server_name())
|
UserId::parse_with_server_name(username.to_lowercase(), services.globals.server_name())
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|user_id| !user_id.is_historical() && services.globals.user_is_local(user_id))
|
.filter(|user_id| {
|
||||||
|
(!user_id.is_historical() || is_matrix_appservice_irc)
|
||||||
|
&& services.globals.user_is_local(user_id)
|
||||||
|
})
|
||||||
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
|
.ok_or(Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid."))?;
|
||||||
|
|
||||||
if services.users.exists(&proposed_user_id).await {
|
if services.users.exists(&proposed_user_id).await {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue