Restructure full_register arguments with names and defaults.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-12-23 02:50:56 +00:00
parent 5b0dfaeef6
commit 4150b917d8
5 changed files with 58 additions and 16 deletions

View File

@@ -22,7 +22,7 @@ use tuwunel_core::{
};
use tuwunel_database::{Deserialized, Json, Map};
pub use self::keys::parse_master_key;
pub use self::{keys::parse_master_key, register::Register};
pub struct Service {
services: Arc<crate::services::OnceServices>,

View File

@@ -6,19 +6,45 @@ use tuwunel_core::{Err, Result, error, implement, info, is_equal_to, warn};
use crate::appservice::RegistrationInfo;
#[derive(Debug, Default)]
pub struct Register<'a> {
pub user_id: Option<&'a UserId>,
pub username: Option<&'a str>,
pub password: Option<&'a str>,
pub origin: Option<&'a str>,
pub appservice_info: Option<&'a RegistrationInfo>,
pub is_guest: bool,
pub grant_first_user_admin: bool,
}
/// Fully register a local user
///
/// Returns a device id and access token for the registered user
#[implement(super::Service)]
#[tracing::instrument(level = "info", skip(self))]
pub async fn full_register(
&self,
user_id: &UserId,
password: Option<&str>,
origin: Option<&str>,
appservice_info: Option<&RegistrationInfo>,
is_guest: bool,
grant_admin: bool,
Register {
username,
user_id,
password,
origin,
appservice_info,
is_guest,
grant_first_user_admin,
}: Register<'_>,
) -> Result {
let ref user_id = user_id
.map(ToOwned::to_owned)
.map(Ok)
.or_else(|| {
username.map(|username| {
UserId::parse_with_server_name(username, self.services.globals.server_name())
})
})
.transpose()?
.expect("Caller failed to supply either user_id or username parameter");
if !self.services.globals.user_is_local(user_id) {
return Err!("Cannot register remote user");
}
@@ -80,7 +106,7 @@ pub async fn full_register(
// users
// Note: the server user is generated first
if !is_guest
&& grant_admin
&& grant_first_user_admin
&& self.services.config.grant_admin_to_first_user
&& let Ok(admin_room) = self.services.admin.get_admin_room().await
&& self