Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Mostly finished

Someone need to do torrent edit page
Can't do it :/
Cette révision appartient à :
akuma06 2017-05-10 17:37:49 +02:00
Parent 032688f532
révision 0bf8088457
13 fichiers modifiés avec 118 ajouts et 53 suppressions

Voir le fichier

@ -10,8 +10,10 @@ import (
"fmt"
"github.com/ewhal/nyaa/service/comment"
"github.com/ewhal/nyaa/service/moderation"
"github.com/ewhal/nyaa/service/torrent"
"github.com/ewhal/nyaa/service/torrent/form"
"github.com/ewhal/nyaa/util/search"
"github.com/ewhal/nyaa/service/user"
form "github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/service/user/permission"
@ -20,14 +22,21 @@ import (
"github.com/gorilla/mux"
)
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd, torrentReportTemplate *template.Template
func init() {
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
panelTorrentList = template.Must(panelTorrentList.ParseGlob(filepath.Join("templates", "_*.html")))
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
panelUserList = template.Must(panelUserList.ParseGlob(filepath.Join("templates", "_*.html")))
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
panelCommentList = template.Must(panelCommentList.ParseGlob(filepath.Join("templates", "_*.html")))
panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html")))
panelTorrentEd = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
panelIndex = template.Must(panelIndex.ParseGlob(filepath.Join("templates", "_*.html")))
panelTorrentEd = template.Must(template.New("torrent_ed").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
panelTorrentEd = template.Must(panelTorrentEd.ParseGlob(filepath.Join("templates", "_*.html")))
torrentReportTemplate = template.Must(template.New("torrent_report").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrent_report.html")))
torrentReportTemplate = template.Must(torrentReportTemplate.ParseGlob(filepath.Join("templates", "_*.html")))
}
func IndexModPanel(w http.ResponseWriter, r *http.Request) {
@ -38,8 +47,9 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
users, _ := userService.RetrieveUsersForAdmin(offset, 0)
comments, _ := commentService.GetAllComments(offset, 0, "", "")
torrentReports, _, _ := moderationService.GetTorrentReports(offset,0, "", "")
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
htv := PanelIndexVbs{torrents, users, comments, r.URL}
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
} else {
http.Error(w, "admins only", http.StatusForbidden)
@ -52,10 +62,16 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
page, _ := strconv.Atoi(vars["page"])
offset := 100
torrents, nbTorrents, _ := torrentService.GetAllTorrents(offset, page * offset)
searchParam, torrents, _, err := search.SearchByQuery(r, page)
searchForm := SearchForm{
SearchParam: searchParam,
Category: searchParam.Category.String(),
HideAdvancedSearch: false,
}
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
htv := PanelTorrentListVbs{torrents, Navigation{nbTorrents, offset, page, "mod_tlist_page"}, r.URL}
err := panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, page, "mod_tlist_page"}, currentUser, r.URL}
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -71,7 +87,7 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
htv := PanelUserListVbs{users, Navigation{nbUsers, offset, page, "mod_ulist_page"}, r.URL}
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, page, "mod_ulist_page"}, currentUser, r.URL}
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -93,7 +109,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
}
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
htv := PanelCommentListVbs{comments, Navigation{nbComments, offset, page, "mod_clist_page"}, r.URL}
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, page, "mod_clist_page"}, currentUser, r.URL}
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -107,7 +123,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id)
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent}
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -138,7 +154,7 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
}
}
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent}
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
} else {
http.Error(w, "admins only", http.StatusForbidden)
@ -169,4 +185,4 @@ func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
} else {
http.Error(w, "admins only", http.StatusForbidden)
}
}
}

Voir le fichier

@ -106,6 +106,7 @@ func init() {
//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("/mod/reports", gzipGetTorrentReportHandler).Name("torrent_report").Methods("GET")
Router.Handle("/mod/reports/{page}", gzipGetTorrentReportHandler).Name("mod_trlist").Methods("GET")
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
}

Voir le fichier

