Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

display reports properly

Cette révision appartient à :
Your Name 2017-05-10 07:57:55 +00:00
Parent 07d488ed96
révision a8e3f705fb
6 fichiers modifiés avec 25 ajouts et 20 suppressions

Voir le fichier

@ -47,9 +47,11 @@ type Torrent struct {
// FIXME can't preload field Torrents for model.TorrentReport // FIXME can't preload field Torrents for model.TorrentReport
type TorrentReport struct { type TorrentReport struct {
ID uint `gorm:"column:torrent_report_id;primary_key"` ID uint `gorm:"column:torrent_report_id;primary_key"`
Description string `gorm:"description"` Description string `gorm:"column:type"`
Torrent Torrent `gorm:"ForeignKey:Id"` TorrentID uint
User User `gorm:"ForeignKey:Id"` UserID uint
Torrent Torrent `gorm:"ForeignKey:TorrentID;AssociationForeignKey:ID"`
User User `gorm:"ForeignKey:UserID;AssociationForeignKey:ID"`
} }
/* We need a JSON object instead of a Gorm structure because magnet URLs are /* We need a JSON object instead of a Gorm structure because magnet URLs are
@ -89,14 +91,14 @@ type TorrentJSON struct {
type TorrentReportJson struct { type TorrentReportJson struct {
ID uint `json:"id"` ID uint `json:"id"`
Description string `json:"description"` Description string `json:"description"`
Torrent Torrent `json:"torrent"` Torrent TorrentJSON `json:"torrent"`
User User `json:"user"` User string
} }
/* Model Conversion to Json */ /* Model Conversion to Json */
func (report *TorrentReport) ToJson() TorrentReportJson { func (report *TorrentReport) ToJson() TorrentReportJson {
json := TorrentReportJson{report.ID, report.Description, report.Torrent, report.User} json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.Username}
return json return json
} }

Voir le fichier

@ -49,9 +49,9 @@ func init() {
gzipTorrentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentDeleteModPanel)) gzipTorrentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentDeleteModPanel))
gzipGetTorrentReportHandler := handlers.CompressHandler(http.HandlerFunc(GetTorrentReportHandler)) gzipGetTorrentReportHandler := handlers.CompressHandler(http.HandlerFunc(GetTorrentReportHandler))
gzipTorrentReportCreateHandler := handlers.CompressHandler(http.HandlerFunc(CreateTorrentReportHandler)) //gzipTorrentReportCreateHandler := handlers.CompressHandler(http.HandlerFunc(CreateTorrentReportHandler))
gzipTorrentReportDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentReportHandler)) //gzipTorrentReportDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentReportHandler))
gzipTorrentDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentHandler)) //gzipTorrentDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentHandler))
Router = mux.NewRouter() Router = mux.NewRouter()
@ -96,10 +96,10 @@ func init() {
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles) Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
Router.Handle("/report/create", gzipTorrentReportCreateHandler).Name("torrent_report_create").Methods("POST") //Router.Handle("/report/create", gzipTorrentReportCreateHandler).Name("torrent_report_create").Methods("POST")
// TODO Allow only moderators to access /moderation/* // TODO Allow only moderators to access /moderation/*
Router.Handle("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST") //Router.Handle("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST")
Router.Handle("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST") //Router.Handle("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST")
Router.Handle("/moderation/report", gzipGetTorrentReportHandler ).Name("torrent_report").Methods("GET") Router.Handle("/moderation/report", gzipGetTorrentReportHandler ).Name("torrent_report").Methods("GET")
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler) Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)

Voir le fichier

@ -132,6 +132,10 @@ type PanelTorrentEdVbs struct {
Torrent model.Torrent Torrent model.Torrent
} }
type ViewTorrentReportsVariables struct {
Torrents []model.TorrentReportJson
}
/* /*
* Variables used by the upper ones * Variables used by the upper ones
*/ */

Voir le fichier

@ -5,10 +5,8 @@ import (
"github.com/ewhal/nyaa/model" "github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/moderation" "github.com/ewhal/nyaa/service/moderation"
"github.com/ewhal/nyaa/service/torrent"
"github.com/ewhal/nyaa/util/modelHelper"
) )
/*
func SanitizeTorrentReport(torrentReport *model.TorrentReport) { func SanitizeTorrentReport(torrentReport *model.TorrentReport) {
// TODO unescape html ? // TODO unescape html ?
return return
@ -47,19 +45,20 @@ func DeleteTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
} }
*/
func GetTorrentReportHandler(w http.ResponseWriter, r *http.Request) { func GetTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
torrentReports, err := moderationService.GetTorrentReports() torrentReports, err := moderationService.GetTorrentReports()
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
err = torrentReportTemplate.ExecuteTemplate(w, "torrent_report.html", model.TorrentReportsToJSON(torrentReports)) err = torrentReportTemplate.ExecuteTemplate(w, "torrent_report.html", ViewTorrentReportsVariables{model.TorrentReportsToJSON(torrentReports)})
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
} }
/*
func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) { func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
// TODO Figure out how to get torrent report id from form // TODO Figure out how to get torrent report id from form
@ -69,4 +68,4 @@ func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
} }*/

Voir le fichier

@ -31,7 +31,7 @@ func DeleteTorrentReport(id int) (int, error) {
// TODO Use limit, offset // TODO Use limit, offset
func GetTorrentReports() ([]model.TorrentReport, error) { func GetTorrentReports() ([]model.TorrentReport, error) {
var torrentReports []model.TorrentReport var torrentReports []model.TorrentReport
if db.ORM.Preload("User").Preload("Torrents").Find(&torrentReports).Error != nil { if db.ORM.Preload("User").Preload("Torrent").Find(&torrentReports).Error != nil {
return nil, errors.New("Problem finding all torrent reports.") return nil, errors.New("Problem finding all torrent reports.")
} }
return torrentReports, nil return torrentReports, nil

Voir le fichier

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
{{ range .TorrentReport }} {{ range .Torrents}}
{{ .ID }} {{ .Description }} {{ .User }} {{ .ID }} {{ .Description }} {{ .User }}
{{end}} {{end}}
</html> </html>