A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(admin): give sign-up settings a page, label sign-up links
Hampusbfe081e48d88
diff --git a/fluxer_admin/src/routes/registrations.rs b/fluxer_admin/src/routes/registrations.rsindex f36be69ce..d4a855694 100644--- a/fluxer_admin/src/routes/registrations.rs+++ b/fluxer_admin/src/routes/registrations.rs@@ -1,7 +1,10 @@// SPDX-License-Identifier: AGPL-3.0-or-lateruse crate::{- api::{client::AdminApiClient, types::PendingRegistrationStatus},+ api::{+ client::{AdminApiClient, ApiResultExt},+ types::{PendingRegistrationStatus, RegistrationUrlResponse},+ },middleware::{auth::AuthContext,csrf::CsrfToken,@@ -40,6 +43,15 @@ pub fn router() -> Router<AppState> {)}+async fn registration_urls(client: &AdminApiClient) -> Vec<RegistrationUrlResponse> {+ client+ .get_instance_config()+ .await+ .log_error("load registration URLs for pending registrations")+ .map(|instance_config| instance_config.registration.urls)+ .unwrap_or_default()+}+async fn pending_registrations_page(State(state): State<AppState>,auth: axum::Extension<AuthContext>,@@ -47,7 +59,11 @@ async fn pending_registrations_page() -> Response {let config = state.config();let client = AdminApiClient::new(state.http_client(), config, &auth.0.session);- let pending_registrations = match client.list_pending_registrations().await {+ let (pending_registrations, registration_urls) = tokio::join!(+ client.list_pending_registrations(),+ registration_urls(&client)+ );+ let pending_registrations = match pending_registrations {Ok(pending_registrations) => Some(pending_registrations),Err(error) => {tracing::warn!(%error, "admin API request failed: list pending registrations");@@ -59,6 +75,7 @@ async fn pending_registrations_page(&auth.0,&csrf.0.0,pending_registrations.as_deref(),+ ®istration_urls,);Html(markup.into_string()).into_response()}@@ -124,11 +141,13 @@ async fn decide_pending_registration(Ok(pending_registrations) => {let flash = FlashData::success(success_message);if htmx::targets(&headers, "pending-registration-list") {+ let registration_urls = registration_urls(&client).await;let markup = maud::html! {(templates::pages::pending_registrations::pending_registration_list(config,&csrf.0.0,&pending_registrations,+ ®istration_urls,))(pending_registration_count_markup(u32::try_from(pending_registrations.len()).ok(),diff --git a/fluxer_admin/src/routes/system_actions/registration_urls.rs b/fluxer_admin/src/routes/system_actions/registration_urls.rsnew file mode 100644index 000000000..399d3395a--- /dev/null+++ b/fluxer_admin/src/routes/system_actions/registration_urls.rs@@ -0,0 +1,216 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++use super::{render_fragment_with_toast, with_api_reason};+use crate::{+ api::{client::AdminApiClient, types::CreateRegistrationUrlRequest},+ config::AdminConfig,+ middleware::{flash::FlashData, htmx},+ templates,+ utils::forms::{MultiValueForm, clean_string},+};+use axum::{http::HeaderMap, response::Response};++pub(super) enum Action {+ Create,+ Rename,+ Revoke,+ Remove,+}++pub(super) enum Outcome {+ Flash(FlashData),+ Response(Response),+}++pub(super) async fn run(+ client: &AdminApiClient,+ form: &MultiValueForm,+ headers: &HeaderMap,+ config: &AdminConfig,+ csrf_token: &str,+ action: Action,+) -> Outcome {+ match action {+ Action::Create => {+ let request = match build_create_registration_url_request(form) {+ Ok(request) => request,+ Err(message) => return Outcome::Flash(FlashData::error(message)),+ };+ let response = match client.create_registration_url(&request).await {+ Ok(response) => response,+ Err(error) => {+ tracing::warn!(%error, "admin API request failed: create registration URL");+ return Outcome::Flash(FlashData::error(with_api_reason(+ "Failed to create registration URL",+ &error,+ )));+ }+ };+ let flash = FlashData::success("Registration URL created");+ if !htmx::targets(headers, "registration-url-list") {+ return Outcome::Flash(FlashData::success(format!(+ "Registration URL created: {}",+ response.url+ )));+ }+ let instance_config = match client.get_instance_config().await {+ Ok(instance_config) => instance_config,+ Err(error) => {+ tracing::warn!(%error, "admin API request failed: reload registration URLs");+ return Outcome::Response(htmx::toast_response(&FlashData::error(+ "Registration URL created, but failed to reload the list",+ )));+ }+ };+ Outcome::Response(render_registration_url_list_response(+ config,+ csrf_token,+ &instance_config,+ &flash,+ ))+ }+ Action::Rename => {+ let Some(id) = form.clean("registration_url_id") else {+ return Outcome::Flash(FlashData::error("Registration URL ID is required"));+ };+ let label = form.clean("registration_url_label");+ let instance_config = match client.rename_registration_url(&id, label.as_deref()).await+ {+ Ok(instance_config) => instance_config,+ Err(error) => {+ tracing::warn!(%error, "admin API request failed: rename registration URL");+ return Outcome::Flash(FlashData::error("Failed to rename registration URL"));+ }+ };+ let flash = FlashData::success("Registration URL renamed");+ if htmx::targets(headers, "registration-url-list") {+ return Outcome::Response(render_registration_url_list_response(+ config,+ csrf_token,+ &instance_config,+ &flash,+ ));+ }+ Outcome::Flash(flash)+ }+ Action::Revoke | Action::Remove => {+ let Some(id) = form.clean("registration_url_id") else {+ return Outcome::Flash(FlashData::error("Registration URL ID is required"));+ };+ let instance_config = match client.revoke_registration_url(&id).await {+ Ok(instance_config) => instance_config,+ Err(error) => {+ tracing::warn!(%error, "admin API request failed: revoke registration URL");+ return Outcome::Flash(FlashData::error("Failed to revoke registration URL"));+ }+ };+ let flash = FlashData::success(match action {+ Action::Remove => "Registration URL removed",+ _ => "Registration URL revoked",+ });+ if htmx::targets(headers, "registration-url-list") {+ return Outcome::Response(render_registration_url_list_response(+ config,+ csrf_token,+ &instance_config,+ &flash,+ ));+ }+ Outcome::Flash(flash)+ }+ }+}++fn render_registration_url_list_response(+ config: &AdminConfig,+ csrf_token: &str,+ instance_config: &crate::api::types::InstanceConfigResponse,+ flash: &FlashData,+) -> Response {+ render_fragment_with_toast(+ templates::pages::instance_registration::registration_url_list(+ config,+ csrf_token,+ &instance_config.registration.urls,+ ),+ flash,+ )+}++fn build_create_registration_url_request(+ form: &MultiValueForm,+) -> Result<CreateRegistrationUrlRequest, &'static str> {+ let label = form.clean("registration_url_label");+ if label+ .as_ref()+ .is_some_and(|value| value.chars().count() > 120)+ {+ return Err("Label must be 120 characters or fewer");+ }+ Ok(CreateRegistrationUrlRequest {+ label,+ expires_at: parse_registration_url_expires_at(form)?,+ max_uses: parse_registration_url_max_uses(form)?,+ approval_required: form.bool_value("registration_url_approval_required"),+ invite_code: parse_invite_code(form.clean("registration_url_invite_code"))?,+ })+}++fn parse_invite_code(value: Option<String>) -> Result<Option<String>, &'static str> {+ let Some(value) = value else {+ return Ok(None);+ };+ let code = value+ .trim_end_matches('/')+ .rsplit('/')+ .next()+ .unwrap_or_default()+ .to_owned();+ if code.is_empty()+ || code.len() > 64+ || !code.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')+ {+ return Err("Enter an invite code or an invite link");+ }+ Ok(Some(code))+}++fn parse_registration_url_expires_at(+ form: &MultiValueForm,+) -> Result<Option<String>, &'static str> {+ let Some(value) = form+ .first("registration_url_expires_in_days")+ .and_then(clean_string)+ else {+ return Ok(None);+ };+ let days = value+ .parse::<i64>()+ .map_err(|_| "Expires in days must be a positive whole number")?;+ if days < 1 {+ return Err("Expires in days must be a positive whole number");+ }+ let expires_at = time::OffsetDateTime::now_utc()+ .checked_add(time::Duration::days(days))+ .ok_or("Expiration is too far in the future")?;+ expires_at+ .format(&time::format_description::well_known::Rfc3339)+ .map(Some)+ .map_err(|_| "Failed to format expiration timestamp")+}++fn parse_registration_url_max_uses(form: &MultiValueForm) -> Result<Option<u64>, &'static str> {+ let Some(value) = form+ .first("registration_url_max_uses")+ .and_then(clean_string)+ else {+ return Ok(None);+ };+ let max_uses = value+ .parse::<u64>()+ .map_err(|_| "Max uses must be a positive whole number")?;+ if max_uses == 0 || max_uses > 1_000_000 {+ return Err("Max uses must be between 1 and 1,000,000");+ }+ Ok(Some(max_uses))+}diff --git a/fluxer_admin/src/templates/pages/instance_registration.rs b/fluxer_admin/src/templates/pages/instance_registration.rsnew file mode 100644index 000000000..0465e06f2--- /dev/null+++ b/fluxer_admin/src/templates/pages/instance_registration.rs@@ -0,0 +1,397 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++use super::instance_config::{+ REGISTRATION_ALLOWED_EMAIL_DOMAINS_FIELD, allowed_domains_input,+ format_optional_admin_timestamp,+};+use crate::templates::pages::instance_config::ConfigForm;+use crate::{+ api::types::{AccountIdentityMode, InstanceRegistrationResponse, RegistrationUrlResponse},+ config::AdminConfig,+ templates::components::{+ badge::{BadgeVariant, badge},+ form::{+ Checkbox, FORM_INPUT_CLASS, NumberField, csrf_input, form_actions, form_field_group,+ select_input, submit_button, text_input,+ },+ section_card::section_card_with_description,+ },+ utils::timestamps::format_admin_timestamp,+};+use maud::{Markup, html};++pub(super) fn registration_config_section(+ config: &AdminConfig,+ config_form: ConfigForm<'_>,+ registration: &InstanceRegistrationResponse,+ account_identity: AccountIdentityMode,+) -> Markup {+ let base = &config.base_path;+ section_card_with_description(+ "Registration Controls",+ "Control public registration and admin-issued registration URLs.",+ html! {+ div class="space-y-8" {+ (registration_policy_form(base, config_form, registration, account_identity))+ (create_registration_url_form(base, config_form.csrf_token))+ (registration_url_list(config, config_form.csrf_token, ®istration.urls))+ }+ },+ )+}++fn registration_policy_form(+ base: &str,+ config_form: ConfigForm<'_>,+ registration: &InstanceRegistrationResponse,+ account_identity: AccountIdentityMode,+) -> Markup {+ html! {+ div class="space-y-4" {+ h3 class="text-sm font-semibold text-neutral-900" { "Registration Policy" }+ form method="post" action={(base) "/instance-config?action=update_registration"} {+ (config_form.fields())+ div class="space-y-4" {+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2" {+ (select_input("registration_mode", "Mode", &[+ ("open", "Open"),+ ("approval", "Approval required"),+ ("closed", "Closed"),+ ], registration.mode.as_str()))+ div class="flex items-end pb-1" {+ (Checkbox {+ name: "admin_registration_urls_enabled",+ value: "true",+ label: "Admin registration URLs enabled",+ checked: registration.admin_registration_urls_enabled,+ enabled: true,+ }.render())+ }+ }+ @if !account_identity.is_username() {+ (allowed_domains_input(+ REGISTRATION_ALLOWED_EMAIL_DOMAINS_FIELD,+ ®istration.allowed_email_domains.join("\n"),+ "Only email addresses on these domains (one per line) can sign up, claim an account or become an account's new email. People with an admin-issued registration URL can use any domain. Leave empty to allow any domain.",+ ))+ }+ (form_actions(html! {+ (submit_button("Save Registration Policy"))+ }))+ }+ }+ }+ }+}++fn create_registration_url_form(base: &str, csrf_token: &str) -> Markup {+ let action = format!("{base}/instance-config?action=create_registration_url");+ html! {+ div class="space-y-4 border-t border-neutral-200 pt-6" {+ h3 class="text-sm font-semibold text-neutral-900" { "Create Admin-Issued Registration URL" }+ form method="post" action=(&action)+ hx-post=(&action)+ hx-target="#registration-url-list"+ hx-swap="outerHTML"+ hx-push-url="false"+ data-admin-allow-swap="true" {+ (csrf_input(csrf_token))+ div class="space-y-4" {+ div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4" {+ (text_input(+ "registration_url_label",+ "Label",+ "",+ "Invite batch, partner, or support case",+ ))+ (NumberField {+ name: "registration_url_expires_in_days",+ label: "Expires In Days",+ value: "",+ min: Some(1),+ max: None,+ step: "1",+ helper: Some("Leave blank for no expiration."),+ placeholder: None,+ }.render())+ (NumberField {+ name: "registration_url_max_uses",+ label: "Max Uses",+ value: "",+ min: Some(1),+ max: Some(1_000_000),+ step: "1",+ helper: Some("Leave blank for unlimited uses."),+ placeholder: None,+ }.render())+ div class="flex items-end pb-1" {+ (Checkbox {+ name: "registration_url_approval_required",+ value: "true",+ label: "Approval required",+ checked: false,+ enabled: true,+ }.render())+ }+ }+ (form_field_group(+ "Join a community after sign-up (optional)",+ "registration_url_invite_code",+ false,+ None,+ Some("An invite code or invite link. People who sign up through this URL accept the invite once their account exists."),+ html! {+ input type="text" id="registration_url_invite_code" name="registration_url_invite_code"+ placeholder="abc123" class=(FORM_INPUT_CLASS);+ },+ ))+ (form_actions(html! {+ (submit_button("Create Registration URL"))+ }))+ }+ }+ }+ }+}++pub(crate) fn registration_url_list(+ config: &AdminConfig,+ csrf_token: &str,+ urls: &[RegistrationUrlResponse],+) -> Markup {+ let base = &config.base_path;+ html! {+ div id="registration-url-list" class="space-y-4 border-t border-neutral-200 pt-6" {+ h3 class="text-sm font-semibold text-neutral-900" { "Existing Registration URLs" }+ @if urls.is_empty() {+ p class="text-sm text-neutral-500" { "No admin-issued registration URLs." }+ } @else {+ div class="overflow-x-auto rounded-lg border border-neutral-200" {+ table class="min-w-[1100px] divide-y divide-neutral-200 text-sm" {+ thead class="bg-neutral-50" {+ tr {+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Label / URL" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Created" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Expires" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Uses" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Status" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Approval" }+ th scope="col" class="px-4 py-3 text-left font-semibold text-neutral-600" { "Action" }+ }+ }+ tbody class="divide-y divide-neutral-200 bg-white" {+ @for url in urls {+ (registration_url_row(config, base, csrf_token, url))+ }+ }+ }+ }+ }+ }+ }+}++fn registration_url_row(+ config: &AdminConfig,+ base: &str,+ csrf_token: &str,+ url: &RegistrationUrlResponse,+) -> Markup {+ let label = url.label.as_deref().unwrap_or("Unlabeled");+ let full_url = admin_issued_registration_url(config, &url.id);+ let created_at = format_admin_timestamp(&url.created_at);+ let expires_at = format_optional_admin_timestamp(url.expires_at.as_deref(), "Never");+ let uses = registration_url_uses_text(url);+ let status = registration_url_status(url);+ let approval = if url.approval_required {+ "Required"+ } else {+ "Not required"+ };+ let revoke_action = format!("{base}/instance-config?action=revoke_registration_url");+ let remove_action = format!("{base}/instance-config?action=remove_registration_url");+ let rename_action = format!("{base}/instance-config?action=rename_registration_url");+ html! {+ tr {+ td class="min-w-[28rem] px-4 py-3 align-top" {+ p class="font-medium text-neutral-900" { (label) }+ (copyable_registration_url(&full_url, "Copy URL"))+ p class="mt-1 whitespace-nowrap text-xs text-neutral-500" { "ID: " (&url.id) }+ @if let Some(invite_code) = url.invite_code.as_deref() {+ p class="mt-1 whitespace-nowrap text-xs text-neutral-500" { "Joins invite: " (invite_code) }+ }+ form method="post" action=(&rename_action)+ hx-post=(&rename_action)+ hx-target="#registration-url-list"+ hx-swap="outerHTML"+ hx-push-url="false"+ data-admin-allow-swap="true"+ class="mt-2 flex items-center gap-2" {+ (csrf_input(csrf_token))+ input type="hidden" name="registration_url_id" value=(&url.id);+ input type="text" name="registration_url_label" maxlength="120"+ value=(url.label.as_deref().unwrap_or(""))+ aria-label="New label" placeholder="New label"+ class="h-8 min-w-0 flex-1 rounded-lg border border-neutral-300 bg-white px-3 py-1.5 text-xs text-neutral-800";+ (compact_button("Rename", CompactButtonVariant::Neutral))+ }+ }+ td class="px-4 py-3 align-top text-neutral-700" {+ p class="whitespace-nowrap" { (created_at) }+ p class="whitespace-nowrap text-xs text-neutral-500" { "By: " (&url.created_by_user_id) }+ }+ td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {+ (expires_at)+ }+ td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {+ (uses)+ }+ td class="px-4 py-3 align-top whitespace-nowrap" {+ (badge(status.label(), status.variant()))+ }+ td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {+ (approval)+ }+ td class="px-4 py-3 align-top" {+ @if status != RegistrationUrlStatus::Revoked {+ form method="post" action=(&revoke_action)+ hx-post=(&revoke_action)+ hx-target="#registration-url-list"+ hx-swap="outerHTML"+ hx-push-url="false"+ data-admin-allow-swap="true" {+ (csrf_input(csrf_token))+ input type="hidden" name="registration_url_id" value=(&url.id);+ (compact_button("Revoke", CompactButtonVariant::Danger))+ }+ } @else {+ form method="post" action=(&remove_action)+ hx-post=(&remove_action)+ hx-target="#registration-url-list"+ hx-swap="outerHTML"+ hx-push-url="false"+ hx-confirm="Remove this registration URL from the list?"+ data-admin-allow-swap="true" {+ (csrf_input(csrf_token))+ input type="hidden" name="registration_url_id" value=(&url.id);+ (compact_button("Remove", CompactButtonVariant::Danger))+ }+ }+ }+ }+ }+}++pub(super) fn admin_issued_registration_url(config: &AdminConfig, code: &str) -> String {+ format!(+ "{}/register?registration_url={}",+ config.web_app_endpoint.trim_end_matches('/'),+ urlencoding::encode(code)+ )+}++fn copyable_registration_url(value: &str, label: &str) -> Markup {+ html! {+ div class="mt-2 flex items-center gap-2" {+ input type="url" readonly value=(value)+ aria-label="Registration URL"+ class="h-8 min-w-0 flex-1 rounded-lg border border-neutral-300 bg-neutral-50 px-3 py-1.5 text-xs text-neutral-800";+ (compact_copy_button(value, label))+ }+ }+}++pub(super) fn compact_copy_button(value: &str, label: &str) -> Markup {+ html! {+ button type="button"+ class="inline-flex h-8 shrink-0 items-center justify-center rounded-lg border border-neutral-300 bg-neutral-50 px-3 text-xs font-medium text-neutral-700 transition-all hover:border-neutral-400 hover:text-neutral-900 focus:outline-none focus:ring-2 focus:ring-brand-primary/20"+ data-copy-value=(value)+ onclick="window.__adminCopyToClipboard && window.__adminCopyToClipboard(this.dataset.copyValue, this, 'Copied')" {+ (label)+ }+ }+}++pub(super) enum CompactButtonVariant {+ Neutral,+ Danger,+}++pub(super) fn compact_button(label: &str, variant: CompactButtonVariant) -> Markup {+ let variant_class = match variant {+ CompactButtonVariant::Danger => {+ "bg-red-600 text-white hover:bg-red-700 focus:ring-red-500/30"+ }+ CompactButtonVariant::Neutral => {+ "bg-neutral-900 text-white hover:bg-neutral-800 focus:ring-brand-primary/20"+ }+ };+ html! {+ button type="submit"+ class={"inline-flex h-8 shrink-0 items-center justify-center rounded-lg px-3 text-xs font-medium transition-all focus:outline-none focus:ring-2 " (variant_class)} {+ (label)+ }+ }+}++#[derive(Clone, Copy, Debug, Eq, PartialEq)]+enum RegistrationUrlStatus {+ Active,+ Revoked,+ Expired,+ Exhausted,+}++impl RegistrationUrlStatus {+ fn label(self) -> &'static str {+ match self {+ Self::Active => "Active",+ Self::Revoked => "Revoked",+ Self::Expired => "Expired",+ Self::Exhausted => "Exhausted",+ }+ }++ fn variant(self) -> BadgeVariant {+ match self {+ Self::Active => BadgeVariant::Success,+ Self::Revoked => BadgeVariant::Danger,+ Self::Expired | Self::Exhausted => BadgeVariant::Warning,+ }+ }+}++fn registration_url_status(url: &RegistrationUrlResponse) -> RegistrationUrlStatus {+ if url.revoked_at.is_some() {+ return RegistrationUrlStatus::Revoked;+ }+ if url.expires_at.as_deref().is_some_and(timestamp_is_past) {+ return RegistrationUrlStatus::Expired;+ }+ if url+ .max_uses+ .is_some_and(|max_uses| url.use_count >= max_uses)+ {+ return RegistrationUrlStatus::Exhausted;+ }+ RegistrationUrlStatus::Active+}++fn timestamp_is_past(iso: &str) -> bool {+ time::OffsetDateTime::parse(iso, &time::format_description::well_known::Rfc3339)+ .or_else(|_| {+ time::OffsetDateTime::parse(+ iso,+ &time::format_description::well_known::Iso8601::DEFAULT,+ )+ })+ .map(|timestamp| timestamp < time::OffsetDateTime::now_utc())+ .unwrap_or(false)+}++fn registration_url_uses_text(url: &RegistrationUrlResponse) -> String {+ match url.max_uses {+ Some(max_uses) => format!("{} / {}", url.use_count, max_uses),+ None => format!("{} / unlimited", url.use_count),+ }+}diff --git a/fluxer_admin/src/templates/pages/pending_registrations.rs b/fluxer_admin/src/templates/pages/pending_registrations.rsindex 8c0e9df59..df96bdda4 100644--- a/fluxer_admin/src/templates/pages/pending_registrations.rs+++ b/fluxer_admin/src/templates/pages/pending_registrations.rs@@ -1,7 +1,7 @@// SPDX-License-Identifier: AGPL-3.0-or-lateruse crate::{- api::types::PendingRegistrationResponse,+ api::types::{PendingRegistrationResponse, RegistrationUrlResponse},config::AdminConfig,middleware::auth::AuthContext,templates::{@@ -16,13 +16,16 @@ use crate::{};use maud::{Markup, html};-use super::instance_config::{admin_issued_registration_url, compact_button, compact_copy_button};+use super::instance_registration::{+ CompactButtonVariant, admin_issued_registration_url, compact_button, compact_copy_button,+};pub fn pending_registrations_page(config: &AdminConfig,auth: &AuthContext,csrf_token: &str,pending_registrations: Option<&[PendingRegistrationResponse]>,+ registration_urls: &[RegistrationUrlResponse],) -> Markup {let content = html! {(page_header(@@ -31,7 +34,7 @@ pub fn pending_registrations_page())@match pending_registrations {Some(pending_registrations) => {- (pending_registration_list(config, csrf_token, pending_registrations))+ (pending_registration_list(config, csrf_token, pending_registrations, registration_urls))}None => (error_alert("Failed to load pending registrations.")),}@@ -50,6 +53,7 @@ pub fn pending_registration_list(config: &AdminConfig,csrf_token: &str,pending_registrations: &[PendingRegistrationResponse],+ registration_urls: &[RegistrationUrlResponse],) -> Markup {let base = &config.base_path;html! {@@ -70,7 +74,7 @@ pub fn pending_registration_list(}tbody class="divide-y divide-neutral-200 bg-white" {@for pending in pending_registrations {- (pending_registration_row(config, base, csrf_token, pending))+ (pending_registration_row(config, base, csrf_token, pending, registration_urls))}}}@@ -85,10 +89,10 @@ fn pending_registration_row(base: &str,csrf_token: &str,pending: &PendingRegistrationResponse,+ registration_urls: &[RegistrationUrlResponse],) -> Markup {let account_name = pending_registration_account_name(pending);let requested_at = format_admin_timestamp(&pending.requested_at);- let email = pending.email.as_deref().unwrap_or("None");let client_ip = pending.client_ip.as_deref().unwrap_or("None");let approve_action = format!("{base}/pending-registrations/approve");let reject_action = format!("{base}/pending-registrations/reject");@@ -99,7 +103,9 @@ fn pending_registration_row(@if let Some(global_name) = pending.global_name.as_deref() {p class="truncate text-xs text-neutral-500" title=(global_name) { (global_name) }}- p class="truncate text-xs text-neutral-500" title=(email) { (email) }+ @if let Some(email) = pending.email.as_deref() {+ p class="truncate text-xs text-neutral-500" title=(email) { (email) }+ }p class="whitespace-nowrap text-xs text-neutral-500" { "ID: " (&pending.user_id) }}td class="px-4 py-3 align-top text-neutral-700 whitespace-nowrap" {@@ -107,7 +113,9 @@ fn pending_registration_row(}td class="px-4 py-3 align-top text-neutral-700" {@if let Some(registration_url_id) = pending.registration_url_id.as_deref() {- p class="whitespace-nowrap text-xs text-neutral-500" { "ID: " (registration_url_id) }+ p class="whitespace-nowrap text-xs text-neutral-500" {+ (registration_url_name(registration_urls, registration_url_id))+ }div class="mt-1" {(compact_copy_button(&admin_issued_registration_url(config, registration_url_id), "Copy URL"))}@@ -120,8 +128,8 @@ fn pending_registration_row(}td class="px-4 py-3 align-top" {div class="flex flex-nowrap gap-2" {- (decision_form(&approve_action, csrf_token, &pending.user_id, "Approve", false))- (decision_form(&reject_action, csrf_token, &pending.user_id, "Reject", true))+ (decision_form(&approve_action, csrf_token, &pending.user_id, "Approve", CompactButtonVariant::Neutral))+ (decision_form(&reject_action, csrf_token, &pending.user_id, "Reject", CompactButtonVariant::Danger))}}}@@ -133,7 +141,7 @@ fn decision_form(csrf_token: &str,user_id: &str,label: &str,- danger: bool,+ variant: CompactButtonVariant,) -> Markup {html! {form method="post" action=(action)@@ -144,7 +152,7 @@ fn decision_form(data-admin-allow-swap="true" {(csrf_input(csrf_token))input type="hidden" name="user_id" value=(user_id);- (compact_button(label, danger))+ (compact_button(label, variant))}}}@@ -156,3 +164,11 @@ fn pending_registration_account_name(pending: &PendingRegistrationResponse) -> Sformat!("{}#{:04}", pending.username, pending.discriminator)}}++fn registration_url_name(registration_urls: &[RegistrationUrlResponse], id: &str) -> String {+ registration_urls+ .iter()+ .find(|url| url.id == id)+ .and_then(|url| url.label.clone())+ .unwrap_or_else(|| format!("ID: {id}"))+}