5dcd30676f
* Fix "torrent is being generated" message showing up even when the torrent couldn't be generated * Add janitor user status * Remove usage of deprecated HasAdmin() function * Give Janitors access to mod panel * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Update edit.go * Update profile.go * Rollback bad changes, remove redundant email check and stop using deprecated function * Show every userstatus (member, janitor, banned, mod) in comments * Return empty status if anonymous * Show no userstatus for anonymous profile * Show moderation link to janitors too * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Stop using deprecated HasAdmin() function * Add Janitor to userstatus select in user edit * "Janitor" translation string * didnt mean to commit this change * rollback wrongfully comitted changes * rollback commit * Update CHANGELOG.md * Fix wrong id for translation * remove deprecated HasAdmin() function again * change name of variable used in comment loop for clarity purposes * visual cue for locked torrents in torrent listing for admins * add visual cues for hidden torrents in admin torrent listing * Dont show delete buttons for janitors * janitor cannot delete torrents * show block/unblock button in torrent list for janitors instead of delete button * fix function that didnt get executed * add ban buttons on userlist & visual cue for banned users * Fix "user successfully deleted" message showing even if user wasnt deleted * Add "ban" button, no "delete" button for jantiors * add "unban" and "ban" translation strings * add "unban" and "ban" translation strings * different <form> for ban button * Update index.jet.html * add userprofile ban route * add toggleBan() function, janitors dont need captcha either * fix panic error when deleting an anonymous comment * add user_banned_by and user_unbanned_by * add user_banned_by and user_unbanned_by * Make ToggleBan() return whether or not the user is now banned * Add handler for /ban route * change log filter * hide locked torrents from regular users * hide locked torrents from regular users * hide locked torrent from api search for regular users * change function to CurrentOrJanitor * change function to currentorjanitor * change function to currentorjanitor * add CurrentOrJanitor function * fix extra ( * fix extra ) and wrong variable name * Fix wrong value for janitor user status * Fix user edit that did not work because of "unique constraint user.emails" error * only immediately visually update user if user has been updated successfully * use FindAllForAdminsOrderBy in order to preload users * create FindAllForAdminsOrderBy that preloads users * Show username instead of ID in Uploader column in admin panel * Fix userprofile buttons overflowing at some specific resolutions * Mods can set users as janitors * Show ban/unban buttons on userprofile for janitors * Identical styling for usermenu links and buttons * dont show ban buttons on other staff * add ban message through get parameter * make toggleBan() trigger user update * Add "user_banned" and "user_unbanned" * add "user_banned" and "user_unbanned" * Visual cue for banned user * banned users can still log in * visual cue for banned user in badgemenu * locked status if banned user on upload * banned users cannot comment * Put "banned" text between () * add GetCategoryName() to template_test * add GetCategoryName() that returns full category name from full category string * Show search content in page title if it exists, or search category if it exists, otherwise shows "Home" * error message when user uploads an torrent & is banned * add torrent_uploaded_locked * add torrent_uploaded_locked * fix delete definitely button that never appeared * Show delete definitely button on admin panel index * admins can undelete a torrent by editing it's status * Trigger ViewHandler() directly instead of redirecting * Render the template directly instead of triggering torrent view handler * bigger usermenu buttons once responsive design kicks in * make btn-* class non-bold * Responsive notification page * visual cue for locked torrents in torrent listing * Update search.go * Update search.go * Update api.go * Update helpers.go * Update template.go * Update torrentParam.go * remove "hidden" class * Update search.go * fix an html error * Add files via upload * Update admin.jet.html * Update index.go * Update index.go * Update router.go * Update torrentParam_test.go * Update torrentParam_test.go * fix extra " * fix bad copypaste * Update CHANGELOG.md * Update guidelines.jet.html * Update CHANGELOG.md * add Guidelines and Moderation Guidelines * fix missing commas * Update torrentlist.jet.html * Update find.go * Update stats.go * Update view.jet.html * Update index.jet.html
205 lignes
6,4 Kio
Go
205 lignes
6,4 Kio
Go
package moderatorController
|
|
|
|
import (
|
|
"fmt"
|
|
"html"
|
|
"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/templates"
|
|
"github.com/NyaaPantsu/nyaa/utils/log"
|
|
msg "github.com/NyaaPantsu/nyaa/utils/messages"
|
|
"github.com/NyaaPantsu/nyaa/utils/search"
|
|
"github.com/NyaaPantsu/nyaa/utils/upload"
|
|
"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// TorrentsListPanel : Controller for listing torrents, can accept common search arguments
|
|
func TorrentsListPanel(c *gin.Context) {
|
|
page := c.Param("page")
|
|
messages := msg.GetMessages(c)
|
|
deleted := c.Request.URL.Query()["deleted"]
|
|
unblocked := c.Request.URL.Query()["unblocked"]
|
|
blocked := c.Request.URL.Query()["blocked"]
|
|
if deleted != nil {
|
|
messages.AddInfoTf("infos", "torrent_deleted", "")
|
|
}
|
|
if blocked != nil {
|
|
messages.AddInfoT("infos", "torrent_blocked")
|
|
}
|
|
if unblocked != nil {
|
|
messages.AddInfoT("infos", "torrent_unblocked")
|
|
}
|
|
|
|
var err error
|
|
pagenum := 1
|
|
if page != "" {
|
|
pagenum, err = strconv.Atoi(html.EscapeString(page))
|
|
if !log.CheckError(err) {
|
|
c.AbortWithError(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
}
|
|
|
|
searchParam, torrents, count, err := search.ByQueryWithUser(c, pagenum)
|
|
if err != nil {
|
|
messages.Error(err)
|
|
}
|
|
category := ""
|
|
if len(searchParam.Category) > 0 {
|
|
category = searchParam.Category[0].String()
|
|
}
|
|
searchForm := templates.SearchForm{
|
|
TorrentParam: searchParam,
|
|
Category: category,
|
|
ShowItemsPerPage: true,
|
|
}
|
|
|
|
nav := templates.Navigation{count, int(searchParam.Max), pagenum, "mod/torrents/p"}
|
|
|
|
templates.ModelList(c, "admin/torrentlist.jet.html", torrents, nav, searchForm)
|
|
}
|
|
|
|
// TorrentEditModPanel : Controller for editing a torrent after GET request
|
|
func TorrentEditModPanel(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
|
torrent, _ := torrents.FindUnscopeByID(uint(id))
|
|
torrent.LoadTags()
|
|
|
|
torrentJSON := torrent.ToJSON()
|
|
uploadForm := upload.NewTorrentRequest()
|
|
uploadForm.ID = torrentJSON.ID
|
|
uploadForm.Name = torrentJSON.Name
|
|
uploadForm.Category = torrentJSON.Category + "_" + torrentJSON.SubCategory
|
|
uploadForm.Status = torrentJSON.Status
|
|
uploadForm.Hidden = torrent.Hidden
|
|
uploadForm.WebsiteLink = string(torrentJSON.WebsiteLink)
|
|
uploadForm.Description = string(torrentJSON.Description)
|
|
uploadForm.Languages = torrent.Languages
|
|
uploadForm.Tags.Bind(&torrent)
|
|
|
|
templates.Form(c, "admin/paneltorrentedit.jet.html", uploadForm)
|
|
}
|
|
|
|
// TorrentPostEditModPanel : Controller for editing a torrent after POST request
|
|
func TorrentPostEditModPanel(c *gin.Context) {
|
|
var uploadForm torrentValidator.UpdateRequest
|
|
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
|
messages := msg.GetMessages(c)
|
|
torrent, _ := torrents.FindUnscopeByID(uint(id))
|
|
torrent.LoadTags()
|
|
currentUser := router.GetUser(c)
|
|
if torrent.ID > 0 {
|
|
errUp := upload.ExtractEditInfo(c, &uploadForm.Update)
|
|
uploadForm.ID = torrent.ID
|
|
uploadForm.Update.ID = torrent.ID
|
|
|
|
if errUp != nil {
|
|
messages.AddErrorT("errors", "fail_torrent_update")
|
|
}
|
|
if !messages.HasErrors() {
|
|
_, err := upload.UpdateUnscopeTorrent(&uploadForm, &torrent, currentUser).UpdateUnscope()
|
|
messages.AddInfoT("infos", "torrent_updated")
|
|
if err == nil { // We only log edit torrent for admins
|
|
if torrent.Uploader == nil {
|
|
torrent.Uploader = &models.User{}
|
|
}
|
|
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
|
activities.Log(&models.User{}, torrent.Identifier(), "edit", "torrent_edited_by", strconv.Itoa(int(torrent.ID)), username, currentUser.Username)
|
|
}
|
|
}
|
|
}
|
|
templates.Form(c, "admin/paneltorrentedit.jet.html", uploadForm.Update)
|
|
}
|
|
|
|
// TorrentDeleteModPanel : Controller for deleting a torrent
|
|
func TorrentDeleteModPanel(c *gin.Context) {
|
|
var returnRoute = "/mod/torrents"
|
|
currentUser := router.GetUser(c)
|
|
|
|
if currentUser.IsModerator() {
|
|
id, _ := strconv.ParseInt(c.PostForm("id"), 10, 32)
|
|
definitely := c.Request.URL.Query()["definitely"]
|
|
|
|
torrent, errFind := torrents.FindByID(uint(id))
|
|
if errFind == nil {
|
|
var err error
|
|
if definitely != nil {
|
|
_, _, err = torrent.DefinitelyDelete()
|
|
returnRoute = "/mod/torrents/deleted"
|
|
} else {
|
|
_, _, err = torrent.Delete(false)
|
|
}
|
|
|
|
//delete reports of torrent
|
|
query := &search.Query{}
|
|
query.Append("torrent_id", id)
|
|
reports, _, _ := reports.FindOrderBy(query, "", 0, 0)
|
|
for _, report := range reports {
|
|
report.Delete()
|
|
}
|
|
|
|
if err == nil {
|
|
if torrent.Uploader == nil {
|
|
torrent.Uploader = &models.User{}
|
|
}
|
|
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
|
activities.Log(&models.User{}, torrent.Identifier(), "delete", "torrent_deleted_by", strconv.Itoa(int(torrent.ID)), username, currentUser.Username)
|
|
}
|
|
}
|
|
c.Redirect(http.StatusSeeOther, returnRoute+"?deleted")
|
|
}
|
|
|
|
c.Redirect(http.StatusSeeOther, returnRoute)
|
|
}
|
|
|
|
// DeleteTagsModPanel : Controller for deleting all torrent tags
|
|
func DeleteTagsModPanel(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(c.Query("id"), 10, 32)
|
|
|
|
torrent, errFind := torrents.FindByID(uint(id))
|
|
if errFind == nil {
|
|
// delete all tags
|
|
torrent.DeleteTags()
|
|
}
|
|
// redirect to edit form
|
|
c.Redirect(http.StatusSeeOther, fmt.Sprintf("/mod/torrent?id=%d", id))
|
|
}
|
|
|
|
// TorrentBlockModPanel : Controller to lock torrents, redirecting to previous page
|
|
func TorrentBlockModPanel(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(c.PostForm("id"), 10, 32)
|
|
torrent, _, err := torrents.ToggleBlock(uint(id))
|
|
var returnRoute, action string
|
|
if torrent.IsDeleted() {
|
|
returnRoute = "/mod/torrents/deleted"
|
|
} else {
|
|
returnRoute = "/mod/torrents"
|
|
}
|
|
if torrent.IsBlocked() {
|
|
action = "blocked"
|
|
} else {
|
|
action = "unblocked"
|
|
}
|
|
if err == nil {
|
|
if torrent.Uploader == nil {
|
|
torrent.Uploader = &models.User{}
|
|
}
|
|
_, username := torrents.HideUser(torrent.UploaderID, torrent.Uploader.Username, torrent.Hidden)
|
|
activities.Log(&models.User{}, torrent.Identifier(), action, "torrent_"+action+"_by", strconv.Itoa(int(torrent.ID)), username, router.GetUser(c).Username)
|
|
}
|
|
|
|
c.Redirect(http.StatusSeeOther, returnRoute+"?"+action)
|
|
}
|
|
|
|
// TorrentsPostListPanel : Controller for listing torrents, after POST request when mass update
|
|
func TorrentsPostListPanel(c *gin.Context) {
|
|
torrentManyAction(c)
|
|
TorrentsListPanel(c)
|
|
}
|