~vpzom/hitide

8c98e0d745412d488f9ae7d060c7248b55edf29c — Colin Reeder 6 months ago 2d73518
Show delete link for local content for site admins
4 files changed, 14 insertions(+), 2 deletions(-)

M src/components/mod.rs
M src/main.rs
M src/resp_types.rs
M src/routes/posts.rs
M src/components/mod.rs => src/components/mod.rs +1 -1
@@ 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>
                            })

M src/main.rs => src/main.rs +9 -0
@@ 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>,

M src/resp_types.rs => src/resp_types.rs +3 -0
@@ 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,
}


M src/routes/posts.rs => src/routes/posts.rs +1 -1
@@ 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>