Skip to content

Commit

Permalink
Merge pull request #397 from sfan5/minorstuff
Browse files Browse the repository at this point in the history
More report categories
  • Loading branch information
Austin authored May 12, 2017
2 parents dc89495 + b2581f5 commit 83be78a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
24 changes: 23 additions & 1 deletion model/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion router/modpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion router/templateVariables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions service/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/panelindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3 id="torrents">Last Torrents Report</h3>
<th class="col-xs-1">Action</th>
</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>
{{end}}
</table>
Expand Down
5 changes: 2 additions & 3 deletions templates/admin/torrent_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
<th class="col-xs-1">User</th>
<th class="col-xs-1">Reason</th>
<th class="col-xs-1">Action</th>
<th class="col-xs-1">Action</th>
</tr>

{{ range .TorrentReports}}
<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_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td>
<td><a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}">Delete Report</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a>
<a href="{{ genRoute "mod_trdelete" }}?id={{ .ID }}">Delete Report</a></td>
</tr>
{{end}}
</table>
Expand Down
6 changes: 4 additions & 2 deletions templates/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ <h4 class="modal-title">Report Torrent #{{.ID}}</h4>
<div class="modal-body">
<b>Report type:</b>
<form method="post" action="/report/{{.ID}}">
<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="illegal"> Illegal content<br />
<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}}
{{block "captcha" .}}{{end}}
<button type="submit" class="btn btn-default">Report!</button>
Expand Down

0 comments on commit 83be78a

Please sign in to comment.