Added advanced thread and post editing for admins

This commit is contained in:
Eduard Urbach 2018-06-03 08:52:38 +09:00
parent 0fd8692100
commit b5f4585edd
6 changed files with 80 additions and 0 deletions

View File

@ -38,6 +38,10 @@ component Postable(post arn.Postable, user *arn.User, highlightAuthorID string)
a.post-tool.post-like.tip.action(id="like-" + post.ID(), aria-label="Like", data-action="like", data-trigger="click") a.post-tool.post-like.tip.action(id="like-" + post.ID(), aria-label="Like", data-action="like", data-trigger="click")
Icon("thumbs-up") Icon("thumbs-up")
if user.Role == "admin"
a.post-tool.post-edit.tip(href=post.Link() + "/edit", aria-label="Edit")
Icon("edit")
if user.ID == post.Creator().ID if user.ID == post.Creator().ID
a.post-tool.post-edit.tip.action(data-action="editPost", data-trigger="click", data-id=post.ID(), aria-label="Edit") a.post-tool.post-edit.tip.action(data-action="editPost", data-trigger="click", data-id=post.ID(), aria-label="Edit")
Icon("pencil") Icon("pencil")

View File

@ -5,7 +5,9 @@ import (
"github.com/animenotifier/notify.moe/pages/forum" "github.com/animenotifier/notify.moe/pages/forum"
"github.com/animenotifier/notify.moe/pages/newthread" "github.com/animenotifier/notify.moe/pages/newthread"
"github.com/animenotifier/notify.moe/pages/post" "github.com/animenotifier/notify.moe/pages/post"
"github.com/animenotifier/notify.moe/pages/post/editpost"
"github.com/animenotifier/notify.moe/pages/thread" "github.com/animenotifier/notify.moe/pages/thread"
"github.com/animenotifier/notify.moe/pages/thread/editthread"
) )
// Register registers the page routes. // Register registers the page routes.
@ -16,8 +18,10 @@ func Register(l *layout.Layout) {
// Thread // Thread
l.Page("/thread/:id", thread.Get) l.Page("/thread/:id", thread.Get)
l.Page("/thread/:id/edit", editthread.Get)
l.Page("/new/thread", newthread.Get) l.Page("/new/thread", newthread.Get)
// Post // Post
l.Page("/post/:id", post.Get) l.Page("/post/:id", post.Get)
l.Page("/post/:id/edit", editpost.Get)
} }

View File

@ -0,0 +1,29 @@
package editpost
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/editform"
)
// Get post edit page.
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this post", nil)
}
post, err := arn.GetPost(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Post not found", err)
}
return ctx.HTML(components.EditPostTabs(post) + editform.Render(post, "Edit post", user))
}

View File

@ -0,0 +1,7 @@
component EditPostTabs(post *arn.Post)
.tabs
a.tab(href=post.Link())
Icon("comment")
span Post
Tab("Edit", "pencil", post.Link() + "/edit")

View File

@ -0,0 +1,29 @@
package editthread
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/editform"
)
// Get thread edit page.
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this thread", nil)
}
thread, err := arn.GetThread(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Thread not found", err)
}
return ctx.HTML(components.EditThreadTabs(thread) + editform.Render(thread, "Edit thread", user))
}

View File

@ -0,0 +1,7 @@
component EditThreadTabs(thread *arn.Thread)
.tabs
a.tab(href=thread.Link())
Icon("comments")
span Thread
Tab("Edit", "pencil", thread.Link() + "/edit")