You can now change the permission preset of a forum. More granular permission changes coming soon.
The permission presets are now shown on the Forum Manager. The hidden state of a forum is now represented with a spy emoji on the Forum Manager.
This commit is contained in:
parent
f8e657ee39
commit
c233f1fbbe
1
data.sql
1
data.sql
|
@ -48,6 +48,7 @@ CREATE TABLE `forums`(
|
||||||
`name` varchar(100) not null,
|
`name` varchar(100) not null,
|
||||||
`active` tinyint DEFAULT 1 not null,
|
`active` tinyint DEFAULT 1 not null,
|
||||||
`topicCount` int DEFAULT 0 not null,
|
`topicCount` int DEFAULT 0 not null,
|
||||||
|
`preset` varchar(100) DEFAULT '' not null,
|
||||||
`lastTopic` varchar(100) DEFAULT '' not null,
|
`lastTopic` varchar(100) DEFAULT '' not null,
|
||||||
`lastTopicID` int DEFAULT 0 not null,
|
`lastTopicID` int DEFAULT 0 not null,
|
||||||
`lastReplyer` varchar(100) DEFAULT '' not null,
|
`lastReplyer` varchar(100) DEFAULT '' not null,
|
||||||
|
|
23
forum.go
23
forum.go
|
@ -2,11 +2,24 @@ package main
|
||||||
import "database/sql"
|
import "database/sql"
|
||||||
import _ "github.com/go-sql-driver/mysql"
|
import _ "github.com/go-sql-driver/mysql"
|
||||||
|
|
||||||
|
type ForumAdmin struct
|
||||||
|
{
|
||||||
|
ID int
|
||||||
|
Name string
|
||||||
|
Active bool
|
||||||
|
Preset string
|
||||||
|
TopicCount int
|
||||||
|
|
||||||
|
PresetLang string
|
||||||
|
PresetEmoji string
|
||||||
|
}
|
||||||
|
|
||||||
type Forum struct
|
type Forum struct
|
||||||
{
|
{
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Name string
|
||||||
Active bool
|
Active bool
|
||||||
|
Preset string
|
||||||
TopicCount int
|
TopicCount int
|
||||||
LastTopic string
|
LastTopic string
|
||||||
LastTopicID int
|
LastTopicID int
|
||||||
|
@ -20,25 +33,27 @@ type ForumSimple struct
|
||||||
ID int
|
ID int
|
||||||
Name string
|
Name string
|
||||||
Active bool
|
Active bool
|
||||||
|
Preset string
|
||||||
}
|
}
|
||||||
|
|
||||||
func create_forum(forum_name string, active bool) (int, error) {
|
func create_forum(forum_name string, active bool, preset string) (int, error) {
|
||||||
var fid int
|
var fid int
|
||||||
err := forum_entry_exists_stmt.QueryRow().Scan(&fid)
|
err := forum_entry_exists_stmt.QueryRow().Scan(&fid)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
_, err = update_forum_stmt.Exec(forum_name, active, fid)
|
_, err = update_forum_stmt.Exec(forum_name, active, preset, fid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fid, err
|
return fid, err
|
||||||
}
|
}
|
||||||
forums[fid].Name = forum_name
|
forums[fid].Name = forum_name
|
||||||
forums[fid].Active = active
|
forums[fid].Active = active
|
||||||
|
forums[fid].Preset = preset
|
||||||
return fid, nil
|
return fid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := create_forum_stmt.Exec(forum_name, active)
|
res, err := create_forum_stmt.Exec(forum_name, active, preset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +64,7 @@ func create_forum(forum_name string, active bool) (int, error) {
|
||||||
}
|
}
|
||||||
fid = int(fid64)
|
fid = int(fid64)
|
||||||
|
|
||||||
forums = append(forums, Forum{fid,forum_name,active,0,"",0,"",0,""})
|
forums = append(forums, Forum{fid,forum_name,active,preset,0,"",0,"",0,""})
|
||||||
return fid, nil
|
return fid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 212 KiB |
2
main.go
2
main.go
|
@ -78,7 +78,7 @@ func compile_templates() {
|
||||||
topics_page := TopicsPage{"Topic List",user,noticeList,topicList,""}
|
topics_page := TopicsPage{"Topic List",user,noticeList,topicList,""}
|
||||||
topics_tmpl := c.compile_template("topics.html","templates/","TopicsPage", topics_page, varList)
|
topics_tmpl := c.compile_template("topics.html","templates/","TopicsPage", topics_page, varList)
|
||||||
|
|
||||||
forum_item := Forum{1,"General Forum",true,0,"",0,"",0,""}
|
forum_item := Forum{1,"General Forum",true,"all",0,"",0,"",0,""}
|
||||||
forum_page := ForumPage{"General Forum",user,noticeList,topicList,forum_item,1,1,nil}
|
forum_page := ForumPage{"General Forum",user,noticeList,topicList,forum_item,1,1,nil}
|
||||||
forum_tmpl := c.compile_template("forum.html","templates/","ForumPage", forum_page, varList)
|
forum_tmpl := c.compile_template("forum.html","templates/","ForumPage", forum_page, varList)
|
||||||
|
|
||||||
|
|
|
@ -700,7 +700,8 @@ func route_panel_forums(w http.ResponseWriter, r *http.Request){
|
||||||
var forumList []interface{}
|
var forumList []interface{}
|
||||||
for _, forum := range forums {
|
for _, forum := range forums {
|
||||||
if forum.Name != "" {
|
if forum.Name != "" {
|
||||||
forumList = append(forumList,forum)
|
fadmin := ForumAdmin{forum.ID,forum.Name,forum.Active,forum.Preset,forum.TopicCount,preset_to_lang(forum.Preset),preset_to_emoji(forum.Preset)}
|
||||||
|
forumList = append(forumList,fadmin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pi := Page{"Forum Manager",user,noticeList,forumList,nil}
|
pi := Page{"Forum Manager",user,noticeList,forumList,nil}
|
||||||
|
@ -729,7 +730,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){
|
||||||
|
|
||||||
var active bool
|
var active bool
|
||||||
fname := r.PostFormValue("forum-name")
|
fname := r.PostFormValue("forum-name")
|
||||||
fpreset := r.PostFormValue("forum-preset")
|
fpreset := strip_invalid_preset(r.PostFormValue("forum-preset"))
|
||||||
factive := r.PostFormValue("forum-name")
|
factive := r.PostFormValue("forum-name")
|
||||||
if factive == "on" || factive == "1" {
|
if factive == "on" || factive == "1" {
|
||||||
active = true
|
active = true
|
||||||
|
@ -737,7 +738,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){
|
||||||
active = false
|
active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fid, err := create_forum(fname,active)
|
fid, err := create_forum(fname,active,fpreset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalError(err,w,r,user)
|
InternalError(err,w,r,user)
|
||||||
return
|
return
|
||||||
|
@ -866,16 +867,17 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
forum_name := r.PostFormValue("forum-name")
|
forum_name := r.PostFormValue("forum-name")
|
||||||
|
forum_preset := strip_invalid_preset(r.PostFormValue("forum-preset"))
|
||||||
forum_active := r.PostFormValue("forum-active")
|
forum_active := r.PostFormValue("forum-active")
|
||||||
if (fid > forumCapCount) || (fid < 0) || forums[fid].Name=="" {
|
if (fid > forumCapCount) || (fid < 0) || forums[fid].Name=="" {
|
||||||
LocalErrorJSQ("The forum you're trying to edit doesn't exist.",w,r,user,is_js)
|
LocalErrorJSQ("The forum you're trying to edit doesn't exist.",w,r,user,is_js)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if forum_name == "" && forum_active == "" {
|
/*if forum_name == "" && forum_active == "" {
|
||||||
LocalErrorJSQ("You haven't changed anything!",w,r,user,is_js)
|
LocalErrorJSQ("You haven't changed anything!",w,r,user,is_js)
|
||||||
return
|
return
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if forum_name == "" {
|
if forum_name == "" {
|
||||||
forum_name = forums[fid].Name
|
forum_name = forums[fid].Name
|
||||||
|
@ -890,7 +892,7 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) {
|
||||||
active = false
|
active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = update_forum_stmt.Exec(forum_name,active,fid)
|
_, err = update_forum_stmt.Exec(forum_name,active,forum_preset,fid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalErrorJSQ(err,w,r,user,is_js)
|
InternalErrorJSQ(err,w,r,user,is_js)
|
||||||
return
|
return
|
||||||
|
@ -902,6 +904,11 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) {
|
||||||
if forums[fid].Active != active {
|
if forums[fid].Active != active {
|
||||||
forums[fid].Active = active
|
forums[fid].Active = active
|
||||||
}
|
}
|
||||||
|
if forums[fid].Preset != forum_preset {
|
||||||
|
forums[fid].Preset = forum_preset
|
||||||
|
}
|
||||||
|
|
||||||
|
permmap_to_query(preset_to_permmap(forum_preset),fid)
|
||||||
|
|
||||||
if is_js == "0" {
|
if is_js == "0" {
|
||||||
http.Redirect(w,r,"/panel/forums/",http.StatusSeeOther)
|
http.Redirect(w,r,"/panel/forums/",http.StatusSeeOther)
|
||||||
|
|
12
mysql.go
12
mysql.go
|
@ -361,7 +361,7 @@ func init_database(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("Preparing create_forum statement.")
|
log.Print("Preparing create_forum statement.")
|
||||||
create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active) VALUES(?,?)")
|
create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active,preset) VALUES(?,?,?)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ func init_database(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("Preparing update_forum statement.")
|
log.Print("Preparing update_forum statement.")
|
||||||
update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ? where fid = ?")
|
update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ?, preset = ? where fid = ?")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -502,10 +502,10 @@ func init_database(err error) {
|
||||||
|
|
||||||
log.Print("Loading the forums.")
|
log.Print("Loading the forums.")
|
||||||
log.Print("Adding the uncategorised forum")
|
log.Print("Adding the uncategorised forum")
|
||||||
forums = append(forums, Forum{0,"Uncategorised",uncategorised_forum_visible,0,"",0,"",0,""})
|
forums = append(forums, Forum{0,"Uncategorised",uncategorised_forum_visible,"all",0,"",0,"",0,""})
|
||||||
|
|
||||||
//rows, err = db.Query("SELECT fid, name, active, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime FROM forums")
|
//rows, err = db.Query("SELECT fid, name, active, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime FROM forums")
|
||||||
rows, err = db.Query("select fid, name, active, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc")
|
rows, err = db.Query("select fid, name, active, preset, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -513,8 +513,8 @@ func init_database(err error) {
|
||||||
|
|
||||||
i = 1
|
i = 1
|
||||||
for ;rows.Next();i++ {
|
for ;rows.Next();i++ {
|
||||||
forum := Forum{0,"",true,0,"",0,"",0,""}
|
forum := Forum{ID:0,Name:"",Active:true,Preset:"all"}
|
||||||
err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime)
|
err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.Preset, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,3 +299,54 @@ func rebuild_forum_permissions(fid int) error {
|
||||||
func build_forum_permissions() error {
|
func build_forum_permissions() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func strip_invalid_preset(preset string) string {
|
||||||
|
switch(preset) {
|
||||||
|
case "all":
|
||||||
|
case "announce":
|
||||||
|
case "members":
|
||||||
|
case "staff":
|
||||||
|
case "admins":
|
||||||
|
case "archive":
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return preset
|
||||||
|
}
|
||||||
|
|
||||||
|
func preset_to_lang(preset string) string {
|
||||||
|
switch(preset) {
|
||||||
|
case "all":
|
||||||
|
return ""//return "Everyone"
|
||||||
|
case "announce":
|
||||||
|
return "Announcements"
|
||||||
|
case "members":
|
||||||
|
return "Member Only"
|
||||||
|
case "staff":
|
||||||
|
return "Staff Only"
|
||||||
|
case "admins":
|
||||||
|
return "Admin Only"
|
||||||
|
case "archive":
|
||||||
|
return "Archive"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func preset_to_emoji(preset string) string {
|
||||||
|
switch(preset) {
|
||||||
|
case "all":
|
||||||
|
return ""//return "Everyone"
|
||||||
|
case "announce":
|
||||||
|
return "📣"
|
||||||
|
case "members":
|
||||||
|
return "👪"
|
||||||
|
case "staff":
|
||||||
|
return "👮"
|
||||||
|
case "admins":
|
||||||
|
return "👑"
|
||||||
|
case "archive":
|
||||||
|
return "☠️"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
|
/* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */
|
||||||
package main
|
package main
|
||||||
|
import "io"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
import "html/template"
|
import "html/template"
|
||||||
import "io"
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
template_topic_handle = template_topic
|
template_topic_handle = template_topic
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
{{template "header.html" . }}
|
{{template "header.html" . }}
|
||||||
{{template "panel-menu.html" . }}
|
{{template "panel-menu.html" . }}
|
||||||
<script>var form_vars = {'forum-active': ['Hide','Show']};</script>
|
<script>var form_vars = {
|
||||||
|
'forum-active': ['Hide','Show'],
|
||||||
|
'forum-preset': ['all','announce','members','staff','admins','archive','custom']};
|
||||||
|
</script>
|
||||||
<div class="colblock_right">
|
<div class="colblock_right">
|
||||||
<div class="rowitem rowhead"><a>Forums</a></div>
|
<div class="rowitem rowhead"><a>Forums</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -9,7 +12,9 @@
|
||||||
<div class="rowitem editable_parent" style="font-weight: normal;{{if eq .ID 1}}border-bottom-style:solid;{{end}}">
|
<div class="rowitem editable_parent" style="font-weight: normal;{{if eq .ID 1}}border-bottom-style:solid;{{end}}">
|
||||||
<a data-field="forum-name" data-type="text" class="editable_block" style="font-size: 20px;position:relative;top: -2px;text-transform: none;{{if not .Active}}color:#707070;{{end}}">{{.Name}}</a>
|
<a data-field="forum-name" data-type="text" class="editable_block" style="font-size: 20px;position:relative;top: -2px;text-transform: none;{{if not .Active}}color:#707070;{{end}}">{{.Name}}</a>
|
||||||
<span style="float: right;">
|
<span style="float: right;">
|
||||||
<span data-field="forum-active" data-type="list" class="username editable_block hide_on_zero" style="color: black;{{if .Active}}display:none;" data-value="1"{{else}}" data-value="0"{{end}}>Hidden</span>
|
<span data-field="forum-active" data-type="list" class="username editable_block hide_on_zero" title="Hidden" style="color: black;{{if .Active}}display:none;" data-value="1"{{else}}" data-value="0"{{end}}>🕵️</span>
|
||||||
|
{{if .PresetEmoji}}<span data-field="forum-preset" data-type="list" data-value="{{.Preset}}" class="username editable_block" title="{{.PresetLang}}">{{.PresetEmoji}}</span>
|
||||||
|
{{else if .PresetLang}}<span data-field="forum-preset" data-type="list" data-value="{{.Preset}}" class="username editable_block">{{.PresetLang}}</span>{{else}}<span data-field="forum-preset" data-type="list" data-value="{{.Preset}}" class="username editable_block" style="display:none;">{{.PresetLang}}</span>{{end}}
|
||||||
{{if gt .ID 0}}<a class="username edit_fields hide_on_edit">Edit</a>
|
{{if gt .ID 0}}<a class="username edit_fields hide_on_edit">Edit</a>
|
||||||
<a href="/panel/forums/edit/submit/{{.ID}}"><button class='username submit_edit show_on_edit' type='submit'>Update</button></a>{{end}}
|
<a href="/panel/forums/edit/submit/{{.ID}}"><button class='username submit_edit show_on_edit' type='submit'>Update</button></a>{{end}}
|
||||||
{{if gt .ID 1}}<a href="/panel/forums/delete/{{.ID}}?session={{$.CurrentUser.Session}}" class="username">Delete</a>{{end}}
|
{{if gt .ID 1}}<a href="/panel/forums/delete/{{.ID}}?session={{$.CurrentUser.Session}}" class="username">Delete</a>{{end}}
|
||||||
|
|
2
utils.go
2
utils.go
|
@ -186,7 +186,7 @@ func getLevels(maxLevel int) []float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fill_forum_id_gap(biggerID int, smallerID int) {
|
func fill_forum_id_gap(biggerID int, smallerID int) {
|
||||||
dummy := Forum{0,"",false,0,"",0,"",0,""}
|
dummy := Forum{ID:0,Name:"",Active:false,Preset:"all"}
|
||||||
for i := smallerID; i > biggerID;i++ {
|
for i := smallerID; i > biggerID;i++ {
|
||||||
forums = append(forums, dummy)
|
forums = append(forums, dummy)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue