From 72fd48d11e49fcb9d8bc14fb6484d5bf1dc6952c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sn=C3=ADda=C5=88ov=C3=BD=20Mistr?= Date: Sat, 20 Jan 2024 14:35:20 +0100 Subject: [PATCH] =?UTF-8?q?Uk=C5=AF=C3=ADze=C4=8Dtext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/markup.rs | 12 ++++++++++-- src/perms.rs | 5 +++++ src/web/actions/create_post.rs | 1 + src/web/actions/edit_posts.rs | 1 + src/web/actions/staff_post_actions.rs | 8 ++++---- src/web/staff/actions/create_news.rs | 2 +- src/web/staff/actions/edit_news.rs | 2 +- src/web/staff/actions/update_permissions.rs | 5 +++++ static/style.css | 5 +++++ static/themes/yotsuba-b.css | 1 + static/themes/yotsuba.css | 1 + templates/staff/permissions.html | 9 +++++++++ 12 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/markup.rs b/src/markup.rs index 7b74d09..ba19d07 100644 --- a/src/markup.rs +++ b/src/markup.rs @@ -24,6 +24,7 @@ lazy_static! { pub static ref SPOILER_REGEX: Regex = Regex::new(r"\|\|([\s\S]+?)\|\|").unwrap(); pub static ref URL_REGEX: Regex = Regex::new(r"https?\://[^\s<>\[\]{}|\\^]+").unwrap(); + pub static ref JANNYTEXT_REGEX: Regex = Regex::new(r"##(.+?)##").unwrap(); } pub fn parse_name( @@ -106,6 +107,7 @@ fn capcode_fallback(owner: bool) -> String { pub async fn markup( ctx: &Ctx, + perms: &PermissionWrapper, board: Option, op: Option, text: &str, @@ -119,8 +121,8 @@ pub async fn markup( let id_raw = &captures[1]; let Ok(id) = id_raw.parse() else { - return format!(">>{id_raw}"); - }; + return format!(">>{id_raw}"); + }; let post = quoted_posts.get(&id); @@ -165,6 +167,12 @@ pub async fn markup( format!("{url}") }); + let text = if perms.owner() || perms.jannytext() { + JANNYTEXT_REGEX.replace_all(&text, "$1") + } else { + text + }; + Ok(text.to_string()) } diff --git a/src/perms.rs b/src/perms.rs index b6af074..745c1c1 100755 --- a/src/perms.rs +++ b/src/perms.rs @@ -14,6 +14,7 @@ pub enum Permissions { BoardBanners, BoardConfig, News, + Jannytext, BypassBans, BypassBoardLock, BypassThreadLock, @@ -78,6 +79,10 @@ impl PermissionWrapper { self.0.contains(Permissions::News) } + pub fn jannytext(&self) -> bool { + self.0.contains(Permissions::Jannytext) + } + pub fn bypass_bans(&self) -> bool { self.0.contains(Permissions::BypassBans) } diff --git a/src/web/actions/create_post.rs b/src/web/actions/create_post.rs index b7ee830..8e8dfc8 100644 --- a/src/web/actions/create_post.rs +++ b/src/web/actions/create_post.rs @@ -174,6 +174,7 @@ pub async fn create_post( let content = markup( &ctx, + &perms, Some(board.id.clone()), thread.as_ref().map(|t| t.id), &content_nomarkup, diff --git a/src/web/actions/edit_posts.rs b/src/web/actions/edit_posts.rs index cb2f836..0c6c76f 100644 --- a/src/web/actions/edit_posts.rs +++ b/src/web/actions/edit_posts.rs @@ -40,6 +40,7 @@ pub async fn edit_posts( let content_nomarkup = content_nomarkup.trim(); let content = markup( &ctx, + &tcx.perms, Some(post.board.clone()), post.thread, content_nomarkup, diff --git a/src/web/actions/staff_post_actions.rs b/src/web/actions/staff_post_actions.rs index 5593192..d0011b0 100644 --- a/src/web/actions/staff_post_actions.rs +++ b/src/web/actions/staff_post_actions.rs @@ -17,7 +17,7 @@ use crate::{ }; #[derive(Deserialize)] -pub struct JannyPostActionsForm { +pub struct StaffPostActionsForm { #[serde(default)] pub posts: Vec, #[serde(rename = "staff_remove_posts")] @@ -40,7 +40,7 @@ pub struct JannyPostActionsForm { pub async fn staff_post_actions( ctx: Data, req: HttpRequest, - QsForm(form): QsForm, + QsForm(form): QsForm, ) -> Result { let tcx = TemplateCtx::new(&ctx, &req).await?; let account = account_from_auth(&ctx, &req).await?; @@ -156,12 +156,12 @@ pub async fn staff_post_actions( Ban::create(&ctx, account, board, ip_range, reason, appealable, expires).await?; let content_nomarkup = format!( - "{}\n\n==(UŽIVATEL BYL ZA TENTO PŘÍSPĚVEK ZABANOVÁN)==", + "{}\n\n##(UŽIVATEL BYL ZA TENTO PŘÍSPĚVEK ZABANOVÁN)##", post.content_nomarkup ); let content = format!( - "{}\n\n(UŽIVATEL BYL ZA TENTO PŘÍSPĚVEK ZABANOVÁN)", + "{}\n\n(UŽIVATEL BYL ZA TENTO PŘÍSPĚVEK ZABANOVÁN)", post.content ); diff --git a/src/web/staff/actions/create_news.rs b/src/web/staff/actions/create_news.rs index 2fba6db..7df667f 100644 --- a/src/web/staff/actions/create_news.rs +++ b/src/web/staff/actions/create_news.rs @@ -36,7 +36,7 @@ pub async fn create_news( } let content_nomarkup = content; - let content = markup(&ctx, None, None, &content_nomarkup).await?; + let content = markup(&ctx, &account.perms(), None, None, &content_nomarkup).await?; NewsPost::create(&ctx, title, content, content_nomarkup, account.username).await?; diff --git a/src/web/staff/actions/edit_news.rs b/src/web/staff/actions/edit_news.rs index 2347da7..fec8575 100644 --- a/src/web/staff/actions/edit_news.rs +++ b/src/web/staff/actions/edit_news.rs @@ -52,7 +52,7 @@ pub async fn edit_news( } let content_nomarkup = content_nomarkup.trim(); - let content = markup(&ctx, None, None, content_nomarkup).await?; + let content = markup(&ctx, &tcx.perms, None, None, content_nomarkup).await?; newspost .update(&ctx, content, content_nomarkup.into()) diff --git a/src/web/staff/actions/update_permissions.rs b/src/web/staff/actions/update_permissions.rs index 20e9fcc..d45acc2 100755 --- a/src/web/staff/actions/update_permissions.rs +++ b/src/web/staff/actions/update_permissions.rs @@ -19,6 +19,7 @@ pub struct UpdatePermissionsForm { bans: Option, banners: Option, news: Option, + jannytext: Option, board_config: Option, bypass_bans: Option, bypass_board_lock: Option, @@ -86,6 +87,10 @@ pub async fn update_permissions( permissions |= Permissions::News; } + if form.jannytext.is_some() { + permissions |= Permissions::Jannytext; + } + if form.bypass_bans.is_some() { permissions |= Permissions::BypassBans; } diff --git a/static/style.css b/static/style.css index 9a0d66d..70b1529 100755 --- a/static/style.css +++ b/static/style.css @@ -426,6 +426,11 @@ summary { background-color: transparent; } +.jannytext { + color: var(--jannytext-color); + font-weight: bold; +} + .icon { height: 1em; vertical-align: text-top; diff --git a/static/themes/yotsuba-b.css b/static/themes/yotsuba-b.css index ee871a5..6d85a7a 100644 --- a/static/themes/yotsuba-b.css +++ b/static/themes/yotsuba-b.css @@ -36,4 +36,5 @@ --bluetext-color: #0000ff; --uh-oh-color: #ffffff; --uh-oh-text: #0038b8; + --jannytext-color: #ff0000; } diff --git a/static/themes/yotsuba.css b/static/themes/yotsuba.css index 227d558..180099e 100644 --- a/static/themes/yotsuba.css +++ b/static/themes/yotsuba.css @@ -36,4 +36,5 @@ --bluetext-color: #0000ff; --uh-oh-color: #ffffff; --uh-oh-text: #0038b8; + --jannytext-color: #ff0000; } diff --git a/templates/staff/permissions.html b/templates/staff/permissions.html index 8c54cd5..7823d5f 100755 --- a/templates/staff/permissions.html +++ b/templates/staff/permissions.html @@ -106,6 +106,15 @@ + + Uklízečtext (pravý redtext) + +
+ +
+ + + Obejít ban