Added snippets to admin approval queue
This commit is contained in:
parent
4c1daae5e1
commit
97ed892ce3
|
@ -1,5 +1,13 @@
|
||||||
{{ template "base.html" . }}
|
{{ template "base.html" . }}
|
||||||
|
|
||||||
|
{{ define "extrahead" }}
|
||||||
|
<style>
|
||||||
|
.timeline-item {
|
||||||
|
background: rgba(147, 147, 147, 0.15);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<div class="content-block">
|
<div class="content-block">
|
||||||
{{ range .UnapprovedUsers }}
|
{{ range .UnapprovedUsers }}
|
||||||
|
@ -75,28 +83,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ range .Posts }}
|
{{ range .Timeline }}
|
||||||
<div class="post background-even pa3">
|
{{ template "timeline_item.html" . }}
|
||||||
<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>
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -128,8 +129,8 @@ type unapprovedUserData struct {
|
||||||
User templates.User
|
User templates.User
|
||||||
Date time.Time
|
Date time.Time
|
||||||
UserLinks []templates.Link
|
UserLinks []templates.Link
|
||||||
Posts []postWithTitle
|
|
||||||
ProjectsWithLinks []projectWithLinks
|
ProjectsWithLinks []projectWithLinks
|
||||||
|
Timeline []templates.TimelineItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminApprovalQueue(c *RequestContext) ResponseData {
|
func AdminApprovalQueue(c *RequestContext) ResponseData {
|
||||||
|
@ -138,6 +139,25 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
|
||||||
lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree)
|
lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree)
|
||||||
c.Perf.EndBlock()
|
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)
|
posts, err := fetchUnapprovedPosts(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.ErrorResponse(http.StatusInternalServerError, oops.New(err, "failed to fetch unapproved posts"))
|
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)
|
unapprovedUsers := make([]*unapprovedUserData, 0)
|
||||||
userIDToDataIdx := make(map[int]int)
|
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 {
|
for _, p := range posts {
|
||||||
var userData *unapprovedUserData
|
var userData *unapprovedUserData
|
||||||
if idx, ok := userIDToDataIdx[p.Author.ID]; ok {
|
if idx, ok := userIDToDataIdx[p.Author.ID]; ok {
|
||||||
|
@ -167,13 +209,11 @@ func AdminApprovalQueue(c *RequestContext) ResponseData {
|
||||||
if p.Post.PostDate.After(userData.Date) {
|
if p.Post.PostDate.After(userData.Date) {
|
||||||
userData.Date = p.Post.PostDate
|
userData.Date = p.Post.PostDate
|
||||||
}
|
}
|
||||||
post := templates.PostToTemplate(&p.Post, &p.Author, c.Theme)
|
timelineItem := PostToTimelineItem(hmndata.UrlContextForProject(&p.Project), lineageBuilder, &p.Post, &p.Thread, &p.Author, c.Theme)
|
||||||
post.AddContentVersion(p.CurrentVersion, &p.Author) // NOTE(asaf): Don't care about editors here
|
timelineItem.OwnerAvatarUrl = ""
|
||||||
post.Url = UrlForGenericPost(hmndata.UrlContextForProject(&p.Project), &p.Thread, &p.Post, lineageBuilder)
|
timelineItem.SmallInfo = true
|
||||||
userData.Posts = append(userData.Posts, postWithTitle{
|
timelineItem.Description = template.HTML(p.CurrentVersion.TextParsed)
|
||||||
Post: post,
|
userData.Timeline = append(userData.Timeline, timelineItem)
|
||||||
Title: p.Thread.Title,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range projects {
|
for _, p := range projects {
|
||||||
|
|
Loading…
Reference in New Issue