A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(admin): default reports to pending and show masked links (#3745)
Hampus34bdfa091676
diff --git a/fluxer_admin/src/routes/reports.rs b/fluxer_admin/src/routes/reports.rsindex 3743c59eb..69c598b23 100644--- a/fluxer_admin/src/routes/reports.rs+++ b/fluxer_admin/src/routes/reports.rs@@ -142,7 +142,8 @@ async fn reports_list(let search_query = query.q.as_deref().and_then(clean_string);let (sort_by, sort_order) = decode_sort(query.sort.as_deref());let client = AdminApiClient::new(state.http_client(), config, &auth.0.session);- let status = query.status.as_deref().and_then(|s| s.parse::<i32>().ok());+ let status_filter = status_filter(&query);+ let status = status_filter.parse::<i32>().ok();let report_type = query.report_type.as_deref()@@ -178,7 +179,7 @@ async fn reports_list(reports.as_ref(),&templates::pages::reports_list::ReportFilters {query: search_query.as_deref(),- status: query.status.as_deref(),+ status: Some(status_filter),report_type: query.report_type.as_deref(),category: query.category.as_deref(),reason: reason.as_deref(),@@ -198,6 +199,40 @@ async fn reports_list(Html(markup.into_string()).into_response()}+fn status_filter(query: &ReportsQuery) -> &str {+ match query.status.as_deref().map(str::trim) {+ Some("") | Some(STATUS_ALL) => STATUS_ALL,+ Some(status) => status,+ None if has_entity_filter(query) => STATUS_ALL,+ None => STATUS_PENDING,+ }+}++fn has_entity_filter(query: &ReportsQuery) -> bool {+ [+ &query.q,+ &query.report_type,+ &query.category,+ &query.reason,+ &query.reporter_id,+ &query.reported_user_id,+ &query.reported_webhook_id,+ &query.reported_guild_id,+ &query.reported_channel_id,+ &query.guild_context_id,+ &query.resolved_by_admin_id,+ ]+ .into_iter()+ .any(|value| {+ value+ .as_deref()+ .is_some_and(|value| !value.trim().is_empty())+ })+}++const STATUS_ALL: &str = "all";+const STATUS_PENDING: &str = "0";+fn reports_error_page(config: &AdminConfig, auth: &AuthContext, message: &str) -> Response {let markup = templates::layout::admin_layout(config,@@ -364,8 +399,7 @@ async fn report_resolve(let duplicate_of = form.duplicate_of.as_deref()- .map(str::trim)- .filter(|value| is_snowflake(value))+ .and_then(duplicate_report_id).map(str::to_owned);let missing = match resolution {UpdateReportRequestResolution::Actioned if outcome.is_none() => Some(OUTCOME_REQUIRED),@@ -395,7 +429,19 @@ async fn report_resolve(Ok(_) => FlashData::success(format!("Report resolved: {label}")),Err(error) => {tracing::warn!(%error, report_id, "admin API request failed: resolve report");- FlashData::error("Failed to resolve report")+ match (&error, duplicate_of.as_deref()) {+ (+ ApiError::Http {+ status: 404,+ message,+ ..+ },+ Some(target),+ ) if message.contains("UNKNOWN_REPORT") => FlashData::error(format!(+ "No report has the ID {target}. Copy the Report ID from that report's page, not a message, user or decision ID."+ )),+ _ => FlashData::error(error.refusal_message("Failed to resolve report")),+ }}};flash::redirect_with_flash(&back, flash, config.secure_cookies())@@ -430,9 +476,18 @@ async fn report_note(flash::redirect_with_flash(&back, flash, config.secure_cookies())}+fn duplicate_report_id(value: &str) -> Option<&str> {+ let value = value.trim();+ let candidate = match value.split_once("/reports/") {+ Some((_, rest)) => rest.split(['/', '?', '#']).next().unwrap_or(""),+ None => value.trim_start_matches('#'),+ };+ is_snowflake(candidate).then_some(candidate)+}+const RESOLUTION_REQUIRED: &str = "Choose a resolution";const OUTCOME_REQUIRED: &str = "Choose what happened to the reported content or account";-const DUPLICATE_OF_REQUIRED: &str = "Enter the ID of the report this one repeats";+const DUPLICATE_OF_REQUIRED: &str = "Enter the ID or link of the report this one repeats";async fn report_legal_hold(State(state): State<AppState>,diff --git a/fluxer_admin/src/templates/components/message_list.rs b/fluxer_admin/src/templates/components/message_list.rsindex a1c0386e9..c8f6ac9f7 100644--- a/fluxer_admin/src/templates/components/message_list.rs+++ b/fluxer_admin/src/templates/components/message_list.rs@@ -91,6 +91,67 @@ fn safe_link(url: &str) -> Option<&str> {(url.starts_with("https://") || url.starts_with("http://")).then_some(url)}+enum ContentPart<'a> {+ Text(&'a str),+ MaskedLink { label: &'a str, url: &'a str },+}++fn masked_link_at(text: &str) -> Option<(&str, &str, usize)> {+ let rest = text.strip_prefix('[')?;+ let label_end = rest.find(']')?;+ let label = &rest[..label_end];+ if label.is_empty() || label.contains('\n') || label.contains('[') {+ return None;+ }+ let after = rest[label_end + 1..].strip_prefix('(')?;+ let url_end = after.find(')')?;+ let url = &after[..url_end];+ if safe_link(url).is_none() || url.chars().any(char::is_whitespace) {+ return None;+ }+ Some((label, url, 1 + label_end + 2 + url_end + 1))+}++fn content_parts(content: &str) -> Vec<ContentPart<'_>> {+ let mut parts = Vec::new();+ let mut text_start = 0;+ let mut index = 0;+ while let Some(offset) = content[index..].find('[') {+ let start = index + offset;+ match masked_link_at(&content[start..]) {+ Some((label, url, len)) => {+ if start > text_start {+ parts.push(ContentPart::Text(&content[text_start..start]));+ }+ parts.push(ContentPart::MaskedLink { label, url });+ index = start + len;+ text_start = index;+ }+ None => index = start + 1,+ }+ }+ if text_start < content.len() {+ parts.push(ContentPart::Text(&content[text_start..]));+ }+ parts+}++fn render_content(content: &str) -> Markup {+ html! {+ @for part in content_parts(content) {+ @match part {+ ContentPart::Text(text) => (text),+ ContentPart::MaskedLink { label, url } => {+ a href=(url) target="_blank" rel="noopener noreferrer" title=(url)+ class="text-blue-600 hover:underline" data-masked-link="" { (label) }+ " "+ span class="text-neutral-500 text-xs break-all" data-masked-link-url="" { "(" (url) ")" }+ },+ }+ }+ }+}+fn render_embed_image(url: &str, alt: &str, class: &str) -> Markup {match safe_link(url) {Some(href) => html! {@@ -286,7 +347,7 @@ fn message_row(div class="min-w-0" style="grid-column:4;" {@if !msg.content.is_empty() {div class="whitespace-pre-wrap break-words text-neutral-800 \- text-sm leading-snug" { (msg.content) }+ text-sm leading-snug" { (render_content(&msg.content)) }}@if !msg.attachments.is_empty() {(render_image_attachments(msg, include_delete))@@ -368,7 +429,7 @@ fn message_row(}@if !msg.content.is_empty() {div class="mt-0.5 whitespace-pre-wrap break-words text-neutral-800 \- text-sm leading-snug" { (msg.content) }+ text-sm leading-snug" { (render_content(&msg.content)) }}@if !msg.attachments.is_empty() {(render_image_attachments(msg, include_delete))diff --git a/fluxer_admin/src/templates/pages/report_detail.rs b/fluxer_admin/src/templates/pages/report_detail.rsindex f24663d59..0e0e92ff6 100644--- a/fluxer_admin/src/templates/pages/report_detail.rs+++ b/fluxer_admin/src/templates/pages/report_detail.rs@@ -607,10 +607,10 @@ fn resolve_report_form(base: &str, report_id: &str, csrf_token: &str) -> Markup}fieldset class="flex flex-col gap-3" data-show-for-resolution="duplicate" hidden disabled {label for="duplicate_of" class=(FORM_LABEL_CLASS) { "Duplicate of" }- input type="text" id="duplicate_of" name="duplicate_of" required inputmode="numeric"- placeholder="Report ID" class={(FORM_CONTROL_CLASS) " h-8 px-3 py-1.5"};+ input type="text" id="duplicate_of" name="duplicate_of" required+ placeholder="Report ID or link" class={(FORM_CONTROL_CLASS) " h-8 px-3 py-1.5"};p class="text-neutral-500 text-xs" {- "The report this one repeats. The reporter is told its outcome, or nothing while it is still open."+ "The report this one repeats, open or resolved. Paste its Report ID or its link. The reporter is told its outcome, or nothing while it is still open."}}label for="public_comment" class=(FORM_LABEL_CLASS) {diff --git a/fluxer_admin/src/templates/pages/reports_list.rs b/fluxer_admin/src/templates/pages/reports_list.rsindex 659ac4350..1373305a6 100644--- a/fluxer_admin/src/templates/pages/reports_list.rs+++ b/fluxer_admin/src/templates/pages/reports_list.rs@@ -117,10 +117,10 @@ fn filters_card())div class=(select_grid_class) {(select_input("status", "Status", &[- ("", "All"),+ ("all", "All"),("0", "Pending"),("1", "Resolved"),- ], filters.status.unwrap_or("")))+ ], filters.status.unwrap_or("all")))(select_input("type", "Type", &[("", "All"),("0", "Message"),