Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge pull request #281 from ewhal/akuma06/master

Fixing Mod Panel
Cette révision appartient à :
PantsuDev 2017-05-11 01:41:40 +10:00 révisé par GitHub
révision 0223f575d3
17 fichiers modifiés avec 257 ajouts et 75 suppressions

Voir le fichier

@ -35,7 +35,7 @@ type Torrent struct {
WebsiteLink string `gorm:"column:website_link"` WebsiteLink string `gorm:"column:website_link"`
DeletedAt *time.Time DeletedAt *time.Time
Uploader *User `gorm:"ForeignKey:UploaderId"` Uploader *User `gorm:"ForeignKey:uploader"`
OldUploader string `gorm:"-"` // ??????? OldUploader string `gorm:"-"` // ???????
OldComments []OldComment `gorm:"ForeignKey:torrent_id"` OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
Comments []Comment `gorm:"ForeignKey:torrent_id"` Comments []Comment `gorm:"ForeignKey:torrent_id"`

Voir le fichier

@ -10,23 +10,33 @@ import (
"fmt" "fmt"
"github.com/ewhal/nyaa/service/comment" "github.com/ewhal/nyaa/service/comment"
"github.com/ewhal/nyaa/service/moderation"
"github.com/ewhal/nyaa/service/torrent" "github.com/ewhal/nyaa/service/torrent"
"github.com/ewhal/nyaa/service/torrent/form" "github.com/ewhal/nyaa/service/torrent/form"
"github.com/ewhal/nyaa/util/search"
"github.com/ewhal/nyaa/service/user" "github.com/ewhal/nyaa/service/user"
form "github.com/ewhal/nyaa/service/user/form" form "github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/service/user/permission" "github.com/ewhal/nyaa/service/user/permission"
"github.com/ewhal/nyaa/util/languages" "github.com/ewhal/nyaa/util/languages"
"github.com/ewhal/nyaa/util/modelHelper" "github.com/ewhal/nyaa/util/modelHelper"
"github.com/gorilla/mux"
) )
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd, torrentReportTemplate *template.Template
func init() { 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(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(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(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"))) 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) { func IndexModPanel(w http.ResponseWriter, r *http.Request) {
@ -34,11 +44,12 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
if userPermission.HasAdmin(currentUser) { if userPermission.HasAdmin(currentUser) {
offset := 10 offset := 10
torrents, _, _ := torrentService.GetAllTorrents(0, offset) torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
users := userService.RetrieveUsersForAdmin(0, offset) users, _ := userService.RetrieveUsersForAdmin(offset, 0)
comments := commentService.GetAllComments(0, offset) comments, _ := commentService.GetAllComments(offset, 0, "", "")
torrentReports, _, _ := moderationService.GetTorrentReports(offset,0, "", "")
languages.SetTranslationFromRequest(panelIndex, r, "en-us") languages.SetTranslationFromRequest(panelIndex, r, "en-us")
htv := PanelIndexVbs{torrents, users, comments} htv := PanelIndexVbs{torrents, 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)
@ -47,13 +58,20 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) { func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r) currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) { if userPermission.HasAdmin(currentUser) {
page, _ := strconv.Atoi(r.URL.Query().Get("p")) vars := mux.Vars(r)
page, _ := strconv.Atoi(vars["page"])
offset := 100 offset := 100
torrents, _, _ := 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") languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
htv := PanelTorrentListVbs{torrents} htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, page, "mod_tlist_page"}, currentUser, r.URL}
err := panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv) err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err) fmt.Println(err)
} else { } else {
@ -63,12 +81,13 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
func UsersListPanel(w http.ResponseWriter, r *http.Request) { func UsersListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r) currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) { if userPermission.HasAdmin(currentUser) {
page, _ := strconv.Atoi(r.URL.Query().Get("p")) vars := mux.Vars(r)
page, _ := strconv.Atoi(vars["page"])
offset := 100 offset := 100
users := userService.RetrieveUsersForAdmin(offset, page*offset) users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
languages.SetTranslationFromRequest(panelUserList, r, "en-us") languages.SetTranslationFromRequest(panelUserList, r, "en-us")
htv := PanelUserListVbs{users} htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, page, "mod_ulist_page"}, currentUser, r.URL}
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv) err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err) fmt.Println(err)
} else { } else {
@ -78,12 +97,19 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
func CommentsListPanel(w http.ResponseWriter, r *http.Request) { func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r) currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) { if userPermission.HasAdmin(currentUser) {
page, _ := strconv.Atoi(r.URL.Query().Get("p")) vars := mux.Vars(r)
page, _ := strconv.Atoi(vars["page"])
offset := 100 offset := 100
userid := r.URL.Query().Get("userid")
comments := commentService.GetAllComments(offset, page * offset) var conditions string
var values []interface{}
if (userid != "") {
conditions = "user_id = ?"
values = append(values, userid)
}
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
languages.SetTranslationFromRequest(panelCommentList, r, "en-us") languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
htv := PanelCommentListVbs{comments} htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, page, "mod_clist_page"}, currentUser, r.URL}
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv) err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err) fmt.Println(err)
} else { } else {
@ -97,7 +123,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id") id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id) torrent, _ := torrentService.GetTorrentById(id)
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us") languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent} htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv) err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err) fmt.Println(err)
} else { } else {
@ -128,7 +154,7 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
} }
} }
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us") languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
htv := PanelTorrentEdVbs{torrent} htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
_ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv) _ = panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
} else { } else {
http.Error(w, "admins only", http.StatusForbidden) http.Error(w, "admins only", http.StatusForbidden)
@ -159,4 +185,4 @@ func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
} else { } else {
http.Error(w, "admins only", http.StatusForbidden) http.Error(w, "admins only", http.StatusForbidden)
} }
} }

