* Update profile.go * Update router.go * Update torrents.go * Update router.go * Update announcements.go * Update comments.go * Update oauth.go * Update reports.go * Update router.go * Update index.jet.html * Update torrentlist.jet.html * Update commentlist.jet.html * Update announcements.jet.html * Update clientlist.jet.html * Update torrent_report.jet.html * Update userlist.jet.html * Update userlist.jet.html * Update userlist.jet.html * Update edit.jet.html * Update delete.go * Update edit.jet.html * Update index.jet.html * Update profile.go * Update router.go * Update profile.go * Update edit.jet.html * Update userlist.jet.html * Update index.jet.html * remove hotfix that didn't even hit live
45 lignes
1,6 Kio
Go
45 lignes
1,6 Kio
Go
package torrentController
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/NyaaPantsu/nyaa/controllers/router"
|
|
"github.com/NyaaPantsu/nyaa/models"
|
|
"github.com/NyaaPantsu/nyaa/models/activities"
|
|
"github.com/NyaaPantsu/nyaa/models/reports"
|
|
"github.com/NyaaPantsu/nyaa/models/torrents"
|
|
"github.com/NyaaPantsu/nyaa/utils/search"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// TorrentDeleteUserPanel : Controller for deleting a user torrent by a user
|
|
func TorrentDeleteUserPanel(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(c.PostForm("id"), 10, 32)
|
|
currentUser := router.GetUser(c)
|
|
torrent, _ := torrents.FindByID(uint(id))
|
|
if currentUser.CurrentOrAdmin(torrent.UploaderID) && torrent.ID > 0 {
|
|
_, _, err := torrent.Delete(false)
|
|
if err == nil {
|
|
if torrent.Uploader == nil {
|
|
torrent.Uploader = &models.User{}
|
|
}
|
|
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
|
if currentUser.HasAdmin() { // We hide username on log activity if user is not admin and torrent is hidden
|
|
activities.Log(&models.User{}, torrent.Identifier(), "delete", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, currentUser.Username)
|
|
} else {
|
|
activities.Log(&models.User{}, torrent.Identifier(), "delete", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, username)
|
|
}
|
|
//delete reports of torrent
|
|
query := &search.Query{}
|
|
query.Append("torrent_id", id)
|
|
torrentReports, _, _ := reports.FindOrderBy(query, "", 0, 0)
|
|
for _, report := range torrentReports {
|
|
report.Delete(false)
|
|
}
|
|
}
|
|
c.Redirect(http.StatusSeeOther, "/?deleted")
|
|
} else {
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
}
|
|
}
|