summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Reeder <vpzomtrrfrt@gmail.com>2020-10-23 20:40:53 -0600
committerColin Reeder <vpzomtrrfrt@gmail.com>2020-10-23 20:40:53 -0600
commit8c98e0d745412d488f9ae7d060c7248b55edf29c (patch)
treec9cb69f452f4ae1cf75e2216807b224c9288dd4e
parent2d73518bc8b89b1e5f2cd638a9a3e2fd13785f92 (diff)
Show delete link for local content for site admins
-rw-r--r--src/components/mod.rs2
-rw-r--r--src/main.rs9
-rw-r--r--src/resp_types.rs3
-rw-r--r--src/routes/posts.rs2
4 files changed, 14 insertions, 2 deletions
diff --git a/src/components/mod.rs b/src/components/mod.rs
index f045023..f5bc16f 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -77,7 +77,7 @@ pub fn Comment<'a>(
}
}
{
- if author_is_me(&comment.author, &base_data.login) {
+ if author_is_me(&comment.author, &base_data.login) || (comment.local && base_data.is_site_admin()) {
Some(render::rsx! {
<a href={format!("/comments/{}/delete", comment.as_ref().id)}>{lang.tr("delete", None)}</a>
})
diff --git a/src/main.rs b/src/main.rs
index 034990b..fae1aea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -73,6 +73,15 @@ pub struct PageBaseData {
pub login: Option<RespLoginInfo>,
}
+impl PageBaseData {
+ pub fn is_site_admin(&self) -> bool {
+ match &self.login {
+ None => false,
+ Some(login) => login.user.is_site_admin,
+ }
+ }
+}
+
pub fn simple_response(
code: hyper::StatusCode,
text: impl Into<hyper::Body>,
diff --git a/src/resp_types.rs b/src/resp_types.rs
index d10dfc7..63bfcc2 100644
--- a/src/resp_types.rs
+++ b/src/resp_types.rs
@@ -82,6 +82,7 @@ pub struct RespPostCommentInfo<'a> {
#[serde(borrow)]
pub author: Option<RespMinimalAuthorInfo<'a>>,
pub created: Cow<'a, str>,
+ pub local: bool,
pub your_vote: Option<Empty>,
#[serde(borrow)]
pub replies: Option<Vec<RespPostCommentInfo<'a>>>,
@@ -119,6 +120,7 @@ pub struct RespPostInfo<'a> {
pub content_html: Option<Cow<'a, str>>,
pub approved: bool,
pub score: i64,
+ pub local: bool,
#[serde(borrow)]
pub replies: Vec<RespPostCommentInfo<'a>>,
pub your_vote: Option<Empty>,
@@ -156,6 +158,7 @@ impl<'a> AsRef<RespMinimalAuthorInfo<'a>> for RespUserInfo<'a> {
#[derive(Deserialize, Debug)]
pub struct RespLoginInfoUser {
pub id: i64,
+ pub is_site_admin: bool,
pub has_unread_notifications: bool,
}
diff --git a/src/routes/posts.rs b/src/routes/posts.rs
index 356a7be..7ad0385 100644
--- a/src/routes/posts.rs
+++ b/src/routes/posts.rs
@@ -163,7 +163,7 @@ async fn page_post_inner(
}
<Content src={&post} />
{
- if author_is_me(&post.as_ref().author, &base_data.login) {
+ if author_is_me(&post.as_ref().author, &base_data.login) || (post.local && base_data.is_site_admin()) {
Some(render::rsx! {
<p>
<a href={format!("/posts/{}/delete", post_id)}>{lang.tr("delete", None)}</a>