2020-10-04 22:22:53 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
"github.com/photoprism/photoprism/internal/i18n"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// POST /api/v1/feedback
|
|
|
|
func SendFeedback(router *gin.RouterGroup) {
|
|
|
|
router.POST("/feedback", func(c *gin.Context) {
|
2020-10-05 07:40:11 +02:00
|
|
|
conf := service.Config()
|
|
|
|
|
|
|
|
if conf.Public() {
|
|
|
|
Abort(c, http.StatusForbidden, i18n.ErrPublic)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-10-04 22:22:53 +02:00
|
|
|
s := Auth(SessionID(c), acl.ResourceFeedback, acl.ActionCreate)
|
|
|
|
|
|
|
|
if s.Invalid() {
|
|
|
|
AbortUnauthorized(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
conf.UpdatePro()
|
|
|
|
|
|
|
|
var f form.Feedback
|
|
|
|
|
|
|
|
if err := c.BindJSON(&f); err != nil {
|
|
|
|
AbortBadRequest(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Empty() {
|
|
|
|
Abort(c, http.StatusBadRequest, i18n.ErrNoItemsSelected)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := conf.Pro().SendFeedback(f); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
AbortSaveFailed(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK})
|
|
|
|
})
|
|
|
|
}
|