44 lines
951 B
Go
Raw Normal View History

2018-03-18 20:41:13 +00:00
package animeimport
import (
"net/http"
2018-03-18 21:44:03 +00:00
"github.com/animenotifier/arn"
2018-03-18 20:41:13 +00:00
"github.com/aerogo/aero"
2018-03-18 21:44:03 +00:00
"github.com/animenotifier/notify.moe/utils"
2018-03-18 20:41:13 +00:00
)
2018-04-17 10:27:54 +00:00
// DeleteKitsu marks an anime for deletion.
func DeleteKitsu(ctx *aero.Context) string {
2018-03-18 21:44:03 +00:00
id := ctx.Get("id")
2018-04-17 10:27:54 +00:00
// Is the user allowed to delete?
2018-03-18 21:44:03 +00:00
user := utils.GetUser(ctx)
2018-03-18 20:41:13 +00:00
2018-03-18 21:44:03 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not authorized")
2018-03-18 20:41:13 +00:00
}
2018-04-17 10:27:54 +00:00
// Check that the anime really exists
2018-03-18 21:44:03 +00:00
kitsuAnimeObj, err := arn.Kitsu.Get("Anime", id)
if kitsuAnimeObj == nil {
return ctx.Error(http.StatusNotFound, "Kitsu anime not found", err)
}
2018-04-17 10:27:54 +00:00
// Add to deleted IDs list
deletedKitsuAnime, err := arn.GetIDList("deleted kitsu anime")
2018-03-18 21:44:03 +00:00
2018-04-17 10:27:54 +00:00
if err != nil {
deletedKitsuAnime = arn.IDList{}
}
2018-03-18 21:44:03 +00:00
2018-04-17 10:27:54 +00:00
deletedKitsuAnime = deletedKitsuAnime.Append(id)
2018-03-18 21:44:03 +00:00
// Save in database
2018-04-17 10:27:54 +00:00
arn.DB.Set("IDList", "deleted kitsu anime", &deletedKitsuAnime)
2018-03-18 21:44:03 +00:00
2018-03-18 20:41:13 +00:00
return ""
}