2018-06-02 23:52:38 +00:00
|
|
|
package editthread
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-06-02 23:52:38 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
"github.com/animenotifier/notify.moe/utils/editform"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Get thread edit page.
|
2019-06-01 04:55:49 +00:00
|
|
|
func Get(ctx aero.Context) error {
|
2018-06-02 23:52:38 +00:00
|
|
|
id := ctx.Get("id")
|
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
|
|
|
|
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this thread")
|
2018-06-02 23:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|