0
0
mirror of https://github.com/rls-moe/nyx synced 2024-12-24 12:17:16 +00:00

Added Board Rules

This commit is contained in:
Tim Schuster 2017-03-15 14:14:35 +01:00
parent 19d0e9282d
commit 477d3477df
No known key found for this signature in database
GPG Key ID: F9E27097EFB77F61
6 changed files with 114 additions and 6 deletions

View File

@ -56,6 +56,7 @@ func AdminRouter(r chi.Router) {
r.Post("/new_admin.sh", handleNewAdmin)
r.Post("/del_admin.sh", handleDelAdmin)
r.Get("/status.sh", serveStatus)
r.Post("/set_rules.sh", handleSetRules)
}
// Router sets up moderation functions

View File

@ -24,7 +24,9 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) {
}
db := middle.GetDB(r)
var board = &resources.Board{}
var board = &resources.Board{
Metadata: map[string]string{},
}
board.ShortName = r.FormValue("shortname")
board.LongName = r.FormValue("longname")
@ -34,7 +36,7 @@ func handleNewBoard(w http.ResponseWriter, r *http.Request) {
return
}
if board.ShortName == "admin" || board.ShortName == "@" || board.ShortName == "mod"{
if board.ShortName == "admin" || board.ShortName == "@" || board.ShortName == "mod" {
errw.ErrorWriter(errors.New("No"), w, r)
}

View File

@ -21,7 +21,7 @@
</div>
<br clear="left" /><hr />
<div class="postarea">
<form id="postform1" action="/admin/new_board.sh" method="POST">
<form action="/admin/new_board.sh" method="POST">
<table>
<tbody>
<tr>
@ -65,7 +65,7 @@
</div>
<br clear="left" /><hr />
<div class="postarea">
<form id="postform2" action="/admin/new_admin.sh" method="POST">
<form action="/admin/new_admin.sh" method="POST">
<table>
<tbody>
<tr>
@ -117,7 +117,7 @@
</div>
<br clear="left" /><hr />
<div class="postarea">
<form id="postform3" action="/admin/del_admin.sh" method="POST">
<form action="/admin/del_admin.sh" method="POST">
<table>
<tbody>
<tr>
@ -157,7 +157,7 @@
</div>
<br clear="left" /><hr />
<div class="postarea">
<form id="postform4" action="/admin/cleanup.sh" method="POST">
<form action="/admin/cleanup.sh" method="POST">
<table>
<tbody>
<tr>
@ -184,5 +184,57 @@
</form>
</div>
<br clear="left" /><hr />
<div class="postarea">
<form action="/admin/set_rules.sh" method="POST">
<table>
<tbody>
<tr>
<td class="postblock">
Action
</td>
<td>
Set Board Rules
<input
type="hidden"
name="csrf_token"
value="{{ .CSRFToken }}" />
</td>
</tr>
<tr>
<td class="postblock">
Board Name (Short)
</td>
<td>
<input type="text"
name="shortname"
required />
</td>
</tr>
<tr>
<td class="postblock">
Rules
</td>
<td>
<textarea
rows="4"
cols="48"
minlength="5"
name="rules"
required>
</textarea>
</td>
</tr>
<tr>
<td class="postblock"></td>
<td>
<input type="submit" value="Set Rules" />
<input type="reset" value="Reset" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
<br clear="left" /><hr />
</body>
</html>

View File

@ -0,0 +1,42 @@
package admin
import (
"github.com/tidwall/buntdb"
"go.rls.moe/nyx/http/errw"
"go.rls.moe/nyx/http/middle"
"go.rls.moe/nyx/resources"
"net/http"
)
func handleSetRules(w http.ResponseWriter, r *http.Request) {
sess := middle.GetSession(r)
if !middle.IsAdminSession(sess) {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("Unauthorized"))
return
}
err := r.ParseForm()
if err != nil {
errw.ErrorWriter(err, w, r)
return
}
db := middle.GetDB(r)
boardName := r.FormValue("shortname")
rules := r.FormValue("rules")
if err = db.Update(func(tx *buntdb.Tx) error {
board, err := resources.GetBoard(tx, r.Host, boardName)
if err != nil {
return err
}
board.Metadata["rules"] = rules
return resources.UpdateBoard(tx, r.Host, board)
}); err != nil {
errw.ErrorWriter(err, w, r)
return
}
http.Redirect(w, r, "/admin/panel.html", http.StatusSeeOther)
}

View File

@ -34,6 +34,7 @@ func handleNewThread(w http.ResponseWriter, r *http.Request) {
var mainReply = &resources.Reply{}
thread.Board = chi.URLParam(r, "board")
thread.Metadata = map[string]string{}
err = parseReply(r, mainReply)
if err == trollThrottle {

View File

@ -103,6 +103,16 @@
<input type="submit" value="Post" />
</td>
</tr>
{{ if .Board.Metadata.rules }}
<tr>
<td class="postblock">
Rules
</td>
<td class="rules">
{{ renderText .Board.Metadata.rules }}
</td>
</tr>
{{ end }}
</tbody>
</table>
</form>