@ -7,7 +7,7 @@ import (
var TemplateDir = "templates"
var torrentReportTemplate, homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate, viewProfileTemplate, viewProfileEditTemplate, viewUserDeleteTemplate, notFoundTemplate *template.Template
var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate, viewVerifySuccessTemplate, viewProfileTemplate, viewProfileEditTemplate, viewUserDeleteTemplate, notFoundTemplate *template.Template
type templateLoader struct {
templ **template.Template
@ -18,11 +18,6 @@ type templateLoader struct {
// ReloadTemplates reloads templates on runtime
func ReloadTemplates() {
templs := []templateLoader{
templateLoader{
templ: &torrentReportTemplate,
name: "torrent_report",
file: "torrent_report.html",
},
templateLoader{
templ: &homeTemplate,
name: "home",

Voir le fichier

@ -113,34 +113,51 @@ type UploadTemplateVariables struct {
Route *mux.Route
}
/* MODERATION Variables */
type PanelIndexVbs struct {
Torrents []model.Torrent
TorrentReports []model.TorrentReport
Users []model.User
Comments []model.Comment
Search SearchForm
User *model.User
URL *url.URL // For parsing Url in templates
}
type PanelTorrentListVbs struct {
Torrents []model.Torrent
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
}
type PanelUserListVbs struct {
Users []model.User
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
}
type PanelCommentListVbs struct {
Comments []model.Comment
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
}
type PanelTorrentEdVbs struct {
Torrent model.Torrent
Search SearchForm
User *model.User
}
type ViewTorrentReportsVariables struct {
Torrents []model.TorrentReportJson
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
}
/*

Voir le fichier

@ -2,10 +2,12 @@ package router
import (
"net/http"
"strconv"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/moderation"
"github.com/ewhal/nyaa/service/user/permission"
"github.com/gorilla/mux"
)
/*
func SanitizeTorrentReport(torrentReport *model.TorrentReport) {
@ -47,24 +49,7 @@ func DeleteTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
}
}
*/
func GetTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
torrentReports, err := moderationService.GetTorrentReports()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = torrentReportTemplate.ExecuteTemplate(w, "torrent_report.html", ViewTorrentReportsVariables{model.TorrentReportsToJSON(torrentReports)})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else {
http.Error(w, "admins only", http.StatusForbidden)
}
}
/*
func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
@ -76,3 +61,33 @@ func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}*/
func GetTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
vars := mux.Vars(r)
page, _ := strconv.Atoi(vars["page"])
offset := 100
userid := r.URL.Query().Get("userid")
var conditions string
var values []interface{}
if (userid != "") {
conditions = "user_id = ?"
values = append(values, userid)
}
torrentReports, nbReports, err := moderationService.GetTorrentReports(offset, page * offset, conditions, values...)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = torrentReportTemplate.ExecuteTemplate(w, "admin_index.html", ViewTorrentReportsVariables{model.TorrentReportsToJSON(torrentReports), NewSearchForm(), Navigation{nbReports, offset, page, "mod_trlist_page"}, currentUser, r.URL})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else {
http.Error(w, "admins only", http.StatusForbidden)
}
}

Voir le fichier

@ -22,17 +22,19 @@ func DeleteTorrentReport(id int) (int, error) {
return http.StatusNotFound, errors.New("Trying to delete a torrent report that does not exists.")
}
if db.ORM.Delete(&torrentReport).Error != nil {
return http.StatusInternalServerError, errors.New("User is not deleted.")
return http.StatusInternalServerError, errors.New("TorrentReport is not deleted.")
}
return http.StatusOK, nil
}
// TODO Add WhereParams to filter the torrent reports (ie: searching description)
// TODO Use limit, offset
func GetTorrentReports() ([]model.TorrentReport, error) {
func GetTorrentReports(limit int, offset int, conditions string, values ...interface{}) ([]model.TorrentReport, int, error) {
var torrentReports []model.TorrentReport
var nbReports int
db.ORM.Model(&torrentReports).Where(conditions, values...).Count(&nbReports)
if db.ORM.Preload("User").Preload("Torrent").Find(&torrentReports).Error != nil {
return nil, errors.New("Problem finding all torrent reports.")
return torrentReports, nbReports, errors.New("Problem finding all torrent reports.")
}
return torrentReports, nil
return torrentReports, nbReports, nil
}

Voir le fichier

@ -1,9 +1,10 @@
{{define "title"}}Comments List{{end}}
{{define "content"}}
<table>
{{ range .Comments}}
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .User.Username }}</a></td>
<td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
<td><a href="{{ genRoute "mod_cdelete" }}?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>
<nav class="torrentNav" aria-label="Page navigation">

Voir le fichier

@ -1,10 +1,11 @@
{{define "title"}}Moderation Overview{{end}}
{{define "content"}}
<h3 id="torrents">Last Torrents</h3>
<table>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
<td><a href="{{ genRoute "mod_tdelete" }}?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>
<nav class="torrentNav" aria-label="Page navigation">
@ -12,13 +13,26 @@
<a href="{{ genRoute "mod_tlist" }}">More</a>
</ul>
</nav>
<h3 id="torrents">Last Torrents Report</h3>
<table>
{{ 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={{ .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>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
<a href="{{ genRoute "mod_trlist" }}">More</a>
</ul>
</nav>
<h3 id="users">Last Users</h3>
<table>
{{ range .Users}}
<tr>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?edit">{{ .Username }}</a></td>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" 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>
@ -32,7 +46,7 @@
{{ range .Comments}}
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .User.Username }}</a></td>
<td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
<td><a href="{{ genRoute "mod_cdelete" }}?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>
<nav class="torrentNav" aria-label="Page navigation">

Voir le fichier

@ -0,0 +1,9 @@
{{define "title"}}Torrents Report{{end}}
{{define "content"}}
<table>
<table>
{{ range .Torrents}}
<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></tr>
{{end}}
</table>
{{end}}

Voir le fichier

@ -1,9 +1,10 @@
{{define "title"}}Torrents List{{end}}
{{define "content"}}
<table>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .UploaderID }}</a></td>
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
<td><a href="{{ genRoute "mod_tdelete" }}?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>
<nav class="torrentNav" aria-label="Page navigation">

Voir le fichier

@ -1,10 +1,11 @@
{{define "title"}}Users List{{end}}
{{define "content"}}
<table>
{{ range .Users}}
<tr>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?edit">{{ .Username }}</a></td>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td>
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" 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>

Voir le fichier

@ -45,6 +45,7 @@
<li><a href="{{ genRoute "mod_tlist"}}">{{T "torrents"}}</a></li>
<li><a href="{{ genRoute "mod_ulist"}}">{{T "users"}}</a></li>
<li><a href="{{ genRoute "mod_clist"}}">{{T "comments"}}</a></li>
<li><a href="{{ genRoute "mod_trlist"}}">{{T "torrent_reports"}}</a></li>
</ul>
{{block "badge_user" .}}{{end}}
<form class="navbar-form navbar-right" role="search" action="/mod/torrents" method="get">
@ -63,7 +64,7 @@
<div class="container" id="container">
{{block "content" .}}{{end}}
</div>
<footer>
<footer style="text-align: center; padding-bottom: 2rem;font-size: 2rem;font-family: cursive; color: #616161;text-shadow: -1px -1px #999999;">
Powered by NyaaPantsu
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

Voir le fichier

@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<table>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.User}}</td><td>{{.Description}}</td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td></tr>
{{end}}
</table>
</html>