use custom_title in syslog
This commit is contained in:
@@ -127,11 +127,10 @@ pub async fn add_comment(
|
||||
NewComment {
|
||||
content: ci.text.to_string(),
|
||||
author_hash: user.namehash.to_string(),
|
||||
author_title: if use_title {
|
||||
user.custom_title
|
||||
} else {
|
||||
"".to_owned()
|
||||
},
|
||||
author_title: user
|
||||
.custom_title
|
||||
.and_then(|title| use_title.then_some(title))
|
||||
.unwrap_or_default(),
|
||||
is_tmp: user.id.is_none(),
|
||||
post_id: pid,
|
||||
},
|
||||
|
||||
@@ -65,8 +65,8 @@ pub struct CurrentUser {
|
||||
namehash: String,
|
||||
is_admin: bool,
|
||||
is_candidate: bool,
|
||||
custom_title: String,
|
||||
title_secret: String,
|
||||
custom_title: Option<String>,
|
||||
title_secret: Option<String>,
|
||||
pub auto_block_rank: u8,
|
||||
}
|
||||
|
||||
@@ -75,8 +75,7 @@ impl CurrentUser {
|
||||
let (custom_title, title_secret) = CustomTitle::get(rconn, &namehash)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.unwrap_or_default();
|
||||
.unwrap_or((None, None));
|
||||
Self {
|
||||
id: None,
|
||||
is_admin: false,
|
||||
|
||||
@@ -64,7 +64,7 @@ pub async fn delete(di: Form<DeleteInput>, user: CurrentUser, db: Db, rconn: Rds
|
||||
|
||||
if user.is_admin && !user.namehash.eq(&author_hash) {
|
||||
Systemlog {
|
||||
user_hash: user.namehash.clone(),
|
||||
user_hash: user.custom_title.clone().unwrap_or(look!(user.namehash)),
|
||||
action_type: LogType::AdminDelete,
|
||||
target: format!("#{}, {}={}", p.id, di.id_type, di.id),
|
||||
detail: di.note.clone(),
|
||||
@@ -75,7 +75,7 @@ pub async fn delete(di: Form<DeleteInput>, user: CurrentUser, db: Db, rconn: Rds
|
||||
|
||||
if di.note.starts_with("!ban ") {
|
||||
Systemlog {
|
||||
user_hash: user.namehash.clone(),
|
||||
user_hash: user.custom_title.unwrap_or(look!(user.namehash)),
|
||||
action_type: LogType::Ban,
|
||||
target: look!(author_hash),
|
||||
detail: di.note.clone(),
|
||||
@@ -120,7 +120,7 @@ pub async fn report(ri: Form<ReportInput>, user: CurrentUser, db: Db, rconn: Rds
|
||||
}
|
||||
|
||||
Systemlog {
|
||||
user_hash: user.namehash.to_string(),
|
||||
user_hash: user.custom_title.unwrap_or(look!(user.namehash)),
|
||||
action_type: LogType::Report,
|
||||
target: format!("#{}", ri.pid),
|
||||
detail: ri.reason.clone(),
|
||||
@@ -135,7 +135,7 @@ pub async fn report(ri: Form<ReportInput>, user: CurrentUser, db: Db, rconn: Rds
|
||||
NewPost {
|
||||
content: format!("[系统自动代发]\n我举报了 #{}\n理由: {}", &p.id, &ri.reason),
|
||||
cw: "举报".to_string(),
|
||||
author_hash: user.namehash.to_string(),
|
||||
author_hash: user.namehash.clone(),
|
||||
author_title: String::default(),
|
||||
is_tmp: false,
|
||||
n_attentions: 1,
|
||||
|
||||
@@ -200,11 +200,10 @@ pub async fn publish_post(
|
||||
content: poi.text.to_string(),
|
||||
cw: poi.cw.to_string(),
|
||||
author_hash: user.namehash.to_string(),
|
||||
author_title: if use_title {
|
||||
user.custom_title
|
||||
} else {
|
||||
"".to_owned()
|
||||
},
|
||||
author_title: user
|
||||
.custom_title
|
||||
.and_then(|title| use_title.then_some(title))
|
||||
.unwrap_or_default(),
|
||||
is_tmp: user.id.is_none(),
|
||||
n_attentions: 1,
|
||||
allow_search: poi.allow_search.is_some(),
|
||||
|
||||
@@ -19,7 +19,7 @@ pub async fn get_systemlog(user: CurrentUser, rh: &State<RandomHasher>, rconn: R
|
||||
"data": logs.into_iter().map(|log|
|
||||
json!({
|
||||
"type": log.action_type,
|
||||
"user": look!(log.user_hash),
|
||||
"user": log.user_hash,
|
||||
"timestamp": log.time.timestamp(),
|
||||
"detail": format!("{}\n{}", &log.target, &log.detail),
|
||||
})
|
||||
|
||||
@@ -250,7 +250,10 @@ impl CustomTitle {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get(rconn: &RdsConn, namehash: &str) -> RedisResult<Option<(String, String)>> {
|
||||
pub async fn get(
|
||||
rconn: &RdsConn,
|
||||
namehash: &str,
|
||||
) -> RedisResult<(Option<String>, Option<String>)> {
|
||||
let t: Option<String> = rconn.clone().hget(KEY_CUSTOM_TITLE, namehash).await?;
|
||||
Ok(if let Some(title) = t {
|
||||
let s: Option<String> = rconn.clone().get(KEY_TITLE_SECRET!(title)).await?;
|
||||
@@ -263,9 +266,9 @@ impl CustomTitle {
|
||||
} else {
|
||||
Self::gen_and_set_secret(rconn, &title).await?
|
||||
};
|
||||
Some((title, secret))
|
||||
(Some(title), Some(secret))
|
||||
} else {
|
||||
None
|
||||
(None, None)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -340,18 +343,20 @@ pub async fn get_announcement(rconn: &RdsConn) -> RedisResult<Option<String>> {
|
||||
rconn.clone().get(KEY_ANNOUNCEMENT).await
|
||||
}
|
||||
|
||||
pub async fn is_elected_candidate(rconn: &RdsConn, title: &str) -> RedisResult<bool> {
|
||||
if title.is_empty() {
|
||||
return Ok(false);
|
||||
pub async fn is_elected_candidate(rconn: &RdsConn, title: &Option<String>) -> RedisResult<bool> {
|
||||
if let Some(t) = title {
|
||||
rconn.clone().sismember(KEY_CANDIDATE, t).await
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
rconn.clone().sismember(KEY_CANDIDATE, title).await
|
||||
}
|
||||
|
||||
pub async fn is_elected_admin(rconn: &RdsConn, title: &str) -> RedisResult<bool> {
|
||||
if title.is_empty() {
|
||||
return Ok(false);
|
||||
pub async fn is_elected_admin(rconn: &RdsConn, title: &Option<String>) -> RedisResult<bool> {
|
||||
if let Some(t) = title {
|
||||
rconn.clone().sismember(KEY_ADMIN, t).await
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
rconn.clone().sismember(KEY_ADMIN, title).await
|
||||
}
|
||||
|
||||
pub async fn get_admin_list(rconn: &RdsConn) -> RedisResult<Vec<String>> {
|
||||
|
||||
Reference in New Issue
Block a user