mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Remove workarounds for matrix-appservice-irc
This commit is contained in:
@@ -51,49 +51,23 @@ pub(crate) async fn get_register_available_route(
|
|||||||
InsecureClientIp(client): InsecureClientIp,
|
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")
|
|
||||||
});
|
|
||||||
|
|
||||||
if services
|
|
||||||
.globals
|
|
||||||
.forbidden_usernames()
|
|
||||||
.is_match(&body.username)
|
|
||||||
{
|
|
||||||
return Err!(Request(Forbidden("Username is forbidden")));
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't force the username lowercase if it's from matrix-appservice-irc
|
|
||||||
let body_username = if is_matrix_appservice_irc {
|
|
||||||
body.username.clone()
|
|
||||||
} else {
|
|
||||||
body.username.to_lowercase()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id =
|
let user_id =
|
||||||
match UserId::parse_with_server_name(&body_username, services.globals.server_name()) {
|
match UserId::parse_with_server_name(&body.username, services.globals.server_name()) {
|
||||||
| Ok(user_id) => {
|
| Ok(user_id) => {
|
||||||
if let Err(e) = user_id.validate_strict() {
|
if let Err(e) = user_id.validate_strict() {
|
||||||
// unless the username is from the broken matrix appservice IRC bridge, we
|
return Err!(Request(InvalidUsername(debug_warn!(
|
||||||
// should follow synapse's behaviour on not allowing things like spaces
|
"Username {} contains disallowed characters or spaces: {e}",
|
||||||
// and UTF-8 characters in usernames
|
body.username
|
||||||
if !is_matrix_appservice_irc {
|
))));
|
||||||
return Err!(Request(InvalidUsername(debug_warn!(
|
|
||||||
"Username {body_username} contains disallowed characters or spaces: \
|
|
||||||
{e}"
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
user_id
|
user_id
|
||||||
},
|
},
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
return Err!(Request(InvalidUsername(debug_warn!(
|
return Err!(Request(InvalidUsername(debug_warn!(
|
||||||
"Username {body_username} is not valid: {e}"
|
"Username {} is not valid: {e}",
|
||||||
|
body.username
|
||||||
))));
|
))));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ pub(crate) async fn register_route(
|
|||||||
let user_id = determine_registration_user_id(
|
let user_id = determine_registration_user_id(
|
||||||
&services,
|
&services,
|
||||||
body.username.clone(),
|
body.username.clone(),
|
||||||
body.appservice_info.as_ref(),
|
|
||||||
is_guest,
|
is_guest,
|
||||||
emergency_mode_enabled,
|
emergency_mode_enabled,
|
||||||
)
|
)
|
||||||
@@ -478,11 +477,10 @@ async fn create_registration_uiaa_session(
|
|||||||
async fn determine_registration_user_id(
|
async fn determine_registration_user_id(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
supplied_username: Option<String>,
|
supplied_username: Option<String>,
|
||||||
appservice_info: Option<&service::appservice::RegistrationInfo>,
|
|
||||||
is_guest: bool,
|
is_guest: bool,
|
||||||
emergency_mode_enabled: bool,
|
emergency_mode_enabled: bool,
|
||||||
) -> Result<OwnedUserId> {
|
) -> Result<OwnedUserId> {
|
||||||
if let Some(mut supplied_username) = supplied_username
|
if let Some(supplied_username) = supplied_username
|
||||||
&& !is_guest
|
&& !is_guest
|
||||||
{
|
{
|
||||||
// The user gets to pick their username. Do some validation to make sure it's
|
// The user gets to pick their username. Do some validation to make sure it's
|
||||||
@@ -498,18 +496,6 @@ async fn determine_registration_user_id(
|
|||||||
return Err!(Request(Forbidden("Username is forbidden")));
|
return Err!(Request(Forbidden("Username is forbidden")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround for https://github.com/matrix-org/matrix-appservice-irc/issues/1780 due to inactivity of fixing the issue
|
|
||||||
let is_matrix_appservice_irc = appservice_info.is_some_and(|appservice| {
|
|
||||||
appservice.registration.id == "irc"
|
|
||||||
|| appservice.registration.id.contains("matrix-appservice-irc")
|
|
||||||
|| appservice.registration.id.contains("matrix_appservice_irc")
|
|
||||||
});
|
|
||||||
|
|
||||||
// Don't force the username lowercase if it's from matrix-appservice-irc.
|
|
||||||
if !is_matrix_appservice_irc {
|
|
||||||
supplied_username = supplied_username.to_lowercase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and validate the user ID
|
// Create and validate the user ID
|
||||||
let user_id = match UserId::parse_with_server_name(
|
let user_id = match UserId::parse_with_server_name(
|
||||||
&supplied_username,
|
&supplied_username,
|
||||||
@@ -517,10 +503,9 @@ async fn determine_registration_user_id(
|
|||||||
) {
|
) {
|
||||||
| Ok(user_id) => {
|
| Ok(user_id) => {
|
||||||
if let Err(e) = user_id.validate_strict() {
|
if let Err(e) = user_id.validate_strict() {
|
||||||
// unless the username is from the broken matrix appservice IRC bridge, or
|
// Unless we are in emergency mode, we should follow synapse's behaviour on
|
||||||
// we are in emergency mode, we should follow synapse's behaviour on
|
|
||||||
// not allowing things like spaces and UTF-8 characters in usernames
|
// not allowing things like spaces and UTF-8 characters in usernames
|
||||||
if !is_matrix_appservice_irc && !emergency_mode_enabled {
|
if !emergency_mode_enabled {
|
||||||
return Err!(Request(InvalidUsername(debug_warn!(
|
return Err!(Request(InvalidUsername(debug_warn!(
|
||||||
"Username {supplied_username} contains disallowed characters or \
|
"Username {supplied_username} contains disallowed characters or \
|
||||||
spaces: {e}"
|
spaces: {e}"
|
||||||
@@ -550,7 +535,7 @@ async fn determine_registration_user_id(
|
|||||||
|
|
||||||
Ok(user_id)
|
Ok(user_id)
|
||||||
} else {
|
} else {
|
||||||
// The user is a guest or is lacking in creativity. Generate a username for
|
// The user is a guest or didn't specify a username. Generate a username for
|
||||||
// them.
|
// them.
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
Reference in New Issue
Block a user