diff --git a/model/report.go b/model/report.go index 68129ee4..8e246ff9 100644 --- a/model/report.go +++ b/model/report.go @@ -29,8 +29,30 @@ type TorrentReportJson struct { /* Model Conversion to Json */ +func getReportDescription(d string) string { + if d == "illegal" { + return "Illegal content" + } else if d == "spam" { + return "Spam / Garbage" + } else if d == "wrongcat" { + return "Wrong category" + } else if d == "dup" { + return "Duplicate / Deprecated" + } + return "???" +} + func (report *TorrentReport) ToJson() TorrentReportJson { - json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.ToJSON()} + // FIXME: report.Torrent and report.User should never be nil + var t TorrentJSON = TorrentJSON{} + if report.Torrent != nil { + t = report.Torrent.ToJSON() + } + var u UserJSON = UserJSON{} + if report.User != nil { + u = report.User.ToJSON() + } + json := TorrentReportJson{report.ID, getReportDescription(report.Description), t, u} return json } diff --git a/router/modpanel.go b/router/modpanel.go index 834c28d1..61006e83 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -32,7 +32,7 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) { torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0) languages.SetTranslationFromRequest(panelIndex, r, "en-us") - htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL} + htv := PanelIndexVbs{torrents, model.TorrentReportsToJSON(torrentReports), users, comments, NewSearchForm(), currentUser, r.URL} _ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv) } else { http.Error(w, "admins only", http.StatusForbidden) diff --git a/router/templateVariables.go b/router/templateVariables.go index 990ab278..cda04256 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -117,7 +117,7 @@ type UploadTemplateVariables struct { type PanelIndexVbs struct { Torrents []model.Torrent - TorrentReports []model.TorrentReport + TorrentReports []model.TorrentReportJson Users []model.User Comments []model.Comment Search SearchForm diff --git a/service/report/report.go b/service/report/report.go index 9b640625..7b32eba1 100644 --- a/service/report/report.go +++ b/service/report/report.go @@ -48,7 +48,6 @@ func getTorrentReportsOrderBy(parameters *serviceBase.WhereParams, orderBy strin return } } - // TODO: Vulnerable to injections. Use query builder. (is it?) // build custom db query for performance reasons dbQuery := "SELECT * FROM torrent_reports" @@ -63,7 +62,7 @@ func getTorrentReportsOrderBy(parameters *serviceBase.WhereParams, orderBy strin if limit != 0 || offset != 0 { // if limits provided dbQuery = dbQuery + " LIMIT " + strconv.Itoa(limit) + " OFFSET " + strconv.Itoa(offset) } - err = db.ORM.Preload("Torrent").Preload("User").Raw(dbQuery, params...).Find(&torrentReports).Error //fixed !!!! + err = db.ORM.Preload("Torrent").Preload("User").Raw(dbQuery, params...).Find(&torrentReports).Error return } diff --git a/templates/admin/panelindex.html b/templates/admin/panelindex.html index f8d33cbd..b718ffca 100644 --- a/templates/admin/panelindex.html +++ b/templates/admin/panelindex.html @@ -29,7 +29,7 @@ Action -{{ .Torrent.Name }}{{.UserID}}{{.Description}} +{{ .Torrent.Name }}{{.User.Username}}{{.Description}} {{ T "delete" }} {{end}} diff --git a/templates/admin/torrent_report.html b/templates/admin/torrent_report.html index a8b61ca2..6e89c550 100644 --- a/templates/admin/torrent_report.html +++ b/templates/admin/torrent_report.html @@ -6,7 +6,6 @@ User Reason Action - Action {{ range .TorrentReports}} @@ -14,8 +13,8 @@ {{.Torrent.Name}} {{.User.Username}} {{.Description}} - Delete - Delete Report + Delete + Delete Report {{end}} diff --git a/templates/view.html b/templates/view.html index 32f3fb63..58681fd4 100644 --- a/templates/view.html +++ b/templates/view.html @@ -134,8 +134,10 @@