2017-04-05 14:15:22 +00:00
package main
2017-05-07 08:31:41 +00:00
import (
2017-12-30 05:47:46 +00:00
"database/sql"
2017-09-03 04:50:31 +00:00
"encoding/json"
2017-05-07 08:31:41 +00:00
"errors"
2017-09-03 04:50:31 +00:00
"fmt"
"log"
"net/http"
"strconv"
"strings"
2017-05-07 08:31:41 +00:00
2017-11-11 04:06:16 +00:00
"./common"
2017-07-17 10:23:42 +00:00
"github.com/Azareal/gopsutil/mem"
2017-06-28 12:05:26 +00:00
)
2017-04-05 14:15:22 +00:00
2018-01-10 03:32:48 +00:00
// We're trying to reduce the amount of boilerplate in here, so I added these two functions, they might wind up circulating outside this file in the future
func panelSuccessRedirect ( dest string , w http . ResponseWriter , r * http . Request , isJs bool ) common . RouteError {
if ! isJs {
http . Redirect ( w , r , dest , http . StatusSeeOther )
} else {
w . Write ( successJSONBytes )
}
return nil
}
2018-01-11 08:03:17 +00:00
func panelRenderTemplate ( tmplName string , w http . ResponseWriter , r * http . Request , user common . User , pi interface { } ) common . RouteError {
2018-02-19 04:26:01 +00:00
if common . RunPreRenderHook ( "pre_render_" + tmplName , w , r , & user , pi ) {
return nil
2018-01-10 03:32:48 +00:00
}
2018-01-11 08:03:17 +00:00
err := common . Templates . ExecuteTemplate ( w , tmplName + ".html" , pi )
2018-01-10 03:32:48 +00:00
if err != nil {
return common . InternalError ( err , w , r )
}
return nil
2018-01-11 08:03:17 +00:00
}
2018-01-10 03:32:48 +00:00
2018-01-22 08:15:45 +00:00
func routePanelDashboard ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_dashboard" )
2017-05-29 14:52:37 +00:00
2017-07-17 10:23:42 +00:00
// We won't calculate this on the spot anymore, as the system doesn't seem to like it if we do multiple fetches simultaneously. Should we constantly calculate this on a background thread? Perhaps, the watchdog to scale back heavy features under load? One plus side is that we'd get immediate CPU percentages here instead of waiting it to kick in with WebSockets
2017-09-03 04:50:31 +00:00
var cpustr = "Unknown"
2017-07-17 10:23:42 +00:00
var cpuColour string
2017-11-23 05:37:08 +00:00
lessThanSwitch := func ( number int , lowerBound int , midBound int ) string {
switch {
case number < lowerBound :
return "stat_green"
case number < midBound :
return "stat_orange"
}
return "stat_red"
}
2017-05-07 08:31:41 +00:00
var ramstr , ramColour string
memres , err := mem . VirtualMemory ( )
if err != nil {
ramstr = "Unknown"
} else {
2017-11-11 04:06:16 +00:00
totalCount , totalUnit := common . ConvertByteUnit ( float64 ( memres . Total ) )
usedCount := common . ConvertByteInUnit ( float64 ( memres . Total - memres . Available ) , totalUnit )
2017-05-29 14:52:37 +00:00
2017-05-07 08:31:41 +00:00
// Round totals with .9s up, it's how most people see it anyway. Floats are notoriously imprecise, so do it off 0.85
var totstr string
2017-09-03 04:50:31 +00:00
if ( totalCount - float64 ( int ( totalCount ) ) ) > 0.85 {
usedCount += 1.0 - ( totalCount - float64 ( int ( totalCount ) ) )
totstr = strconv . Itoa ( int ( totalCount ) + 1 )
2017-05-07 08:31:41 +00:00
} else {
2017-09-03 04:50:31 +00:00
totstr = fmt . Sprintf ( "%.1f" , totalCount )
2017-05-07 08:31:41 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if usedCount > totalCount {
usedCount = totalCount
2017-05-07 08:31:41 +00:00
}
2017-09-03 04:50:31 +00:00
ramstr = fmt . Sprintf ( "%.1f" , usedCount ) + " / " + totstr + totalUnit
2017-05-29 14:52:37 +00:00
2017-05-07 08:31:41 +00:00
ramperc := ( ( memres . Total - memres . Available ) * 100 ) / memres . Total
2017-11-23 05:37:08 +00:00
ramColour = lessThanSwitch ( int ( ramperc ) , 50 , 75 )
}
greaterThanSwitch := func ( number int , lowerBound int , midBound int ) string {
switch {
case number > midBound :
return "stat_green"
case number > lowerBound :
return "stat_orange"
2017-05-07 08:31:41 +00:00
}
2017-11-23 05:37:08 +00:00
return "stat_red"
2017-05-07 08:31:41 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
// TODO: Add a stat store for this?
2017-12-30 05:47:46 +00:00
var intErr error
2018-06-06 00:21:22 +00:00
var extractStat = func ( stmt * sql . Stmt , args ... interface { } ) ( stat int ) {
err := stmt . QueryRow ( args ... ) . Scan ( & stat )
2017-12-30 05:47:46 +00:00
if err != nil && err != ErrNoRows {
intErr = err
}
return stat
2017-05-07 08:31:41 +00:00
}
2017-12-30 05:47:46 +00:00
var postCount = extractStat ( stmts . todaysPostCount )
2017-09-03 04:50:31 +00:00
var postInterval = "day"
2017-11-23 05:37:08 +00:00
var postColour = greaterThanSwitch ( postCount , 5 , 25 )
2017-05-29 14:52:37 +00:00
2017-12-30 05:47:46 +00:00
var topicCount = extractStat ( stmts . todaysTopicCount )
2017-09-03 04:50:31 +00:00
var topicInterval = "day"
2017-11-23 05:37:08 +00:00
var topicColour = greaterThanSwitch ( topicCount , 0 , 8 )
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
var reportCount = extractStat ( stmts . todaysTopicCountByForum , common . ReportForumID )
2017-09-03 04:50:31 +00:00
var reportInterval = "week"
2017-05-29 14:52:37 +00:00
2017-12-30 05:47:46 +00:00
var newUserCount = extractStat ( stmts . todaysNewUserCount )
2017-09-03 04:50:31 +00:00
var newUserInterval = "week"
2017-05-29 14:52:37 +00:00
2017-12-30 05:47:46 +00:00
// Did any of the extractStats fail?
if intErr != nil {
return common . InternalError ( intErr , w , r )
}
2018-06-06 00:21:22 +00:00
// TODO: Localise these
2017-11-11 04:06:16 +00:00
var gridElements = [ ] common . GridElement {
2018-06-26 04:54:20 +00:00
// TODO: Implement a check for new versions of Gosora
//common.GridElement{"dash-version", "v" + version.String(), 0, "grid_istat stat_green", "", "", "Gosora is up-to-date :)"},
common . GridElement { "dash-version" , "v" + version . String ( ) , 0 , "grid_istat" , "" , "" , "" } ,
2017-11-11 04:06:16 +00:00
common . GridElement { "dash-cpu" , "CPU: " + cpustr , 1 , "grid_istat " + cpuColour , "" , "" , "The global CPU usage of this server" } ,
common . GridElement { "dash-ram" , "RAM: " + ramstr , 2 , "grid_istat " + ramColour , "" , "" , "The global RAM usage of this server" } ,
2017-05-11 13:04:43 +00:00
}
2018-06-06 00:21:22 +00:00
var addElement = func ( element common . GridElement ) {
gridElements = append ( gridElements , element )
}
2017-05-29 14:52:37 +00:00
2018-03-08 03:59:47 +00:00
if common . EnableWebsockets {
uonline := common . WsHub . UserCount ( )
gonline := common . WsHub . GuestCount ( )
2017-05-11 13:04:43 +00:00
totonline := uonline + gonline
2017-12-30 05:47:46 +00:00
reqCount := 0
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
var onlineColour = greaterThanSwitch ( totonline , 3 , 10 )
var onlineGuestsColour = greaterThanSwitch ( gonline , 1 , 10 )
var onlineUsersColour = greaterThanSwitch ( uonline , 1 , 5 )
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
totonline , totunit := common . ConvertFriendlyUnit ( totonline )
uonline , uunit := common . ConvertFriendlyUnit ( uonline )
gonline , gunit := common . ConvertFriendlyUnit ( gonline )
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
addElement ( common . GridElement { "dash-totonline" , strconv . Itoa ( totonline ) + totunit + " online" , 3 , "grid_stat " + onlineColour , "" , "" , "The number of people who are currently online" } )
addElement ( common . GridElement { "dash-gonline" , strconv . Itoa ( gonline ) + gunit + " guests online" , 4 , "grid_stat " + onlineGuestsColour , "" , "" , "The number of guests who are currently online" } )
addElement ( common . GridElement { "dash-uonline" , strconv . Itoa ( uonline ) + uunit + " users online" , 5 , "grid_stat " + onlineUsersColour , "" , "" , "The number of logged-in users who are currently online" } )
addElement ( common . GridElement { "dash-reqs" , strconv . Itoa ( reqCount ) + " reqs / second" , 7 , "grid_stat grid_end_group " + topicColour , "" , "" , "The number of requests over the last 24 hours" } )
2017-05-07 08:31:41 +00:00
}
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
addElement ( common . GridElement { "dash-postsperday" , strconv . Itoa ( postCount ) + " posts / " + postInterval , 6 , "grid_stat " + postColour , "" , "" , "The number of new posts over the last 24 hours" } )
addElement ( common . GridElement { "dash-topicsperday" , strconv . Itoa ( topicCount ) + " topics / " + topicInterval , 7 , "grid_stat " + topicColour , "" , "" , "The number of new topics over the last 24 hours" } )
addElement ( common . GridElement { "dash-totonlineperday" , "20 online / day" , 8 , "grid_stat stat_disabled" , "" , "" , "Coming Soon!" /*, "The people online over the last 24 hours"*/ } )
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
addElement ( common . GridElement { "dash-searches" , "8 searches / week" , 9 , "grid_stat stat_disabled" , "" , "" , "Coming Soon!" /*"The number of searches over the last 7 days"*/ } )
addElement ( common . GridElement { "dash-newusers" , strconv . Itoa ( newUserCount ) + " new users / " + newUserInterval , 10 , "grid_stat" , "" , "" , "The number of new users over the last 7 days" } )
addElement ( common . GridElement { "dash-reports" , strconv . Itoa ( reportCount ) + " reports / " + reportInterval , 11 , "grid_stat" , "" , "" , "The number of reports over the last 7 days" } )
2017-05-29 14:52:37 +00:00
2017-12-30 05:47:46 +00:00
if false {
2018-06-06 00:21:22 +00:00
addElement ( common . GridElement { "dash-minperuser" , "2 minutes / user / week" , 12 , "grid_stat stat_disabled" , "" , "" , "Coming Soon!" /*"The average number of number of minutes spent by each active user over the last 7 days"*/ } )
addElement ( common . GridElement { "dash-visitorsperweek" , "2 visitors / week" , 13 , "grid_stat stat_disabled" , "" , "" , "Coming Soon!" /*"The number of unique visitors we've had over the last 7 days"*/ } )
addElement ( common . GridElement { "dash-postsperuser" , "5 posts / user / week" , 14 , "grid_stat stat_disabled" , "" , "" , "Coming Soon!" /*"The average number of posts made by each active user over the past week"*/ } )
2017-12-30 05:47:46 +00:00
}
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
pi := common . PanelDashboardPage { & common . BasePanelPage { header , stats , "dashboard" , common . ReportForumID } , gridElements }
2018-01-11 08:03:17 +00:00
return panelRenderTemplate ( "panel_dashboard" , w , r , user , & pi )
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelWordFilters ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
2017-11-11 23:34:27 +00:00
return ferr
2017-08-27 09:33:45 +00:00
}
if ! user . Perms . EditSettings {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-08-27 09:33:45 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_word_filters" )
2017-08-27 09:33:45 +00:00
2017-11-11 04:06:16 +00:00
var filterList = common . WordFilterBox . Load ( ) . ( common . WordFilterMap )
2018-06-06 00:21:22 +00:00
pi := common . PanelPage { & common . BasePanelPage { header , stats , "word-filters" , common . ReportForumID } , tList , filterList }
2018-01-11 08:03:17 +00:00
return panelRenderTemplate ( "panel_word_filters" , w , r , user , & pi )
2017-08-27 09:33:45 +00:00
}
2018-01-18 12:31:25 +00:00
func routePanelWordFiltersCreateSubmit ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2017-11-11 04:06:16 +00:00
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-08-27 09:33:45 +00:00
}
if ! user . Perms . EditSettings {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-08-27 09:33:45 +00:00
}
2017-09-03 04:50:31 +00:00
isJs := ( r . PostFormValue ( "js" ) == "1" )
2017-08-27 09:33:45 +00:00
2018-05-31 06:51:31 +00:00
// ? - We're not doing a full sanitise here, as it would be useful if admins were able to put down rules for replacing things with HTML, etc.
2017-08-27 09:33:45 +00:00
find := strings . TrimSpace ( r . PostFormValue ( "find" ) )
if find == "" {
2017-11-11 04:06:16 +00:00
return common . LocalErrorJSQ ( "You need to specify what word you want to match" , w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
replacement := strings . TrimSpace ( r . PostFormValue ( "replacement" ) )
2017-11-05 09:55:34 +00:00
res , err := stmts . createWordFilter . Exec ( find , replacement )
2017-08-27 09:33:45 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalErrorJSQ ( err , w , r , isJs )
2017-08-27 09:33:45 +00:00
}
2017-09-10 16:57:22 +00:00
lastID , err := res . LastInsertId ( )
2017-08-27 09:33:45 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalErrorJSQ ( err , w , r , isJs )
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
common . AddWordFilter ( int ( lastID ) , find , replacement )
2018-01-10 03:32:48 +00:00
return panelSuccessRedirect ( "/panel/settings/word-filters/" , w , r , isJs )
2017-08-27 09:33:45 +00:00
}
2018-01-11 08:03:17 +00:00
// TODO: Implement this as a non-JS fallback
2017-11-11 04:06:16 +00:00
func routePanelWordFiltersEdit ( w http . ResponseWriter , r * http . Request , user common . User , wfid string ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-08-27 09:33:45 +00:00
}
if ! user . Perms . EditSettings {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-08-27 09:33:45 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_edit_word_filter" )
2017-08-27 09:33:45 +00:00
_ = wfid
2018-06-06 00:21:22 +00:00
pi := common . PanelPage { & common . BasePanelPage { header , stats , "word-filters" , common . ReportForumID } , tList , nil }
2018-01-11 08:03:17 +00:00
return panelRenderTemplate ( "panel_word_filters_edit" , w , r , user , & pi )
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelWordFiltersEditSubmit ( w http . ResponseWriter , r * http . Request , user common . User , wfid string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-08-27 09:33:45 +00:00
}
2017-09-10 16:57:22 +00:00
// TODO: Either call it isJs or js rather than flip-flopping back and forth across the routes x.x
2017-09-03 04:50:31 +00:00
isJs := ( r . PostFormValue ( "isJs" ) == "1" )
2017-08-27 09:33:45 +00:00
if ! user . Perms . EditSettings {
2017-11-11 04:06:16 +00:00
return common . NoPermissionsJSQ ( w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
id , err := strconv . Atoi ( wfid )
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalErrorJSQ ( "The word filter ID must be an integer." , w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
find := strings . TrimSpace ( r . PostFormValue ( "find" ) )
if find == "" {
2017-11-11 04:06:16 +00:00
return common . LocalErrorJSQ ( "You need to specify what word you want to match" , w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
// Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement
replacement := strings . TrimSpace ( r . PostFormValue ( "replacement" ) )
2017-11-05 09:55:34 +00:00
_ , err = stmts . updateWordFilter . Exec ( find , replacement , id )
2017-08-27 09:33:45 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalErrorJSQ ( err , w , r , isJs )
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
wordFilters := common . WordFilterBox . Load ( ) . ( common . WordFilterMap )
wordFilters [ id ] = common . WordFilter { ID : id , Find : find , Replacement : replacement }
common . WordFilterBox . Store ( wordFilters )
2017-08-27 09:33:45 +00:00
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/settings/word-filters/" , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelWordFiltersDeleteSubmit ( w http . ResponseWriter , r * http . Request , user common . User , wfid string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-08-27 09:33:45 +00:00
}
2017-09-03 04:50:31 +00:00
isJs := ( r . PostFormValue ( "isJs" ) == "1" )
2017-08-27 09:33:45 +00:00
if ! user . Perms . EditSettings {
2017-11-11 04:06:16 +00:00
return common . NoPermissionsJSQ ( w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
id , err := strconv . Atoi ( wfid )
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalErrorJSQ ( "The word filter ID must be an integer." , w , r , user , isJs )
2017-08-27 09:33:45 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . deleteWordFilter . Exec ( id )
2017-08-27 09:33:45 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalErrorJSQ ( err , w , r , isJs )
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
wordFilters := common . WordFilterBox . Load ( ) . ( common . WordFilterMap )
2017-09-03 04:50:31 +00:00
delete ( wordFilters , id )
2017-11-11 04:06:16 +00:00
common . WordFilterBox . Store ( wordFilters )
2017-08-27 09:33:45 +00:00
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/settings/word-filters/" , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-08-27 09:33:45 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroups ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_groups" )
2017-05-29 14:52:37 +00:00
2017-08-15 13:47:56 +00:00
page , _ := strconv . Atoi ( r . FormValue ( "page" ) )
perPage := 9
2017-11-11 04:06:16 +00:00
offset , page , lastPage := common . PageOffset ( stats . Groups , page , perPage )
2017-08-15 13:47:56 +00:00
2017-10-21 00:27:47 +00:00
// Skip the 'Unknown' group
2017-08-15 13:47:56 +00:00
offset ++
var count int
2017-11-11 04:06:16 +00:00
var groupList [ ] common . GroupAdmin
2017-11-23 05:37:08 +00:00
groups , _ := common . Groups . GetRange ( offset , 0 )
2017-09-15 22:20:01 +00:00
for _ , group := range groups {
2017-08-15 13:47:56 +00:00
if count == perPage {
break
}
2017-04-05 14:15:22 +00:00
var rank string
2017-09-03 04:50:31 +00:00
var rankClass string
var canEdit bool
var canDelete = false
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
// TODO: Use a switch for this
2018-06-06 00:21:22 +00:00
// TODO: Localise this
2017-09-03 04:50:31 +00:00
if group . IsAdmin {
2017-04-05 14:15:22 +00:00
rank = "Admin"
2017-09-03 04:50:31 +00:00
rankClass = "admin"
} else if group . IsMod {
2017-04-05 14:15:22 +00:00
rank = "Mod"
2017-09-03 04:50:31 +00:00
rankClass = "mod"
} else if group . IsBanned {
2017-04-05 14:15:22 +00:00
rank = "Banned"
2017-09-03 04:50:31 +00:00
rankClass = "banned"
2017-04-05 14:15:22 +00:00
} else if group . ID == 6 {
rank = "Guest"
2017-09-03 04:50:31 +00:00
rankClass = "guest"
2017-04-05 14:15:22 +00:00
} else {
rank = "Member"
2017-09-03 04:50:31 +00:00
rankClass = "member"
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
canEdit = user . Perms . EditGroup && ( ! group . IsAdmin || user . Perms . EditGroupAdmin ) && ( ! group . IsMod || user . Perms . EditGroupSuperMod )
2017-11-11 04:06:16 +00:00
groupList = append ( groupList , common . GroupAdmin { group . ID , group . Name , rank , rankClass , canEdit , canDelete } )
2017-08-15 13:47:56 +00:00
count ++
2017-04-05 14:15:22 +00:00
}
2017-08-13 11:22:34 +00:00
//log.Printf("groupList: %+v\n", groupList)
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
pageList := common . Paginate ( stats . Groups , perPage , 5 )
2018-06-06 00:21:22 +00:00
pi := common . PanelGroupPage { & common . BasePanelPage { header , stats , "groups" , common . ReportForumID } , groupList , common . Paginator { pageList , page , lastPage } }
2018-01-11 08:03:17 +00:00
return panelRenderTemplate ( "panel_groups" , w , r , user , & pi )
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroupsEdit ( w http . ResponseWriter , r * http . Request , user common . User , sgid string ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . EditGroup {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_edit_group" )
2017-05-29 14:52:37 +00:00
2017-04-13 15:01:30 +00:00
gid , err := strconv . Atoi ( sgid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need to provide a whole number for the group ID" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
group , err := common . Groups . Get ( gid )
2017-09-15 22:20:01 +00:00
if err == ErrNoRows {
2017-08-13 11:22:34 +00:00
//log.Print("aaaaa monsters")
2018-06-06 00:21:22 +00:00
return common . NotFound ( w , r , header )
2017-09-15 22:20:01 +00:00
} else if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if group . IsAdmin && ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to edit an admin group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
if group . IsMod && ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to edit a super-mod group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-05 14:15:22 +00:00
var rank string
2017-10-21 00:27:47 +00:00
switch {
case group . IsAdmin :
2017-04-05 14:15:22 +00:00
rank = "Admin"
2017-10-21 00:27:47 +00:00
case group . IsMod :
2017-04-05 14:15:22 +00:00
rank = "Mod"
2017-10-21 00:27:47 +00:00
case group . IsBanned :
2017-04-05 14:15:22 +00:00
rank = "Banned"
2017-10-21 00:27:47 +00:00
case group . ID == 6 :
2017-04-05 14:15:22 +00:00
rank = "Guest"
2017-10-21 00:27:47 +00:00
default :
2017-04-05 14:15:22 +00:00
rank = "Member"
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
disableRank := ! user . Perms . EditGroupGlobalPerms || ( group . ID == 6 )
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
pi := common . PanelEditGroupPage { & common . BasePanelPage { header , stats , "groups" , common . ReportForumID } , group . ID , group . Name , group . Tag , rank , disableRank }
2018-02-19 04:26:01 +00:00
if common . RunPreRenderHook ( "pre_render_panel_edit_group" , w , r , & user , & pi ) {
return nil
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2018-06-17 07:28:18 +00:00
err = common . Templates . ExecuteTemplate ( w , "panel_group_edit.html" , pi )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroupsEditPerms ( w http . ResponseWriter , r * http . Request , user common . User , sgid string ) common . RouteError {
2018-06-06 00:21:22 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . EditGroup {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2018-06-06 00:21:22 +00:00
header . Title = common . GetTitlePhrase ( "panel_edit_group" )
2017-05-29 14:52:37 +00:00
2017-04-13 15:01:30 +00:00
gid , err := strconv . Atoi ( sgid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "The Group ID is not a valid integer." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
group , err := common . Groups . Get ( gid )
2017-09-15 22:20:01 +00:00
if err == ErrNoRows {
2017-08-13 11:22:34 +00:00
//log.Print("aaaaa monsters")
2018-06-06 00:21:22 +00:00
return common . NotFound ( w , r , header )
2017-09-15 22:20:01 +00:00
} else if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if group . IsAdmin && ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to edit an admin group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
if group . IsMod && ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to edit a super-mod group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Load the phrases in bulk for efficiency?
2017-11-11 04:06:16 +00:00
var localPerms [ ] common . NameLangToggle
2018-01-10 03:32:48 +00:00
var addLocalPerm = func ( permStr string , perm bool ) {
localPerms = append ( localPerms , common . NameLangToggle { permStr , common . GetLocalPermPhrase ( permStr ) , perm } )
}
addLocalPerm ( "ViewTopic" , group . Perms . ViewTopic )
addLocalPerm ( "LikeItem" , group . Perms . LikeItem )
addLocalPerm ( "CreateTopic" , group . Perms . CreateTopic )
2017-04-05 14:15:22 +00:00
//<--
2018-01-10 03:32:48 +00:00
addLocalPerm ( "EditTopic" , group . Perms . EditTopic )
addLocalPerm ( "DeleteTopic" , group . Perms . DeleteTopic )
addLocalPerm ( "CreateReply" , group . Perms . CreateReply )
addLocalPerm ( "EditReply" , group . Perms . EditReply )
addLocalPerm ( "DeleteReply" , group . Perms . DeleteReply )
addLocalPerm ( "PinTopic" , group . Perms . PinTopic )
addLocalPerm ( "CloseTopic" , group . Perms . CloseTopic )
2018-01-15 08:24:18 +00:00
addLocalPerm ( "MoveTopic" , group . Perms . MoveTopic )
2017-11-11 04:06:16 +00:00
var globalPerms [ ] common . NameLangToggle
2018-01-10 03:32:48 +00:00
var addGlobalPerm = func ( permStr string , perm bool ) {
globalPerms = append ( globalPerms , common . NameLangToggle { permStr , common . GetGlobalPermPhrase ( permStr ) , perm } )
}
addGlobalPerm ( "BanUsers" , group . Perms . BanUsers )
addGlobalPerm ( "ActivateUsers" , group . Perms . ActivateUsers )
addGlobalPerm ( "EditUser" , group . Perms . EditUser )
addGlobalPerm ( "EditUserEmail" , group . Perms . EditUserEmail )
addGlobalPerm ( "EditUserPassword" , group . Perms . EditUserPassword )
addGlobalPerm ( "EditUserGroup" , group . Perms . EditUserGroup )
addGlobalPerm ( "EditUserGroupSuperMod" , group . Perms . EditUserGroupSuperMod )
addGlobalPerm ( "EditUserGroupAdmin" , group . Perms . EditUserGroupAdmin )
addGlobalPerm ( "EditGroup" , group . Perms . EditGroup )
addGlobalPerm ( "EditGroupLocalPerms" , group . Perms . EditGroupLocalPerms )
addGlobalPerm ( "EditGroupGlobalPerms" , group . Perms . EditGroupGlobalPerms )
addGlobalPerm ( "EditGroupSuperMod" , group . Perms . EditGroupSuperMod )
addGlobalPerm ( "EditGroupAdmin" , group . Perms . EditGroupAdmin )
addGlobalPerm ( "ManageForums" , group . Perms . ManageForums )
addGlobalPerm ( "EditSettings" , group . Perms . EditSettings )
addGlobalPerm ( "ManageThemes" , group . Perms . ManageThemes )
addGlobalPerm ( "ManagePlugins" , group . Perms . ManagePlugins )
addGlobalPerm ( "ViewAdminLogs" , group . Perms . ViewAdminLogs )
addGlobalPerm ( "ViewIPs" , group . Perms . ViewIPs )
addGlobalPerm ( "UploadFiles" , group . Perms . UploadFiles )
2017-11-11 04:06:16 +00:00
2018-06-06 00:21:22 +00:00
pi := common . PanelEditGroupPermsPage { & common . BasePanelPage { header , stats , "groups" , common . ReportForumID } , group . ID , group . Name , localPerms , globalPerms }
2018-02-19 04:26:01 +00:00
if common . RunPreRenderHook ( "pre_render_panel_edit_group_perms" , w , r , & user , & pi ) {
return nil
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
2018-06-17 07:28:18 +00:00
err = common . Templates . ExecuteTemplate ( w , "panel_group_edit_perms.html" , pi )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroupsEditSubmit ( w http . ResponseWriter , r * http . Request , user common . User , sgid string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . EditGroup {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-13 15:01:30 +00:00
gid , err := strconv . Atoi ( sgid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need to provide a whole number for the group ID" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
group , err := common . Groups . Get ( gid )
2017-09-15 22:20:01 +00:00
if err == ErrNoRows {
2017-08-13 11:22:34 +00:00
//log.Print("aaaaa monsters")
2018-02-19 04:26:01 +00:00
return common . NotFound ( w , r , nil )
2017-09-15 22:20:01 +00:00
} else if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if group . IsAdmin && ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to edit an admin group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
if group . IsMod && ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to edit a super-mod group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-05 14:15:22 +00:00
gname := r . FormValue ( "group-name" )
if gname == "" {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "The group name can't be left blank." , w , r , user )
2017-04-05 14:15:22 +00:00
}
gtag := r . FormValue ( "group-tag" )
rank := r . FormValue ( "group-type" )
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
var originalRank string
2017-11-23 05:37:08 +00:00
// TODO: Use a switch for this
2017-09-03 04:50:31 +00:00
if group . IsAdmin {
originalRank = "Admin"
} else if group . IsMod {
originalRank = "Mod"
} else if group . IsBanned {
originalRank = "Banned"
2017-04-05 14:15:22 +00:00
} else if group . ID == 6 {
2017-09-03 04:50:31 +00:00
originalRank = "Guest"
2017-04-05 14:15:22 +00:00
} else {
2017-09-03 04:50:31 +00:00
originalRank = "Member"
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if rank != originalRank {
2017-04-05 14:15:22 +00:00
if ! user . Perms . EditGroupGlobalPerms {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupGlobalPerms permission to change the group type." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
switch rank {
case "Admin" :
if ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to designate this group as an admin group." , w , r , user )
2017-09-03 04:50:31 +00:00
}
2017-10-21 00:27:47 +00:00
err = group . ChangeRank ( true , true , false )
2017-09-03 04:50:31 +00:00
case "Mod" :
if ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to designate this group as a super-mod group." , w , r , user )
2017-09-03 04:50:31 +00:00
}
2017-10-21 00:27:47 +00:00
err = group . ChangeRank ( false , true , false )
2017-09-03 04:50:31 +00:00
case "Banned" :
2017-10-21 00:27:47 +00:00
err = group . ChangeRank ( false , false , true )
2017-09-03 04:50:31 +00:00
case "Guest" :
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You can't designate a group as a guest group." , w , r , user )
2017-09-03 04:50:31 +00:00
case "Member" :
2017-10-21 00:27:47 +00:00
err = group . ChangeRank ( false , false , false )
2017-09-03 04:50:31 +00:00
default :
2017-11-11 04:06:16 +00:00
return common . LocalError ( "Invalid group type." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-10-21 00:27:47 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-10-21 00:27:47 +00:00
}
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-02 13:35:19 +00:00
// TODO: Move this to *Group
2017-11-05 09:55:34 +00:00
_ , err = stmts . updateGroup . Exec ( gname , gtag , gid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-11-23 05:37:08 +00:00
common . Groups . Reload ( gid )
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/groups/edit/" + strconv . Itoa ( gid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroupsEditPermsSubmit ( w http . ResponseWriter , r * http . Request , user common . User , sgid string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . EditGroup {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-13 15:01:30 +00:00
gid , err := strconv . Atoi ( sgid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "The Group ID is not a valid integer." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
group , err := common . Groups . Get ( gid )
2017-09-15 22:20:01 +00:00
if err == ErrNoRows {
2017-08-13 11:22:34 +00:00
//log.Print("aaaaa monsters o.o")
2018-02-19 04:26:01 +00:00
return common . NotFound ( w , r , nil )
2017-09-15 22:20:01 +00:00
} else if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
if group . IsAdmin && ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to edit an admin group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
if group . IsMod && ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to edit a super-mod group." , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
var pmap = make ( map [ string ] bool )
2017-04-05 14:15:22 +00:00
if user . Perms . EditGroupLocalPerms {
2017-11-11 04:06:16 +00:00
for _ , perm := range common . LocalPermList {
2017-04-05 14:15:22 +00:00
pvalue := r . PostFormValue ( "group-perm-" + perm )
2017-04-13 15:01:30 +00:00
pmap [ perm ] = ( pvalue == "1" )
2017-04-05 14:15:22 +00:00
}
}
2017-05-29 14:52:37 +00:00
2017-04-05 14:15:22 +00:00
if user . Perms . EditGroupGlobalPerms {
2017-11-11 04:06:16 +00:00
for _ , perm := range common . GlobalPermList {
2017-04-05 14:15:22 +00:00
pvalue := r . PostFormValue ( "group-perm-" + perm )
2017-04-13 15:01:30 +00:00
pmap [ perm ] = ( pvalue == "1" )
2017-04-05 14:15:22 +00:00
}
}
2017-05-29 14:52:37 +00:00
2018-01-10 03:32:48 +00:00
// TODO: Abstract this
2017-04-05 14:15:22 +00:00
pjson , err := json . Marshal ( pmap )
if err != nil {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "Unable to marshal the data" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . updateGroupPerms . Exec ( pjson , gid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
err = common . RebuildGroupPermissions ( gid )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/groups/edit/perms/" + strconv . Itoa ( gid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelGroupsCreateSubmit ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . EditGroup {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
groupName := r . PostFormValue ( "group-name" )
if groupName == "" {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need a name for this group!" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
groupTag := r . PostFormValue ( "group-tag" )
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
var isAdmin , isMod , isBanned bool
2017-04-05 14:15:22 +00:00
if user . Perms . EditGroupGlobalPerms {
2017-09-03 04:50:31 +00:00
groupType := r . PostFormValue ( "group-type" )
if groupType == "Admin" {
2017-04-05 14:15:22 +00:00
if ! user . Perms . EditGroupAdmin {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupAdmin permission to create admin groups" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
isAdmin = true
isMod = true
} else if groupType == "Mod" {
2017-04-05 14:15:22 +00:00
if ! user . Perms . EditGroupSuperMod {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You need the EditGroupSuperMod permission to create admin groups" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
isMod = true
} else if groupType == "Banned" {
isBanned = true
2017-04-05 14:15:22 +00:00
}
}
2017-05-29 14:52:37 +00:00
2017-11-23 05:37:08 +00:00
gid , err := common . Groups . Create ( groupName , groupTag , isAdmin , isMod , isBanned )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/groups/edit/" + strconv . Itoa ( gid ) , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelThemes ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
2018-05-11 05:41:51 +00:00
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . ManageThemes {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2018-05-11 05:41:51 +00:00
header . Title = common . GetTitlePhrase ( "panel_themes" )
2017-05-29 14:52:37 +00:00
2017-12-01 02:04:29 +00:00
var pThemeList , vThemeList [ ] * common . Theme
2017-11-11 04:06:16 +00:00
for _ , theme := range common . Themes {
2017-04-05 14:15:22 +00:00
if theme . HideFromThemes {
continue
}
if theme . ForkOf == "" {
2017-09-03 04:50:31 +00:00
pThemeList = append ( pThemeList , theme )
2017-04-05 14:15:22 +00:00
} else {
2017-09-03 04:50:31 +00:00
vThemeList = append ( vThemeList , theme )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2018-06-06 00:21:22 +00:00
pi := common . PanelThemesPage { & common . BasePanelPage { header , stats , "themes" , common . ReportForumID } , pThemeList , vThemeList }
2018-01-11 08:03:17 +00:00
return panelRenderTemplate ( "panel_themes" , w , r , user , & pi )
2017-04-05 14:15:22 +00:00
}
2017-11-11 04:06:16 +00:00
func routePanelThemesSetDefault ( w http . ResponseWriter , r * http . Request , user common . User , uname string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
2017-10-30 09:57:08 +00:00
if ferr != nil {
return ferr
2017-04-05 14:15:22 +00:00
}
2017-06-16 10:41:30 +00:00
if ! user . Perms . ManageThemes {
2017-11-11 04:06:16 +00:00
return common . NoPermissions ( w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
theme , ok := common . Themes [ uname ]
2017-04-05 14:15:22 +00:00
if ! ok {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "The theme isn't registered in the system" , w , r , user )
2017-04-05 14:15:22 +00:00
}
if theme . Disabled {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "You must not enable this theme" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-04-05 14:15:22 +00:00
var isDefault bool
2017-11-05 09:55:34 +00:00
err := stmts . isThemeDefault . QueryRow ( uname ) . Scan ( & isDefault )
2017-06-28 12:05:26 +00:00
if err != nil && err != ErrNoRows {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
hasTheme := err != ErrNoRows
if hasTheme {
2017-04-05 14:15:22 +00:00
if isDefault {
2017-11-11 04:06:16 +00:00
return common . LocalError ( "The theme is already active" , w , r , user )
2017-04-05 14:15:22 +00:00
}
2017-11-05 09:55:34 +00:00
_ , err = stmts . updateTheme . Exec ( 1 , uname )
2017-04-05 14:15:22 +00:00
} else {
2017-11-11 23:34:27 +00:00
_ , err = stmts . addTheme . Exec ( uname , 1 )
}
if err != nil {
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Make this less racey
2017-11-11 04:06:16 +00:00
// TODO: Move this to common
common . ChangeDefaultThemeMutex . Lock ( )
defaultTheme := common . DefaultThemeBox . Load ( ) . ( string )
2017-11-05 09:55:34 +00:00
_ , err = stmts . updateTheme . Exec ( 0 , defaultTheme )
2017-04-05 14:15:22 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
return common . InternalError ( err , w , r )
2017-04-05 14:15:22 +00:00
}
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
log . Printf ( "Setting theme '%s' as the default theme" , theme . Name )
2017-04-05 14:15:22 +00:00
theme . Active = true
2017-11-11 04:06:16 +00:00
common . Themes [ uname ] = theme
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
dTheme , ok := common . Themes [ defaultTheme ]
2017-04-05 14:15:22 +00:00
if ! ok {
2017-11-11 04:06:16 +00:00
return common . InternalError ( errors . New ( "The default theme is missing" ) , w , r )
2017-04-05 14:15:22 +00:00
}
dTheme . Active = false
2017-11-11 04:06:16 +00:00
common . Themes [ defaultTheme ] = dTheme
2017-05-29 14:52:37 +00:00
2017-11-11 04:06:16 +00:00
common . DefaultThemeBox . Store ( uname )
common . ResetTemplateOverrides ( )
2017-12-01 02:04:29 +00:00
theme . MapTemplates ( )
2017-11-11 04:06:16 +00:00
common . ChangeDefaultThemeMutex . Unlock ( )
2017-05-29 14:52:37 +00:00
2017-09-03 04:50:31 +00:00
http . Redirect ( w , r , "/panel/themes/" , http . StatusSeeOther )
2017-10-30 09:57:08 +00:00
return nil
2017-04-05 14:15:22 +00:00
}
2017-04-06 17:37:32 +00:00
2018-05-11 05:41:51 +00:00
func routePanelThemesMenus ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
if ! user . Perms . ManageThemes {
return common . NoPermissions ( w , r , user )
}
header . Title = common . GetTitlePhrase ( "panel_themes_menus" )
var menuList [ ] common . PanelMenuListItem
for mid , list := range common . Menus . GetAllMap ( ) {
2018-05-15 05:59:52 +00:00
var name = ""
if mid == 1 {
name = common . GetTmplPhrase ( "panel_themes_menus_main" )
}
2018-05-11 05:41:51 +00:00
menuList = append ( menuList , common . PanelMenuListItem {
2018-05-15 05:59:52 +00:00
Name : name ,
2018-05-11 05:41:51 +00:00
ID : mid ,
ItemCount : len ( list . List ) ,
} )
}
2018-06-06 00:21:22 +00:00
pi := common . PanelMenuListPage { & common . BasePanelPage { header , stats , "themes" , common . ReportForumID } , menuList }
2018-05-11 05:41:51 +00:00
return panelRenderTemplate ( "panel_themes_menus" , w , r , user , & pi )
}
func routePanelThemesMenusEdit ( w http . ResponseWriter , r * http . Request , user common . User , smid string ) common . RouteError {
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
if ! user . Perms . ManageThemes {
return common . NoPermissions ( w , r , user )
}
// TODO: Something like Menu #1 for the title?
header . Title = common . GetTitlePhrase ( "panel_themes_menus_edit" )
2018-05-13 06:56:59 +00:00
header . AddScript ( "Sortable-1.4.0/Sortable.min.js" )
2018-05-11 05:41:51 +00:00
mid , err := strconv . Atoi ( smid )
if err != nil {
return common . LocalError ( "Invalid integer" , w , r , user )
}
menuHold , err := common . Menus . Get ( mid )
if err == ErrNoRows {
return common . NotFound ( w , r , header )
} else if err != nil {
return common . InternalError ( err , w , r )
}
var menuList [ ] common . MenuItem
for _ , item := range menuHold . List {
var menuTmpls = map [ string ] common . MenuTmpl {
item . TmplName : menuHold . Parse ( item . Name , [ ] byte ( "{{.Name}}" ) ) ,
}
var renderBuffer [ ] [ ] byte
var variableIndices [ ] int
renderBuffer , _ = menuHold . ScanItem ( menuTmpls , item , renderBuffer , variableIndices )
var out string
for _ , renderItem := range renderBuffer {
out += string ( renderItem )
}
item . Name = out
if item . Name == "" {
item . Name = "???"
}
menuList = append ( menuList , item )
}
2018-06-06 00:21:22 +00:00
pi := common . PanelMenuPage { & common . BasePanelPage { header , stats , "themes" , common . ReportForumID } , mid , menuList }
2018-05-11 05:41:51 +00:00
return panelRenderTemplate ( "panel_themes_menus_items" , w , r , user , & pi )
}
func routePanelThemesMenuItemEdit ( w http . ResponseWriter , r * http . Request , user common . User , sitemID string ) common . RouteError {
header , stats , ferr := common . PanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
if ! user . Perms . ManageThemes {
return common . NoPermissions ( w , r , user )
}
// TODO: Something like Menu #1 for the title?
header . Title = common . GetTitlePhrase ( "panel_themes_menus_edit" )
itemID , err := strconv . Atoi ( sitemID )
if err != nil {
return common . LocalError ( "Invalid integer" , w , r , user )
}
menuItem , err := common . Menus . ItemStore ( ) . Get ( itemID )
if err == ErrNoRows {
return common . NotFound ( w , r , header )
} else if err != nil {
return common . InternalError ( err , w , r )
}
2018-06-06 00:21:22 +00:00
pi := common . PanelMenuItemPage { & common . BasePanelPage { header , stats , "themes" , common . ReportForumID } , menuItem }
2018-05-11 05:41:51 +00:00
return panelRenderTemplate ( "panel_themes_menus_item_edit" , w , r , user , & pi )
}
2018-05-13 06:56:59 +00:00
func routePanelThemesMenuItemSetters ( r * http . Request , menuItem common . MenuItem ) common . MenuItem {
2018-05-11 05:41:51 +00:00
var getItem = func ( name string ) string {
2018-05-31 06:51:31 +00:00
return common . SanitiseSingleLine ( r . PostFormValue ( "item-" + name ) )
2018-05-11 05:41:51 +00:00
}
menuItem . Name = getItem ( "name" )
menuItem . HTMLID = getItem ( "htmlid" )
menuItem . CSSClass = getItem ( "cssclass" )
menuItem . Position = getItem ( "position" )
if menuItem . Position != "left" && menuItem . Position != "right" {
menuItem . Position = "left"
}
menuItem . Path = getItem ( "path" )
menuItem . Aria = getItem ( "aria" )
menuItem . Tooltip = getItem ( "tooltip" )
menuItem . TmplName = getItem ( "tmplname" )
2018-05-13 06:56:59 +00:00
switch getItem ( "permissions" ) {
2018-05-11 05:41:51 +00:00
case "everyone" :
menuItem . GuestOnly = false
menuItem . MemberOnly = false
menuItem . SuperModOnly = false
menuItem . AdminOnly = false
case "guest-only" :
menuItem . GuestOnly = true
menuItem . MemberOnly = false
menuItem . SuperModOnly = false
menuItem . AdminOnly = false
case "member-only" :
menuItem . GuestOnly = false
menuItem . MemberOnly = true
menuItem . SuperModOnly = false
menuItem . AdminOnly = false
case "supermod-only" :
menuItem . GuestOnly = false
menuItem . MemberOnly = true
menuItem . SuperModOnly = true
menuItem . AdminOnly = false
case "admin-only" :
menuItem . GuestOnly = false
menuItem . MemberOnly = true
menuItem . SuperModOnly = true
menuItem . AdminOnly = true
}
2018-05-13 06:56:59 +00:00
return menuItem
}
func routePanelThemesMenuItemEditSubmit ( w http . ResponseWriter , r * http . Request , user common . User , sitemID string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
isJs := ( r . PostFormValue ( "js" ) == "1" )
if ! user . Perms . ManageThemes {
return common . NoPermissionsJSQ ( w , r , user , isJs )
}
itemID , err := strconv . Atoi ( sitemID )
if err != nil {
return common . LocalErrorJSQ ( "Invalid integer" , w , r , user , isJs )
}
menuItem , err := common . Menus . ItemStore ( ) . Get ( itemID )
if err == ErrNoRows {
return common . LocalErrorJSQ ( "This item doesn't exist." , w , r , user , isJs )
} else if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
//menuItem = menuItem.Copy() // If we switch this for a pointer, we might need this as a scratchpad
menuItem = routePanelThemesMenuItemSetters ( r , menuItem )
2018-05-11 05:41:51 +00:00
err = menuItem . Commit ( )
if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
return panelSuccessRedirect ( "/panel/themes/menus/item/edit/" + strconv . Itoa ( itemID ) , w , r , isJs )
}
2018-05-13 06:56:59 +00:00
func routePanelThemesMenuItemCreateSubmit ( w http . ResponseWriter , r * http . Request , user common . User ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
isJs := ( r . PostFormValue ( "js" ) == "1" )
if ! user . Perms . ManageThemes {
return common . NoPermissionsJSQ ( w , r , user , isJs )
}
smenuID := r . PostFormValue ( "mid" )
if smenuID == "" {
return common . LocalErrorJSQ ( "No menuID provided" , w , r , user , isJs )
}
menuID , err := strconv . Atoi ( smenuID )
if err != nil {
return common . LocalErrorJSQ ( "Invalid integer" , w , r , user , isJs )
}
menuItem := common . MenuItem { MenuID : menuID }
menuItem = routePanelThemesMenuItemSetters ( r , menuItem )
itemID , err := menuItem . Create ( )
if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
return panelSuccessRedirect ( "/panel/themes/menus/item/edit/" + strconv . Itoa ( itemID ) , w , r , isJs )
}
func routePanelThemesMenuItemDeleteSubmit ( w http . ResponseWriter , r * http . Request , user common . User , sitemID string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
isJs := ( r . PostFormValue ( "js" ) == "1" )
if ! user . Perms . ManageThemes {
return common . NoPermissionsJSQ ( w , r , user , isJs )
}
itemID , err := strconv . Atoi ( sitemID )
if err != nil {
return common . LocalErrorJSQ ( "Invalid integer" , w , r , user , isJs )
}
menuItem , err := common . Menus . ItemStore ( ) . Get ( itemID )
if err == ErrNoRows {
return common . LocalErrorJSQ ( "This item doesn't exist." , w , r , user , isJs )
} else if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
//menuItem = menuItem.Copy() // If we switch this for a pointer, we might need this as a scratchpad
err = menuItem . Delete ( )
if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
return panelSuccessRedirect ( "/panel/themes/menus/" , w , r , isJs )
}
func routePanelThemesMenuItemOrderSubmit ( w http . ResponseWriter , r * http . Request , user common . User , smid string ) common . RouteError {
_ , ferr := common . SimplePanelUserCheck ( w , r , & user )
if ferr != nil {
return ferr
}
isJs := ( r . PostFormValue ( "js" ) == "1" )
if ! user . Perms . ManageThemes {
return common . NoPermissionsJSQ ( w , r , user , isJs )
}
mid , err := strconv . Atoi ( smid )
if err != nil {
return common . LocalErrorJSQ ( "Invalid integer" , w , r , user , isJs )
}
menuHold , err := common . Menus . Get ( mid )
if err == ErrNoRows {
return common . LocalErrorJSQ ( "Can't find menu" , w , r , user , isJs )
} else if err != nil {
return common . InternalErrorJSQ ( err , w , r , isJs )
}
sitems := strings . TrimSuffix ( strings . TrimPrefix ( r . PostFormValue ( "items" ) , "{" ) , "}" )
fmt . Printf ( "sitems: %+v\n" , sitems )
var updateMap = make ( map [ int ] int )
for index , smiid := range strings . Split ( sitems , "," ) {
miid , err := strconv . Atoi ( smiid )
if err != nil {
return common . LocalErrorJSQ ( "Invalid integer in menu item list" , w , r , user , isJs )
}
updateMap [ miid ] = index
}
menuHold . UpdateOrder ( updateMap )
return panelSuccessRedirect ( "/panel/themes/menus/edit/" + strconv . Itoa ( mid ) , w , r , isJs )
}