c60118e7c4
Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
114 lines
2.7 KiB
Go
114 lines
2.7 KiB
Go
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
"encoding/json"
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
var blankGroup = Group{ID: 0, Name: ""}
|
|
|
|
type GroupAdmin struct {
|
|
ID int
|
|
Name string
|
|
Rank string
|
|
RankClass string
|
|
CanEdit bool
|
|
CanDelete bool
|
|
}
|
|
|
|
// ! Fix the data races in the fperms
|
|
type Group struct {
|
|
ID int
|
|
Name string
|
|
IsMod bool
|
|
IsAdmin bool
|
|
IsBanned bool
|
|
Tag string
|
|
Perms Perms
|
|
PermissionsText []byte
|
|
PluginPerms map[string]bool // Custom permissions defined by plugins. What if two plugins declare the same permission, but they handle them in incompatible ways? Very unlikely, we probably don't need to worry about this, the plugin authors should be aware of each other to some extent
|
|
PluginPermsText []byte
|
|
CanSee []int // The IDs of the forums this group can see
|
|
UserCount int // ! Might be temporary as I might want to lean on the database instead for this
|
|
}
|
|
|
|
type GroupStmts struct {
|
|
updateGroup *sql.Stmt
|
|
updateGroupRank *sql.Stmt
|
|
updateGroupPerms *sql.Stmt
|
|
}
|
|
|
|
var groupStmts GroupStmts
|
|
|
|
func init() {
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
|
set := func(s string) *sql.Stmt {
|
|
return acc.Update("users_groups").Set(s).Where("gid=?").Prepare()
|
|
}
|
|
groupStmts = GroupStmts{
|
|
updateGroup: set("name=?,tag=?"),
|
|
updateGroupRank: set("is_admin=?,is_mod=?,is_banned=?"),
|
|
updateGroupPerms: set("permissions=?"),
|
|
}
|
|
return acc.FirstError()
|
|
})
|
|
}
|
|
|
|
func (g *Group) ChangeRank(isAdmin, isMod, isBanned bool) (err error) {
|
|
_, err = groupStmts.updateGroupRank.Exec(isAdmin, isMod, isBanned, g.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
Groups.Reload(g.ID)
|
|
return nil
|
|
}
|
|
|
|
func (g *Group) Update(name, tag string) (err error) {
|
|
_, err = groupStmts.updateGroup.Exec(name, tag, g.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
Groups.Reload(g.ID)
|
|
return nil
|
|
}
|
|
|
|
// Please don't pass arbitrary inputs to this method
|
|
func (g *Group) UpdatePerms(perms map[string]bool) (err error) {
|
|
pjson, err := json.Marshal(perms)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_, err = groupStmts.updateGroupPerms.Exec(pjson, g.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return Groups.Reload(g.ID)
|
|
}
|
|
|
|
// Copy gives you a non-pointer concurrency safe copy of the group
|
|
func (g *Group) Copy() Group {
|
|
return *g
|
|
}
|
|
|
|
func (g *Group) CopyPtr() (co *Group) {
|
|
co = new(Group)
|
|
*co = *g
|
|
return co
|
|
}
|
|
|
|
// TODO: Replace this sorting mechanism with something a lot more efficient
|
|
// ? - Use sort.Slice instead?
|
|
type SortGroup []*Group
|
|
|
|
func (sg SortGroup) Len() int {
|
|
return len(sg)
|
|
}
|
|
func (sg SortGroup) Swap(i, j int) {
|
|
sg[i], sg[j] = sg[j], sg[i]
|
|
}
|
|
func (sg SortGroup) Less(i, j int) bool {
|
|
return sg[i].ID < sg[j].ID
|
|
}
|