fa065bc584
Change the length of the ticks for referrer tracking. Fixed a bug in Shadow and Tempra Simple where the polls would appear when they shouldn't. Added styling to Shadow for Control Panel Sub-menus. Fixed the ridiculously wide attachment images on Cosora. The analytics pages should no longer be treated as the dashboard style-wise. The installer now works again. Tests now run again, as do the benchmarks. Refactored the topic list logic, and moved the route portion into the routes package. Fixed an inverted comparison in the referrer logic. Added friendly text for Mac operating systems to the english language pack. Removed two obsolete prepared statements. Fixed three race conditions in the database adapters. Potentially sped up the topic page by 20% Added several new benchmarks and refactored the others. Removed a redundant prepared statement in user.go Added reviseID as a primary key to the revisions table. The user_count column was added to the users_groups table, but it's unknown if it will stay.
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package common
|
|
|
|
import "database/sql"
|
|
import "../query_gen/lib"
|
|
|
|
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
|
|
Forums []*ForumPerms
|
|
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 {
|
|
updateGroupRank *sql.Stmt
|
|
}
|
|
|
|
var groupStmts GroupStmts
|
|
|
|
func init() {
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
|
groupStmts = GroupStmts{
|
|
updateGroupRank: acc.Update("users_groups").Set("is_admin = ?, is_mod = ?, is_banned = ?").Where("gid = ?").Prepare(),
|
|
}
|
|
return acc.FirstError()
|
|
})
|
|
}
|
|
|
|
func (group *Group) ChangeRank(isAdmin bool, isMod bool, isBanned bool) (err error) {
|
|
_, err = groupStmts.updateGroupRank.Exec(isAdmin, isMod, isBanned, group.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
Groups.Reload(group.ID)
|
|
return nil
|
|
}
|
|
|
|
// Copy gives you a non-pointer concurrency safe copy of the group
|
|
func (group *Group) Copy() Group {
|
|
return *group
|
|
}
|
|
|
|
// 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
|
|
}
|