Forum: every member may upload an own avatar and ask for a conversation
- Own avatars: no longer from the Kereső rank; before the first nickname save the settings page says the upload comes right after it (that is why even an admin did not see it). - Conversation requests: any member from the first day (a newcomers' limit may come back later in may_request). - The terms (8.1, 8.4) and the docs follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
//! Own avatars: a member from the Kereső rank may upload a picture instead of
|
||||
//! a starter avatar. It is cut to a square, made small (256 pixels), stripped
|
||||
//! Own avatars: any member may upload a picture instead of a starter avatar. It is cut to a square, made small (256 pixels), stripped
|
||||
//! of its metadata (EXIF: camera, place) and kept in the object storage; the
|
||||
//! forum serves it. A moderator can put the starter avatar back.
|
||||
|
||||
@@ -17,7 +16,6 @@ use image::metadata::Orientation;
|
||||
use image::{DynamicImage, ImageDecoder, ImageFormat, ImageReader, Limits};
|
||||
use serde_json::{Value, json};
|
||||
use sha2::{Digest, Sha256};
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::St;
|
||||
@@ -97,9 +95,6 @@ pub async fn forget(state: &crate::AppState, avatar: &str) {
|
||||
/// `PUT /v1/forum/me/avatar`: the picture's bytes as the body.
|
||||
pub async fn upload(State(state): St, viewer: Viewer, body: Bytes) -> ApiResult<Json<Value>> {
|
||||
let member = viewer.require_writer()?.clone();
|
||||
if member.rank(OffsetDateTime::now_utc()).is_newcomer() && !viewer.is_moderator() {
|
||||
return Err(ApiError::Forbidden("Saját képet a Kereső rangtól tölthetsz fel.".into()));
|
||||
}
|
||||
let Some(storage) = &state.storage else {
|
||||
return Err(ApiError::Forbidden("A képfeltöltés most nem érhető el.".into()));
|
||||
};
|
||||
|
||||
@@ -61,9 +61,9 @@ pub async fn me(State(state): St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
},
|
||||
"listener": m.listener,
|
||||
"supporter_badge": m.supporter_badge,
|
||||
// From the Kereső rank: volunteering as a listener, an own picture.
|
||||
// From the Kereső rank: volunteering as a companion. An own picture: anyone.
|
||||
"can_listen": viewer.is_moderator() || !rank.is_newcomer(),
|
||||
"can_upload_avatar": viewer.is_moderator() || !rank.is_newcomer(),
|
||||
"can_upload_avatar": true,
|
||||
})
|
||||
});
|
||||
let buyer = super::has_purchase(&state.db, user.id).await?;
|
||||
|
||||
@@ -82,10 +82,11 @@ fn pair(a: Uuid, b: Uuid) -> (Uuid, Uuid) {
|
||||
if a < b { (a, b) } else { (b, a) }
|
||||
}
|
||||
|
||||
/// Whether a member may start conversations: from the Kereső rank and after
|
||||
/// writing in public (moderators always).
|
||||
fn may_request(viewer: &Viewer, member: &Member) -> bool {
|
||||
viewer.is_moderator() || (!member.rank(OffsetDateTime::now_utc()).is_newcomer() && member.post_count > 0)
|
||||
/// Whether a member may start conversations: any member for now, from the
|
||||
/// first day (the user decided on 2026-11-26; a newcomers' limit, such as the
|
||||
/// Kereső rank, may come back later here).
|
||||
fn may_request(_viewer: &Viewer, _member: &Member) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The viewer's relation to another member, for the profile page.
|
||||
@@ -143,8 +144,7 @@ pub async fn request(
|
||||
let me = viewer.require_writer()?;
|
||||
if !may_request(&viewer, me) {
|
||||
return Err(ApiError::Forbidden(
|
||||
"Beszélgetést a Kereső rangtól kezdeményezhetsz, ha már írtál a fórumba. A neked küldött kéréseket addig is elfogadhatod."
|
||||
.into(),
|
||||
"Most nem kezdeményezhetsz beszélgetést. A neked küldött kéréseket elfogadhatod.".into(),
|
||||
));
|
||||
}
|
||||
let other: Uuid = sqlx::query_scalar("SELECT user_id FROM forum.members WHERE nickname_key = $1")
|
||||
|
||||
@@ -642,13 +642,7 @@ async fn private_messages_start_with_a_request(pool: PgPool) {
|
||||
async move { app.call("POST", "/v1/forum/conversations", Some(&user), body).await }
|
||||
};
|
||||
|
||||
// A newcomer may not start one; a seasoned member who wrote in public may.
|
||||
let (status, _) = request(&anna, "Holdfény", "Szia, olvastam a hozzászólásodat.").await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
let profile = app.get("/v1/forum/members/Holdfény", Some(&anna)).await;
|
||||
assert_eq!(profile["relation"]["can_request"], false);
|
||||
app.thread(&anna, "torzsasztal", "Sziasztok").await;
|
||||
app.season(&anna, 5, 10).await;
|
||||
// Any member may start one from the first day (a newcomers' limit may come later).
|
||||
assert_eq!(app.get("/v1/forum/members/Holdfény", Some(&anna)).await["relation"]["can_request"], true);
|
||||
assert_eq!(request(&anna, "Holdfény", "Nézd: www.pelda.hu").await.0, StatusCode::BAD_REQUEST);
|
||||
assert_eq!(request(&anna, "Csendesvíz", "Szia, én vagyok.").await.0, StatusCode::BAD_REQUEST);
|
||||
@@ -1403,3 +1397,14 @@ async fn youtube_links_get_a_preview(pool: PgPool) {
|
||||
assert_eq!(shown["posts"][1]["links"][0]["title"], "Telihold meditáció");
|
||||
assert!(shown["posts"][0]["links"].is_null());
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn any_member_may_upload_an_avatar(pool: PgPool) {
|
||||
let app = TestApp::new(pool);
|
||||
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
|
||||
// A newcomer (Vándor) is offered it too; without storage the upload says it is not available.
|
||||
assert_eq!(app.get("/v1/forum/me", Some(&anna)).await["member"]["can_upload_avatar"], true);
|
||||
let (status, body) = app.call("PUT", "/v1/forum/me/avatar", Some(&anna), Value::Null).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
assert!(body.to_string().contains("nem érhető el"), "{body}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user