Voir le fichier

@ -87,9 +87,12 @@ func init() {
Router.Handle("/mod", gzipIndexModPanel).Name("mod_index") Router.Handle("/mod", gzipIndexModPanel).Name("mod_index")
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist") Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
Router.Handle("/mod/torrents/{page}", gzipTorrentsListPanel).Name("mod_tlist_page")
Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist") Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist")
Router.Handle("/mod/users/{page}", gzipUsersListPanel).Name("mod_ulist_page")
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_clist") Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_clist")
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_cedit") // TODO Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
Router.Handle("/mod/torrent/", gzipTorrentEditModPanel).Name("mod_tedit") Router.Handle("/mod/torrent/", gzipTorrentEditModPanel).Name("mod_tedit")
Router.Handle("/mod/torrent/", gzipTorrentPostEditModPanel).Name("mod_ptedit") Router.Handle("/mod/torrent/", gzipTorrentPostEditModPanel).Name("mod_ptedit")
Router.Handle("/mod/torrent/delete", gzipTorrentDeleteModPanel).Name("mod_tdelete") Router.Handle("/mod/torrent/delete", gzipTorrentDeleteModPanel).Name("mod_tdelete")
@ -105,6 +108,7 @@ func init() {
//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("/mod/reports", gzipGetTorrentReportHandler).Name("torrent_report").Methods("GET") 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) Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)
} }

Voir le fichier

