Added snippets to admin approval queue

This commit is contained in:
Asaf Gartner 2022-08-07 02:03:34 +03:00
parent 4c1daae5e1
commit 97ed892ce3
2 changed files with 58 additions and 30 deletions

View File

@ -1,5 +1,13 @@
{{ template "base.html" . }}
{{ define "extrahead" }}
<style>
.timeline-item {
background: rgba(147, 147, 147, 0.15);
}
</style>
{{ end }}
{{ define "content" }}
<div class="content-block">
{{ range .UnapprovedUsers }}
@ -75,28 +83,8 @@
</div>
</div>
{{ end }}
{{ range .Posts }}
<div class="post background-even pa3">
<div class="fl w-100 pv3 pa3-l">
<div class="w-100 flex-l flex-row-reverse-l">
<div class="inline-flex flex-row-reverse pl3-l pb3 items-center">
<div class="postid">
<a name="{{ .ID }}" href="{{ .Url }}">#{{ .ID }}</a>
</div>
</div>
<div class="w-100 pb3">
<div class="b" role="heading" aria-level="2">{{ .Title }}</div>
{{ timehtml (relativedate .PostDate) .PostDate }}
{{ if and $.User.IsStaff .IP }}
<span>[{{ .IP }}]</span>
{{ end }}
</div>
</div>
<div class="post-content overflow-x-auto">
{{ .Content }}
</div>
</div>
</div>
{{ range .Timeline }}
{{ template "timeline_item.html" . }}
{{ end }}
</div>
</div>

View File

@ -5,6 +5,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"html/template"
"net/http"
"sort"
"strconv"
@ -128,8 +129,8 @@ type unapprovedUserData struct {
User templates.User
Date time.Time
UserLinks []templates.Link
Posts []postWithTitle
ProjectsWithLinks []projectWithLinks
Timeline []templates.TimelineItem
}
func AdminApprovalQueue(c *RequestContext) ResponseData {
@ -138,6 +139,25 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree)
c.Perf.EndBlock()
potentialUsers, err := db.QueryScalar[int](c, c.Conn,
`
SELECT id
FROM hmn_user
WHERE hmn_user.status = $1
`,
models.UserStatusConfirmed,
)
if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch unapproved users"))
}
snippets, err := hmndata.FetchSnippets(c, c.Conn, c.CurrentUser, hmndata.SnippetQuery{
OwnerIDs: potentialUsers,
})
if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch unapproved snippets"))
}
posts, err := fetchUnapprovedPosts(c)
if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch unapproved posts"))
@ -151,6 +171,28 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
unapprovedUsers := make([]*unapprovedUserData, 0)
userIDToDataIdx := make(map[int]int)
for _, s := range snippets {
var userData *unapprovedUserData
if idx, ok := userIDToDataIdx[s.Owner.ID]; ok {
userData = unapprovedUsers[idx]
} else {
userData = &unapprovedUserData{
User: templates.UserToTemplate(s.Owner, c.Theme),
UserLinks: make([]templates.Link, 0, 10),
}
unapprovedUsers = append(unapprovedUsers, userData)
userIDToDataIdx[s.Owner.ID] = len(unapprovedUsers) - 1
}
if s.Snippet.When.After(userData.Date) {
userData.Date = s.Snippet.When
}
timelineItem := SnippetToTimelineItem(&s.Snippet, s.Asset, s.DiscordMessage, s.Projects, s.Owner, c.Theme, false)
timelineItem.OwnerAvatarUrl = ""
timelineItem.SmallInfo = true
userData.Timeline = append(userData.Timeline, timelineItem)
}
for _, p := range posts {
var userData *unapprovedUserData
if idx, ok := userIDToDataIdx[p.Author.ID]; ok {
@ -167,13 +209,11 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
if p.Post.PostDate.After(userData.Date) {
userData.Date = p.Post.PostDate
}
post := templates.PostToTemplate(&p.Post, &p.Author, c.Theme)
post.AddContentVersion(p.CurrentVersion, &p.Author) // NOTE(asaf): Don't care about editors here
post.Url = UrlForGenericPost(hmndata.UrlContextForProject(&p.Project), &p.Thread, &p.Post, lineageBuilder)
userData.Posts = append(userData.Posts, postWithTitle{
Post: post,
Title: p.Thread.Title,
})
timelineItem := PostToTimelineItem(hmndata.UrlContextForProject(&p.Project), lineageBuilder, &p.Post, &p.Thread, &p.Author, c.Theme)
timelineItem.OwnerAvatarUrl = ""
timelineItem.SmallInfo = true
timelineItem.Description = template.HTML(p.CurrentVersion.TextParsed)
userData.Timeline = append(userData.Timeline, timelineItem)
}
for _, p := range projects {