Forum: asking about one's own chart, forecast or comparison

- "Kérdezek róla a fórumon" on the chart, yearly forecast and comparison
  pages: after a window that says what goes out, a share link made for the
  forum (never birth data, names or a title) and a new thread in "Égbolt és
  képletek" with it attached.
- The question shows a card (Sun, Moon, Ascendant with sign, degree and
  house, the summary's title, a link to the shared page) to logged-in
  members only; visitors and search engines see only that there is one.
  The author can take it off, and deleting the question ends the link.
- The shared page (/s/...) now shows comparisons (one wheel, the aspects,
  no names) and yearly forecasts (keys, timeline, transits, the detailed
  text; without the birthday's place); the backend shares forecasts.
- The privacy notice (HU, EN) covers attached charts and muted members.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 14:52:00 +00:00
co-authored by Claude Opus 5.5
parent 9ca3f478be
commit 863002c1e7
24 changed files with 871 additions and 32 deletions
+82 -11
View File
@@ -13,6 +13,12 @@
//! per user: a click proves little. A natal analysis is earned by bringing a
//! new user (`REFERRAL_REWARDS`): someone who signs up from a shared link and
//! makes their own chart, at most [`REFERRAL_LIMIT`] times.
//!
//! A share made for the forum (`for_forum`, a question about one's chart,
//! forecast or synastry) never shows birth data, and its public view leaves
//! out the chart names: they may be real names next to a nickname. A yearly
//! forecast can be shared too: its calculation and its detailed text, without
//! the place of the birthday.
use axum::Json;
use axum::extract::{Path, State};
@@ -27,6 +33,7 @@ use uuid::Uuid;
use super::analyses::{can_see, find_analysis};
use super::charts::{ChartRow, find_chart, owned_chart};
use super::forecasts::{ForecastRow, find_forecast, owned_forecast};
use super::synastries::{VisibleSynastry, load_synastry, visible_synastry};
use super::{Body, IdPath, St};
use crate::auth::{AuthUser, user_agent};
@@ -39,6 +46,7 @@ pub enum ShareKind {
Chart,
Synastry,
Analysis,
Forecast,
}
#[derive(Debug, sqlx::FromRow)]
@@ -50,16 +58,18 @@ struct ShareRow {
chart_id: Option<Uuid>,
synastry_id: Option<Uuid>,
analysis_id: Option<Uuid>,
forecast_id: Option<Uuid>,
title: Option<String>,
show_birth_data: bool,
for_forum: bool,
view_count: i64,
created_at: OffsetDateTime,
revoked_at: Option<OffsetDateTime>,
owner_ip_hash: Option<Vec<u8>>,
}
const SHARE_COLUMNS: &str = "id, owner_id, slug, kind, chart_id, synastry_id, analysis_id, title, show_birth_data, \
view_count, created_at, revoked_at, owner_ip_hash";
const SHARE_COLUMNS: &str = "id, owner_id, slug, kind, chart_id, synastry_id, analysis_id, forecast_id, title, \
show_birth_data, for_forum, view_count, created_at, revoked_at, owner_ip_hash";
use super::client_ip;
@@ -113,8 +123,10 @@ impl ShareRow {
"chart_id": self.chart_id,
"synastry_id": self.synastry_id,
"analysis_id": self.analysis_id,
"forecast_id": self.forecast_id,
"title": self.title,
"show_birth_data": self.show_birth_data,
"for_forum": self.for_forum,
"view_count": self.view_count,
"created_at": rfc3339(self.created_at),
"revoked_at": rfc3339_opt(self.revoked_at),
@@ -132,6 +144,9 @@ pub struct CreateShare {
/// Show birth date, time and place (only ever of the sharer's own charts).
#[serde(default)]
show_birth_data: bool,
/// For a forum post: no birth data, no names, no title.
#[serde(default)]
for_forum: bool,
}
pub async fn create(
@@ -140,14 +155,22 @@ pub async fn create(
headers: HeaderMap,
WithRejection(Json(req), _): Body<CreateShare>,
) -> ApiResult<(StatusCode, Json<Value>)> {
let (chart_id, synastry_id, analysis_id, kind) = match req.kind {
let (mut chart_id, mut synastry_id, mut analysis_id, mut forecast_id) = (None, None, None, None);
let kind = match req.kind {
ShareKind::Chart => {
owned_chart(&state.db, req.target_id, auth.id()).await?;
(Some(req.target_id), None, None, "chart")
chart_id = Some(req.target_id);
"chart"
}
ShareKind::Synastry => {
visible_synastry(&state.db, req.target_id, auth.id()).await?;
(None, Some(req.target_id), None, "synastry")
synastry_id = Some(req.target_id);
"synastry"
}
ShareKind::Forecast => {
owned_forecast(&state.db, req.target_id, auth.id()).await?;
forecast_id = Some(req.target_id);
"forecast"
}
ShareKind::Analysis => {
let analysis = find_analysis(&state.db, req.target_id).await?.ok_or(ApiError::NotFound("analysis"))?;
@@ -157,14 +180,18 @@ pub async fn create(
if analysis.status != "done" {
return Err(ApiError::conflict("analysis_not_ready", "Csak elkészült elemzést lehet megosztani."));
}
(None, None, Some(req.target_id), "analysis")
analysis_id = Some(req.target_id);
"analysis"
}
};
let title = req.title.map(|t| t.trim().chars().take(120).collect::<String>()).filter(|t| !t.is_empty());
// A forum share: never birth data, and no title of the sharer's own.
let (title, show_birth_data) = if req.for_forum { (None, false) } else { (title, req.show_birth_data) };
let open: Option<ShareRow> = sqlx::query_as(&format!(
"SELECT {SHARE_COLUMNS} FROM shares WHERE owner_id = $1 AND kind = $2 AND revoked_at IS NULL \
AND chart_id IS NOT DISTINCT FROM $3 AND synastry_id IS NOT DISTINCT FROM $4 \
AND analysis_id IS NOT DISTINCT FROM $5 AND title IS NOT DISTINCT FROM $6 AND show_birth_data = $7 \
AND forecast_id IS NOT DISTINCT FROM $8 AND for_forum = $9 \
ORDER BY created_at DESC LIMIT 1"
))
.bind(auth.id())
@@ -173,7 +200,9 @@ pub async fn create(
.bind(synastry_id)
.bind(analysis_id)
.bind(&title)
.bind(req.show_birth_data)
.bind(show_birth_data)
.bind(forecast_id)
.bind(req.for_forum)
.fetch_optional(&state.db)
.await?;
if let Some(row) = open {
@@ -182,8 +211,8 @@ pub async fn create(
let slug = new_slug();
let row: ShareRow = sqlx::query_as(&format!(
"INSERT INTO shares (id, owner_id, slug, kind, chart_id, synastry_id, analysis_id, title, show_birth_data, \
owner_ip_hash) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING {SHARE_COLUMNS}"
owner_ip_hash, forecast_id, for_forum) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING {SHARE_COLUMNS}"
))
.bind(Uuid::now_v7())
.bind(auth.id())
@@ -193,8 +222,10 @@ pub async fn create(
.bind(synastry_id)
.bind(analysis_id)
.bind(title)
.bind(req.show_birth_data)
.bind(show_birth_data)
.bind(client_ip(&headers).map(|ip| ip_hash(&slug, &ip)))
.bind(forecast_id)
.bind(req.for_forum)
.fetch_one(&state.db)
.await?;
Ok((StatusCode::CREATED, Json(row.view(&state.config.public_base_url))))
@@ -229,7 +260,27 @@ fn public_chart_block(chart: &ChartRow, share: &ShareRow) -> Value {
// Birth data only of the sharer's own chart, never of a partner's or of a
// person they added (that is someone else's data).
let show = share.show_birth_data && chart.owner_id == share.owner_id && chart.kind == "own";
json!({ "label": chart.label, "chart": public_chart(&chart.result, show) })
// A forum share leaves out the names (they may be real names next to a nickname).
let label = if share.for_forum { Value::Null } else { Value::from(chart.label.clone()) };
json!({ "label": label, "chart": public_chart(&chart.result, show) })
}
/// A yearly forecast without where it was reckoned: the solar return chart
/// without its place and time zone, and the year's calculation.
fn public_forecast_block(forecast: &ForecastRow) -> Value {
let sr = &forecast.result["solar_return"];
let solar_return = if sr.is_object() {
let mut chart = public_chart(sr, false);
if let Some(obj) = chart.as_object_mut() {
for key in ["local_time", "timezone", "utc_offset", "moment_utc", "location"] {
obj.remove(key);
}
}
chart
} else {
Value::Null
};
json!({ "year": forecast.year, "forecast": forecast.result["forecast"], "solar_return": solar_return })
}
fn public_synastry_block(s: &VisibleSynastry, share: &ShareRow) -> Value {
@@ -269,6 +320,26 @@ async fn public_body(db: &PgPool, share: &ShareRow) -> Result<Value, ApiError> {
let s = load_synastry(db, synastry_id).await?.ok_or(ApiError::NotFound("share"))?;
body["synastry"] = public_synastry_block(&s, share);
}
} else if let Some(forecast_id) = share.forecast_id {
let forecast = find_forecast(db, forecast_id).await?.ok_or(ApiError::NotFound("share"))?;
body["forecast"] = public_forecast_block(&forecast);
// The detailed text of the year, if it was written.
let analysis: Option<(String, Option<Value>, Option<OffsetDateTime>)> = sqlx::query_as(
"SELECT language, content, completed_at FROM analyses \
WHERE forecast_id = $1 AND kind = 'forecast' AND status = 'done' ORDER BY completed_at DESC LIMIT 1",
)
.bind(forecast_id)
.fetch_optional(db)
.await?;
body["analysis"] = match analysis {
Some((language, content, completed_at)) => json!({
"kind": "forecast",
"language": language,
"content": content,
"completed_at": rfc3339_opt(completed_at),
}),
None => Value::Null,
};
}
Ok(body)
}
+28
View File
@@ -1011,6 +1011,21 @@ async fn public_shares(pool: PgPool) {
);
assert_eq!(app.get(&format!("/v1/public/shares/{slug}"), None).await.status, StatusCode::NOT_FOUND);
assert_eq!(app.get("/v1/public/shares/nincs-ilyen", None).await.status, StatusCode::NOT_FOUND);
// A share for the forum: its own link, never birth data, no names, no title.
let r = app
.post(
"/v1/shares",
Some(&anna),
json!({"kind": "chart", "target_id": chart_id, "for_forum": true, "show_birth_data": true, "title": "Én"}),
)
.await;
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
assert_eq!((r.body["for_forum"].as_bool(), r.body["show_birth_data"].as_bool()), (Some(true), Some(false)));
let r = app.get(&format!("/v1/public/shares/{}", r.body["slug"].as_str().unwrap()), None).await;
assert!(r.body["chart"]["label"].is_null(), "{}", r.body);
assert!(r.body["chart"]["chart"].get("birth").is_none());
assert!(r.body["title"].is_null());
}
#[sqlx::test(migrator = "db::MIGRATOR")]
@@ -1968,6 +1983,19 @@ async fn forecasts_are_free_their_analysis_uses_a_forecast_unit(pool: PgPool) {
assert_eq!(app.get(&uri, Some(&bob)).await.status, StatusCode::NOT_FOUND);
assert_eq!(app.get(&format!("/v1/forecasts/{id}"), Some(&anna)).await.body["year"], json!(year));
// A forecast can be shared (not by others), without where it was reckoned.
let r = app.post("/v1/shares", Some(&bob), json!({"kind": "forecast", "target_id": away.body["id"]})).await;
assert_eq!(r.status, StatusCode::NOT_FOUND);
let r = app
.post("/v1/shares", Some(&anna), json!({"kind": "forecast", "target_id": away.body["id"], "for_forum": true}))
.await;
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
let shared = app.get(&format!("/v1/public/shares/{}", r.body["slug"].as_str().unwrap()), None).await.body;
assert_eq!(shared["kind"], "forecast");
assert_eq!(shared["forecast"]["forecast"]["start"], format!("{year}-03-15"));
assert!(!shared.to_string().contains("Tokió"), "the place stays private: {shared}");
assert!(shared["analysis"].is_null(), "no detailed text yet");
// the detailed text uses a forecast unit, not a natal one
let analyses = format!("/v1/forecasts/{id}/analyses");
grant_units(&app, &anna, "natal", 1).await;