diff --git a/mixins/Postable.pixy b/mixins/Postable.pixy index d1b81247..830ad2d4 100644 --- a/mixins/Postable.pixy +++ b/mixins/Postable.pixy @@ -37,6 +37,10 @@ component Postable(post arn.Postable, user *arn.User, highlightAuthorID string) else a.post-tool.post-like.tip.action(id="like-" + post.ID(), aria-label="Like", data-action="like", data-trigger="click") 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 a.post-tool.post-edit.tip.action(data-action="editPost", data-trigger="click", data-id=post.ID(), aria-label="Edit") diff --git a/pages/index/forumroutes/forumroutes.go b/pages/index/forumroutes/forumroutes.go index 94591e99..57230a84 100644 --- a/pages/index/forumroutes/forumroutes.go +++ b/pages/index/forumroutes/forumroutes.go @@ -5,7 +5,9 @@ import ( "github.com/animenotifier/notify.moe/pages/forum" "github.com/animenotifier/notify.moe/pages/newthread" "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/editthread" ) // Register registers the page routes. @@ -16,8 +18,10 @@ func Register(l *layout.Layout) { // Thread l.Page("/thread/:id", thread.Get) + l.Page("/thread/:id/edit", editthread.Get) l.Page("/new/thread", newthread.Get) // Post l.Page("/post/:id", post.Get) + l.Page("/post/:id/edit", editpost.Get) } diff --git a/pages/post/editpost/editpost.go b/pages/post/editpost/editpost.go new file mode 100644 index 00000000..d124e1b3 --- /dev/null +++ b/pages/post/editpost/editpost.go @@ -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)) +} diff --git a/pages/post/editpost/editpost.pixy b/pages/post/editpost/editpost.pixy new file mode 100644 index 00000000..ff47c5f6 --- /dev/null +++ b/pages/post/editpost/editpost.pixy @@ -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") \ No newline at end of file diff --git a/pages/thread/editthread/editthread.go b/pages/thread/editthread/editthread.go new file mode 100644 index 00000000..8790d27e --- /dev/null +++ b/pages/thread/editthread/editthread.go @@ -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)) +} diff --git a/pages/thread/editthread/editthread.pixy b/pages/thread/editthread/editthread.pixy new file mode 100644 index 00000000..34f19a54 --- /dev/null +++ b/pages/thread/editthread/editthread.pixy @@ -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") \ No newline at end of file