gosora/group.go
Azareal 9b1489b90f Happy 100th commit! For the 100th commit, I've revamped a good portion of the user interface, and we don't plan on stopping! There's more to come!
Each theme has more of a distinct feel in the control panel now. I moved a large portion of the inline CSS into global.css, tweaked some core code which didn't line up, and added CSS text insertions to make things more flexible.

Revamped the alerts interface. We have more changes coming up!
Added screenshots for Tempra Cursive and Tempra Conflux Mobile to the README.
Added a .htaccess file, just in case someone plops Gosora in Apache's /www/ folder to stop the contents of config.go from becoming publically visible. Never put Gosora in your /www/ folder, Gosora is a standalone program which does NOT use Apache or any other webserver.
Fixed a bug in the inline forum editor.
Added a hand-written Markdown parser which is much faster than the previous Regex based one. This is still a work in progress.
Added support for strikethrough and underline elements to the Markdown parser.
Fixed the missing semicolons in global.js
Revamped the form CSS.
Author bits on the theme manager now link to the author's website.
Improved the profiles a little.
The code in the stylesheets now have a more consistent style.
Fixed a bug in the Cosmo theme relating to the fact that Gosora doesn't have sidebars yet.

There are many more changes which aren't listed here.
If weirdness regarding lines or spacing occurs, I'm experimenting with a new text editor. I hope to have this fixed by the next commit.
2017-05-29 15:52:37 +01:00

117 lines
2.5 KiB
Go

package main
import "sync"
import "encoding/json"
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
var group_update_mutex sync.Mutex
type GroupAdmin struct
{
ID int
Name string
Rank string
RankClass string
CanEdit bool
CanDelete bool
}
type Group struct
{
ID int
Name string
Is_Mod bool
Is_Admin bool
Is_Banned bool
Tag string
Perms Perms
PermissionsText []byte
Forums []ForumPerms
CanSee []int // The IDs of the forums this group can see
}
func create_group(group_name string, tag string, is_admin bool, is_mod bool, is_banned bool) (int, error) {
var gid int
err := group_entry_exists_stmt.QueryRow().Scan(&gid)
if err != nil && err != sql.ErrNoRows {
return 0, err
}
if err != sql.ErrNoRows {
group_update_mutex.Lock()
_, err = update_group_rank_stmt.Exec(is_admin, is_mod, is_banned, gid)
if err != nil {
return gid, err
}
_, err = update_group_stmt.Exec(group_name, tag, gid)
if err != nil {
return gid, err
}
groups[gid].Name = group_name
groups[gid].Tag = tag
groups[gid].Is_Banned = is_banned
groups[gid].Is_Mod = is_mod
groups[gid].Is_Admin = is_admin
group_update_mutex.Unlock()
return gid, nil
}
var permstr string = "{}"
res, err := create_group_stmt.Exec(group_name, tag, is_admin, is_mod, is_banned, permstr)
if err != nil {
return 0, err
}
gid64, err := res.LastInsertId()
if err != nil {
return 0, err
}
gid = int(gid64)
perms := BlankPerms
var blankForums []ForumPerms
var blankIntList []int
groups = append(groups, Group{gid,group_name,is_mod,is_admin,is_banned,tag,perms,[]byte(permstr),blankForums,blankIntList})
// Generate the forum permissions based on the presets...
fdata := forums
permupdate_mutex.Lock()
for _, forum := range fdata {
var thePreset string
if is_admin {
thePreset = "admins"
} else if is_mod {
thePreset = "staff"
} else if is_banned {
thePreset = "banned"
} else {
thePreset = "members"
}
permmap := preset_to_permmap(forum.Preset)
permitem := permmap[thePreset]
permitem.Overrides = true
permstr, err := json.Marshal(permitem)
if err != nil {
return gid, err
}
perms := string(permstr)
_, err = add_forum_perms_to_group_stmt.Exec(gid,forum.ID,forum.Preset,perms)
if err != nil {
return gid, err
}
err = rebuild_forum_permissions(forum.ID)
if err != nil {
return gid, err
}
}
permupdate_mutex.Unlock()
return gid, nil
}
func group_exists(gid int) bool {
return (gid <= groupCapCount) && (gid > 0) && groups[gid].Name!=""
}