révision
83be78aa1b
7 fichiers modifiés avec 33 ajouts et 11 suppressions
|
@ -29,8 +29,30 @@ type TorrentReportJson struct {
|
||||||
|
|
||||||
/* Model Conversion to Json */
|
/* 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 {
|
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
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
|
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
|
||||||
|
|
||||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
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)
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
|
|
|
@ -117,7 +117,7 @@ type UploadTemplateVariables struct {
|
||||||
|
|
||||||
type PanelIndexVbs struct {
|
type PanelIndexVbs struct {
|
||||||
Torrents []model.Torrent
|
Torrents []model.Torrent
|
||||||
TorrentReports []model.TorrentReport
|
TorrentReports []model.TorrentReportJson
|
||||||
Users []model.User
|
Users []model.User
|
||||||
Comments []model.Comment
|
Comments []model.Comment
|
||||||
Search SearchForm
|
Search SearchForm
|
||||||
|
|
|
@ -48,7 +48,6 @@ func getTorrentReportsOrderBy(parameters *serviceBase.WhereParams, orderBy strin
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Vulnerable to injections. Use query builder. (is it?)
|
|
||||||
|
|
||||||
// build custom db query for performance reasons
|
// build custom db query for performance reasons
|
||||||
dbQuery := "SELECT * FROM torrent_reports"
|
dbQuery := "SELECT * FROM torrent_reports"
|
||||||
|
@ -63,7 +62,7 @@ func getTorrentReportsOrderBy(parameters *serviceBase.WhereParams, orderBy strin
|
||||||
if limit != 0 || offset != 0 { // if limits provided
|
if limit != 0 || offset != 0 { // if limits provided
|
||||||
dbQuery = dbQuery + " LIMIT " + strconv.Itoa(limit) + " OFFSET " + strconv.Itoa(offset)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<th class="col-xs-1">Action</th>
|
<th class="col-xs-1">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.UserID}}</td><td>{{.Description}}</td>
|
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td>
|
||||||
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td></tr>
|
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a></td></tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
<th class="col-xs-1">User</th>
|
<th class="col-xs-1">User</th>
|
||||||
<th class="col-xs-1">Reason</th>
|
<th class="col-xs-1">Reason</th>
|
||||||
<th class="col-xs-1">Action</th>
|
<th class="col-xs-1">Action</th>
|
||||||
<th class="col-xs-1">Action</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{{ range .TorrentReports}}
|
{{ range .TorrentReports}}
|
||||||
|
@ -14,8 +13,8 @@
|
||||||
<td><a href="{{ genRoute "mod_tedit"}}?id={{.Torrent.ID}}">{{.Torrent.Name}}</a></td>
|
<td><a href="{{ genRoute "mod_tedit"}}?id={{.Torrent.ID}}">{{.Torrent.Name}}</a></td>
|
||||||
<td>{{.User.Username}}</td>
|
<td>{{.User.Username}}</td>
|
||||||
<td>{{.Description}}</td>
|
<td>{{.Description}}</td>
|
||||||
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td>
|
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a>
|
||||||
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}">Delete Report</a></td>
|
<a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}">Delete Report</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -134,8 +134,10 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<b>Report type:</b>
|
<b>Report type:</b>
|
||||||
<form method="post" action="/report/{{.ID}}">
|
<form method="post" action="/report/{{.ID}}">
|
||||||
<input type="radio" name="report_type" value="illegal"> Illegal content <br/>
|
<input type="radio" name="report_type" value="illegal"> Illegal content<br />
|
||||||
<input type="radio" name="report_type" value="spam"> Spam / garbage
|
<input type="radio" name="report_type" value="spam"> Spam / Garbage<br />
|
||||||
|
<input type="radio" name="report_type" value="wrongcat"> Wrong category<br />
|
||||||
|
<input type="radio" name="report_type" value="dup"> Duplicate / Deprecated<br />
|
||||||
{{end}}
|
{{end}}
|
||||||
{{block "captcha" .}}{{end}}
|
{{block "captcha" .}}{{end}}
|
||||||
<button type="submit" class="btn btn-default">Report!</button>
|
<button type="submit" class="btn btn-default">Report!</button>
|
||||||
|
|
Référencer dans un nouveau ticket