@ -7,7 +7,7 @@ import (
var TemplateDir = "templates" 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 { type templateLoader struct {
templ **template.Template templ **template.Template
@ -18,11 +18,6 @@ type templateLoader struct {
// ReloadTemplates reloads templates on runtime // ReloadTemplates reloads templates on runtime
func ReloadTemplates() { func ReloadTemplates() {
templs := []templateLoader{ templs := []templateLoader{
templateLoader{
templ: &torrentReportTemplate,
name: "torrent_report",
file: "torrent_report.html",
},
templateLoader{ templateLoader{
templ: &homeTemplate, templ: &homeTemplate,
name: "home", name: "home",

Voir le fichier

@ -27,9 +27,10 @@ var FuncMap = template.FuncMap{
return "error" return "error"
}, },
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML { "genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
var ret = ""
if (nav.TotalItem > 0) {
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage)) maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
var ret = ""
if nav.CurrentPage-1 > 0 { if nav.CurrentPage-1 > 0 {
url, _ := Router.Get(nav.Route).URL("page", "1") url, _ := Router.Get(nav.Route).URL("page", "1")
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>" ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>"
@ -57,6 +58,7 @@ var FuncMap = template.FuncMap{
url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1)) url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>" ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a></li>"
} }
}
return template.HTML(ret) return template.HTML(ret)
}, },
"T": i18n.IdentityTfunc, "T": i18n.IdentityTfunc,

Voir le fichier

@ -113,27 +113,51 @@ type UploadTemplateVariables struct {
Route *mux.Route Route *mux.Route
} }
/* MODERATION Variables */
type PanelIndexVbs struct { type PanelIndexVbs struct {
Torrents []model.Torrent Torrents []model.Torrent
TorrentReports []model.TorrentReport
Users []model.User Users []model.User
Comments []model.Comment Comments []model.Comment
Search SearchForm
User *model.User
URL *url.URL // For parsing Url in templates
} }
type PanelTorrentListVbs struct { type PanelTorrentListVbs struct {
Torrents []model.Torrent Torrents []model.Torrent
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
} }
type PanelUserListVbs struct { type PanelUserListVbs struct {
Users []model.User Users []model.User
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
} }
type PanelCommentListVbs struct { type PanelCommentListVbs struct {
Comments []model.Comment Comments []model.Comment
Search SearchForm
Navigation Navigation
User *model.User
URL *url.URL // For parsing Url in templates
} }
type PanelTorrentEdVbs struct { type PanelTorrentEdVbs struct {
Torrent model.Torrent Torrent model.Torrent
Search SearchForm
User *model.User
} }
type ViewTorrentReportsVariables struct { type ViewTorrentReportsVariables struct {
Torrents []model.TorrentReportJson 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 ( import (
"net/http" "net/http"
"strconv"
"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/user/permission" "github.com/ewhal/nyaa/service/user/permission"
"github.com/gorilla/mux"
) )
/* /*
func SanitizeTorrentReport(torrentReport *model.TorrentReport) { 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) { 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) 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

@ -6,8 +6,10 @@ import (
) )
func GetAllComments(limit int, offset int) []model.Comment{ func GetAllComments(limit int, offset int, conditions string, values ...interface{}) ([]model.Comment, int){
var comments []model.Comment var comments []model.Comment
db.ORM.Limit(limit).Offset(offset).Preload("User").Find(&comments) var nbComments int
return comments db.ORM.Model(&comments).Where(conditions, values...).Count(&nbComments)
db.ORM.Preload("User").Limit(limit).Offset(offset).Where(conditions, values...).Find(&comments)
return comments, nbComments
} }

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.") return http.StatusNotFound, errors.New("Trying to delete a torrent report that does not exists.")
} }
if db.ORM.Delete(&torrentReport).Error != nil { 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 return http.StatusOK, nil
} }
// TODO Add WhereParams to filter the torrent reports (ie: searching description) // TODO Add WhereParams to filter the torrent reports (ie: searching description)
// TODO Use limit, offset // 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 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 { 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

@ -273,10 +273,12 @@ func RetrieveUserForAdmin(id string) (model.User, int, error) {
} }
// RetrieveUsersForAdmin retrieves users for an administrator. // RetrieveUsersForAdmin retrieves users for an administrator.
func RetrieveUsersForAdmin(limit int, offset int) []model.User { func RetrieveUsersForAdmin(limit int, offset int) ([]model.User, int) {
var users []model.User var users []model.User
db.ORM.Preload("Torrents").Find(&users).Limit(limit).Offset(offset) var nbUsers int
return users db.ORM.Model(&users).Count(&nbUsers)
db.ORM.Preload("Torrents").Limit(limit).Offset(offset).Find(&users)
return users, nbUsers
} }
// CreateUserAuthentication creates user authentication. // CreateUserAuthentication creates user authentication.

Voir le fichier

@ -1,8 +1,15 @@
{{define "title"}}Comments List{{end}}
{{define "content"}} {{define "content"}}
<table> <table>
{{ range .Comments}} {{ range .Comments}}
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}">Delete</a></td></tr> <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>{{ T "delete" }}</a></td></tr>
{{end}} {{end}}
</table> </table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}} {{end}}

Voir le fichier

@ -1,7 +1,57 @@
{{define "title"}}Moderation Overview{{end}}
{{define "content"}} {{define "content"}}
nigga this just be some links <h3 id="torrents">Last Torrents</h3>
<a href="/mod/torrents">torrent list</a> <table>
<a href="/mod/users">user list </a> {{ range .Torrents}}
<a href="/mod/comments">comments list</a>
<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>{{ T "delete" }}</a></td></tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
<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>{{ T "delete" }}</a></td>
</tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
<a href="{{ genRoute "mod_ulist" }}">More </a>
</ul>
</nav>
<h3 id="comments">Last Comments</h3>
<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>{{ T "delete" }}</a></td></tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
<a href="{{ genRoute "mod_ulist" }}">More</a>
</ul>
</nav>
{{end}} {{end}}

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,8 +1,15 @@
{{define "title"}}Torrents List{{end}}
{{define "content"}} {{define "content"}}
<table> <table>
{{ range .Torrents}} {{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}">Delete</a></td></tr> <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>{{ T "delete" }}</a></td></tr>
{{end}} {{end}}
</table> </table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}} {{end}}

Voir le fichier

@ -1,8 +1,17 @@
{{define "title"}}Users List{{end}}
{{define "content"}} {{define "content"}}
<table> <table>
{{ range .Users}} {{ range .Users}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Username }}</a></td><td><a href="{{ genRoute "mod_tdelete" }}?id{{ .ID }}">Delete</a></td></tr> <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>{{ T "delete" }}</a></td>
</tr>
{{end}} {{end}}
</table> </table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}} {{end}}

Voir le fichier

@ -27,10 +27,46 @@
<!-- Website CSS --> <!-- Website CSS -->
</head> </head>
<body> <body>
<nav class="navbar navbar-default" id="mainmenu">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">{{ T "toggle_navigation" }}</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{.URL.Parse "/"}}">Nyaa Pantsu Moderation</a>
<a class="navbar-brand hidden-md pull-right nightswitch" href="javascript:toggleNightMode();" ></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{{.URL.Parse "/"}}">{{T "website"}}</a/></li>
<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">
<div class="form-group">
{{block "search_common" .}}{{end}}
</div>
<div class="form-group">
{{block "search_button" .}}{{end}}
</div>
</form>
</div>
</div>
</nav>
<div class="container" id="container"> <div class="container" id="container">
{{block "content" .}}{{end}} {{block "content" .}}{{end}}
</div> </div>
<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) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed --> <!-- Include all compiled plugins (below), or include individual files as needed -->

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>