2017-09-15 22:20:01 +00:00
|
|
|
/* Under Heavy Construction */
|
2017-11-10 03:43:38 +00:00
|
|
|
package common
|
2017-09-13 15:09:13 +00:00
|
|
|
|
2017-09-15 22:20:01 +00:00
|
|
|
import (
|
2017-11-02 13:35:19 +00:00
|
|
|
"database/sql"
|
2017-09-15 22:20:01 +00:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"log"
|
2017-11-02 13:35:19 +00:00
|
|
|
"sort"
|
2019-06-18 04:13:47 +00:00
|
|
|
"strconv"
|
2020-02-05 02:48:35 +00:00
|
|
|
"sync"
|
2017-10-21 00:27:47 +00:00
|
|
|
|
2020-02-05 02:48:35 +00:00
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
2017-09-15 22:20:01 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 05:37:08 +00:00
|
|
|
var Groups GroupStore
|
2017-09-15 22:20:01 +00:00
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
// ? - We could fallback onto the database when an item can't be found in the cache?
|
2017-09-15 22:20:01 +00:00
|
|
|
type GroupStore interface {
|
|
|
|
LoadGroups() error
|
|
|
|
DirtyGet(id int) *Group
|
|
|
|
Get(id int) (*Group, error)
|
|
|
|
GetCopy(id int) (Group, error)
|
|
|
|
Exists(id int) bool
|
2020-02-05 02:48:35 +00:00
|
|
|
Create(name, tag string, isAdmin, isMod, isBanned bool) (id int, err error)
|
2017-09-15 22:20:01 +00:00
|
|
|
GetAll() ([]*Group, error)
|
2020-02-05 02:48:35 +00:00
|
|
|
GetRange(lower, higher int) ([]*Group, error)
|
2017-11-02 13:35:19 +00:00
|
|
|
Reload(id int) error // ? - Should we move this to GroupCache? It might require us to do some unnecessary casting though
|
2019-06-01 12:31:48 +00:00
|
|
|
Count() int
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
type GroupCache interface {
|
2020-02-05 02:48:35 +00:00
|
|
|
CacheSet(g *Group) error
|
2019-06-19 03:16:03 +00:00
|
|
|
SetCanSee(gid int, canSee []int) error
|
2021-03-22 09:58:13 +00:00
|
|
|
CacheAdd(g *Group) error
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
Length() int
|
|
|
|
}
|
|
|
|
|
2017-09-15 22:20:01 +00:00
|
|
|
type MemoryGroupStore struct {
|
2017-11-02 13:35:19 +00:00
|
|
|
groups map[int]*Group // TODO: Use a sync.Map instead of a map?
|
|
|
|
groupCount int
|
2017-11-06 04:02:35 +00:00
|
|
|
getAll *sql.Stmt
|
2017-11-02 13:35:19 +00:00
|
|
|
get *sql.Stmt
|
2017-11-11 04:06:16 +00:00
|
|
|
count *sql.Stmt
|
2018-02-10 15:07:21 +00:00
|
|
|
userCount *sql.Stmt
|
2017-11-02 13:35:19 +00:00
|
|
|
|
|
|
|
sync.RWMutex
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
func NewMemoryGroupStore() (*MemoryGroupStore, error) {
|
2018-08-04 11:46:36 +00:00
|
|
|
acc := qgen.NewAcc()
|
2019-12-07 06:27:01 +00:00
|
|
|
ug := "users_groups"
|
2017-11-02 13:35:19 +00:00
|
|
|
return &MemoryGroupStore{
|
|
|
|
groups: make(map[int]*Group),
|
|
|
|
groupCount: 0,
|
2020-02-05 02:48:35 +00:00
|
|
|
getAll: acc.Select(ug).Columns("gid,name,permissions,plugin_perms,is_mod,is_admin,is_banned,tag").Prepare(),
|
|
|
|
get: acc.Select(ug).Columns("name,permissions,plugin_perms,is_mod,is_admin,is_banned,tag").Where("gid=?").Prepare(),
|
2019-12-07 06:27:01 +00:00
|
|
|
count: acc.Count(ug).Prepare(),
|
2020-02-05 02:48:35 +00:00
|
|
|
userCount: acc.Count("users").Where("group=?").Prepare(),
|
2017-11-06 07:23:32 +00:00
|
|
|
}, acc.FirstError()
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 09:55:34 +00:00
|
|
|
// TODO: Move this query from the global stmt store into this store
|
2019-07-28 23:19:46 +00:00
|
|
|
func (s *MemoryGroupStore) LoadGroups() error {
|
|
|
|
s.Lock()
|
|
|
|
defer s.Unlock()
|
|
|
|
s.groups[0] = &Group{ID: 0, Name: "Unknown"}
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
rows, err := s.getAll.Query()
|
2017-09-15 22:20:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
i := 1
|
|
|
|
for ; rows.Next(); i++ {
|
2019-07-28 23:19:46 +00:00
|
|
|
g := &Group{ID: 0}
|
|
|
|
err := rows.Scan(&g.ID, &g.Name, &g.PermissionsText, &g.PluginPermsText, &g.IsMod, &g.IsAdmin, &g.IsBanned, &g.Tag)
|
2017-09-15 22:20:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
err = s.initGroup(g)
|
2017-09-15 22:20:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-28 23:19:46 +00:00
|
|
|
s.groups[g.ID] = g
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
2021-03-22 09:58:13 +00:00
|
|
|
if err = rows.Err(); err != nil {
|
2017-09-15 22:20:01 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-07-28 23:19:46 +00:00
|
|
|
s.groupCount = i
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2018-02-19 04:26:01 +00:00
|
|
|
DebugLog("Binding the Not Loggedin Group")
|
2019-10-29 22:13:45 +00:00
|
|
|
GuestPerms = s.dirtyGetUnsafe(6).Perms // ! Race?
|
2018-11-19 23:06:15 +00:00
|
|
|
TopicListThaw.Thaw()
|
2017-09-15 22:20:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
// TODO: Hit the database when the item isn't in memory
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) dirtyGetUnsafe(id int) *Group {
|
|
|
|
group, ok := s.groups[id]
|
2017-11-02 13:35:19 +00:00
|
|
|
if !ok {
|
|
|
|
return &blankGroup
|
|
|
|
}
|
|
|
|
return group
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Hit the database when the item isn't in memory
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) DirtyGet(id int) *Group {
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RLock()
|
2020-02-05 02:48:35 +00:00
|
|
|
group, ok := s.groups[id]
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
if !ok {
|
2017-09-15 22:20:01 +00:00
|
|
|
return &blankGroup
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
return group
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
// TODO: Hit the database when the item isn't in memory
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) Get(id int) (*Group, error) {
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RLock()
|
2020-02-05 02:48:35 +00:00
|
|
|
group, ok := s.groups[id]
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
if !ok {
|
2017-09-15 22:20:01 +00:00
|
|
|
return nil, ErrNoRows
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
return group, nil
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
// TODO: Hit the database when the item isn't in memory
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) GetCopy(id int) (Group, error) {
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RLock()
|
2020-02-05 02:48:35 +00:00
|
|
|
group, ok := s.groups[id]
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
if !ok {
|
2017-09-15 22:20:01 +00:00
|
|
|
return blankGroup, ErrNoRows
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
return *group, nil
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 04:13:47 +00:00
|
|
|
func (s *MemoryGroupStore) Reload(id int) error {
|
|
|
|
// TODO: Reload this data too
|
2021-04-07 14:23:11 +00:00
|
|
|
g, e := s.Get(id)
|
|
|
|
if e != nil {
|
2019-06-18 04:13:47 +00:00
|
|
|
LogError(errors.New("can't get cansee data for group #" + strconv.Itoa(id)))
|
|
|
|
return nil
|
|
|
|
}
|
2019-07-28 23:19:46 +00:00
|
|
|
canSee := g.CanSee
|
2020-02-05 02:48:35 +00:00
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
g = &Group{ID: id, CanSee: canSee}
|
2021-04-07 14:23:11 +00:00
|
|
|
e = s.get.QueryRow(id).Scan(&g.Name, &g.PermissionsText, &g.PluginPermsText, &g.IsMod, &g.IsAdmin, &g.IsBanned, &g.Tag)
|
|
|
|
if e != nil {
|
|
|
|
return e
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
2021-04-07 14:23:11 +00:00
|
|
|
if e = s.initGroup(g); e != nil {
|
|
|
|
LogError(e)
|
2019-06-18 04:13:47 +00:00
|
|
|
return nil
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
2020-02-05 02:48:35 +00:00
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
s.CacheSet(g)
|
2018-11-19 23:06:15 +00:00
|
|
|
TopicListThaw.Thaw()
|
2017-11-02 13:35:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:13:45 +00:00
|
|
|
func (s *MemoryGroupStore) initGroup(g *Group) error {
|
2021-04-07 14:23:11 +00:00
|
|
|
e := json.Unmarshal(g.PermissionsText, &g.Perms)
|
|
|
|
if e != nil {
|
|
|
|
log.Printf("g: %+v\n", g)
|
2019-10-29 22:13:45 +00:00
|
|
|
log.Print("bad group perms: ", g.PermissionsText)
|
2021-04-07 14:23:11 +00:00
|
|
|
return e
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
2019-10-29 22:13:45 +00:00
|
|
|
DebugLogf(g.Name+": %+v\n", g.Perms)
|
2017-11-02 13:35:19 +00:00
|
|
|
|
2021-04-07 14:23:11 +00:00
|
|
|
e = json.Unmarshal(g.PluginPermsText, &g.PluginPerms)
|
|
|
|
if e != nil {
|
|
|
|
log.Printf("g: %+v\n", g)
|
2019-10-29 22:13:45 +00:00
|
|
|
log.Print("bad group plugin perms: ", g.PluginPermsText)
|
2021-04-07 14:23:11 +00:00
|
|
|
return e
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
2019-10-29 22:13:45 +00:00
|
|
|
DebugLogf(g.Name+": %+v\n", g.PluginPerms)
|
2017-11-05 01:04:57 +00:00
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
//group.Perms.ExtData = make(map[string]bool)
|
|
|
|
// TODO: Can we optimise the bit where this cascades down to the user now?
|
2019-10-29 22:13:45 +00:00
|
|
|
if g.IsAdmin || g.IsMod {
|
|
|
|
g.IsBanned = false
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
2018-02-10 15:07:21 +00:00
|
|
|
|
2021-04-07 14:23:11 +00:00
|
|
|
e = s.userCount.QueryRow(g.ID).Scan(&g.UserCount)
|
|
|
|
if e != sql.ErrNoRows {
|
|
|
|
return e
|
2018-02-10 15:07:21 +00:00
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-19 03:16:03 +00:00
|
|
|
func (s *MemoryGroupStore) SetCanSee(gid int, canSee []int) error {
|
|
|
|
s.Lock()
|
|
|
|
group, ok := s.groups[gid]
|
|
|
|
if !ok {
|
|
|
|
s.Unlock()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ngroup := &Group{}
|
|
|
|
*ngroup = *group
|
|
|
|
ngroup.CanSee = canSee
|
|
|
|
s.groups[group.ID] = ngroup
|
|
|
|
s.Unlock()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:13:45 +00:00
|
|
|
func (s *MemoryGroupStore) CacheSet(g *Group) error {
|
2019-06-18 04:13:47 +00:00
|
|
|
s.Lock()
|
2019-10-29 22:13:45 +00:00
|
|
|
s.groups[g.ID] = g
|
2019-06-18 04:13:47 +00:00
|
|
|
s.Unlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Hit the database when the item isn't in memory
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) Exists(id int) bool {
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RLock()
|
2020-02-05 02:48:35 +00:00
|
|
|
group, ok := s.groups[id]
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
return ok && group.Name != ""
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-21 00:27:47 +00:00
|
|
|
// ? Allow two groups with the same name?
|
2017-11-13 05:22:37 +00:00
|
|
|
// TODO: Refactor this
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) Create(name, tag string, isAdmin, isMod, isBanned bool) (gid int, err error) {
|
2019-07-28 23:19:46 +00:00
|
|
|
permstr := "{}"
|
2017-11-11 04:06:16 +00:00
|
|
|
tx, err := qgen.Builder.Begin()
|
2017-10-21 00:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2019-10-29 22:13:45 +00:00
|
|
|
insertTx, err := qgen.Builder.SimpleInsertTx(tx, "users_groups", "name,tag,is_admin,is_mod,is_banned,permissions,plugin_perms", "?,?,?,?,?,?,'{}'")
|
2017-10-21 00:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
res, err := insertTx.Exec(name, tag, isAdmin, isMod, isBanned, permstr)
|
2017-09-15 22:20:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
gid64, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
gid = int(gid64)
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
perms := BlankPerms
|
|
|
|
blankIntList := []int{}
|
|
|
|
pluginPerms := make(map[string]bool)
|
|
|
|
pluginPermsBytes := []byte("{}")
|
2018-10-21 13:54:32 +00:00
|
|
|
GetHookTable().Vhook("create_group_preappend", &pluginPerms, &pluginPermsBytes)
|
2017-09-15 22:20:01 +00:00
|
|
|
|
|
|
|
// Generate the forum permissions based on the presets...
|
2021-03-22 09:58:13 +00:00
|
|
|
forums, err := Forums.GetAll()
|
2017-09-15 22:20:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
presetSet := make(map[int]string)
|
|
|
|
permSet := make(map[int]*ForumPerms)
|
2021-03-22 09:58:13 +00:00
|
|
|
for _, f := range forums {
|
2017-09-15 22:20:01 +00:00
|
|
|
var thePreset string
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
|
|
|
case isAdmin:
|
2017-09-15 22:20:01 +00:00
|
|
|
thePreset = "admins"
|
2017-11-13 05:22:37 +00:00
|
|
|
case isMod:
|
2017-09-15 22:20:01 +00:00
|
|
|
thePreset = "staff"
|
2017-11-13 05:22:37 +00:00
|
|
|
case isBanned:
|
2017-09-15 22:20:01 +00:00
|
|
|
thePreset = "banned"
|
2017-11-13 05:22:37 +00:00
|
|
|
default:
|
2017-09-15 22:20:01 +00:00
|
|
|
thePreset = "members"
|
|
|
|
}
|
|
|
|
|
2021-03-22 09:58:13 +00:00
|
|
|
permmap := PresetToPermmap(f.Preset)
|
2017-10-21 00:27:47 +00:00
|
|
|
permItem := permmap[thePreset]
|
|
|
|
permItem.Overrides = true
|
|
|
|
|
2021-03-22 09:58:13 +00:00
|
|
|
permSet[f.ID] = permItem
|
|
|
|
presetSet[f.ID] = f.Preset
|
2017-10-21 00:27:47 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:06:16 +00:00
|
|
|
err = ReplaceForumPermsForGroupTx(tx, gid, presetSet, permSet)
|
2017-10-21 00:27:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
err = tx.Commit()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Can we optimise the bit where this cascades down to the user now?
|
|
|
|
if isAdmin || isMod {
|
|
|
|
isBanned = false
|
|
|
|
}
|
|
|
|
|
2021-03-22 09:58:13 +00:00
|
|
|
s.CacheAdd(&Group{gid, name, isMod, isAdmin, isBanned, tag, perms, []byte(permstr), pluginPerms, pluginPermsBytes, blankIntList, 0})
|
2017-09-15 22:20:01 +00:00
|
|
|
|
2018-11-19 23:06:15 +00:00
|
|
|
TopicListThaw.Thaw()
|
2018-11-17 02:36:02 +00:00
|
|
|
return gid, FPStore.ReloadAll()
|
|
|
|
//return gid, TopicList.RebuildPermTree()
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 09:58:13 +00:00
|
|
|
func (s *MemoryGroupStore) CacheAdd(g *Group) error {
|
|
|
|
s.Lock()
|
|
|
|
s.groups[g.ID] = g
|
|
|
|
s.groupCount++
|
|
|
|
s.Unlock()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-18 04:13:47 +00:00
|
|
|
func (s *MemoryGroupStore) GetAll() (results []*Group, err error) {
|
2017-11-02 13:35:19 +00:00
|
|
|
var i int
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RLock()
|
|
|
|
results = make([]*Group, len(s.groups))
|
|
|
|
for _, group := range s.groups {
|
2017-11-02 13:35:19 +00:00
|
|
|
results[i] = group
|
|
|
|
i++
|
|
|
|
}
|
2019-06-18 04:13:47 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
sort.Sort(SortGroup(results))
|
|
|
|
return results, nil
|
|
|
|
}
|
|
|
|
|
2019-06-18 04:13:47 +00:00
|
|
|
func (s *MemoryGroupStore) GetAllMap() (map[int]*Group, error) {
|
|
|
|
s.RLock()
|
|
|
|
defer s.RUnlock()
|
|
|
|
return s.groups, nil
|
2017-09-15 22:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ? - Set the lower and higher numbers to 0 to remove the bounds
|
2017-11-02 13:35:19 +00:00
|
|
|
// TODO: Might be a little slow right now, maybe we can cache the groups in a slice or break the map up into chunks
|
2020-02-05 02:48:35 +00:00
|
|
|
func (s *MemoryGroupStore) GetRange(lower, higher int) (groups []*Group, err error) {
|
2017-09-15 22:20:01 +00:00
|
|
|
if lower == 0 && higher == 0 {
|
2019-07-28 23:19:46 +00:00
|
|
|
return s.GetAll()
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 09:36:35 +00:00
|
|
|
// TODO: Simplify these four conditionals into two
|
2017-11-02 13:35:19 +00:00
|
|
|
if lower == 0 {
|
2017-09-15 22:20:01 +00:00
|
|
|
if higher < 0 {
|
|
|
|
return nil, errors.New("higher may not be lower than 0")
|
|
|
|
}
|
|
|
|
} else if higher == 0 {
|
|
|
|
if lower < 0 {
|
|
|
|
return nil, errors.New("lower may not be lower than 0")
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
|
2019-07-28 23:19:46 +00:00
|
|
|
s.RLock()
|
|
|
|
for gid, group := range s.groups {
|
2017-11-02 13:35:19 +00:00
|
|
|
if gid >= lower && (gid <= higher || higher == 0) {
|
|
|
|
groups = append(groups, group)
|
|
|
|
}
|
|
|
|
}
|
2019-07-28 23:19:46 +00:00
|
|
|
s.RUnlock()
|
2017-11-02 13:35:19 +00:00
|
|
|
sort.Sort(SortGroup(groups))
|
|
|
|
|
2017-09-15 22:20:01 +00:00
|
|
|
return groups, nil
|
|
|
|
}
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *MemoryGroupStore) Length() int {
|
|
|
|
s.RLock()
|
|
|
|
defer s.RUnlock()
|
|
|
|
return s.groupCount
|
2017-11-02 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 12:31:48 +00:00
|
|
|
func (s *MemoryGroupStore) Count() (count int) {
|
|
|
|
err := s.count.QueryRow().Scan(&count)
|
2017-11-11 04:06:16 +00:00
|
|
|
if err != nil {
|
|
|
|
LogError(err)
|
|
|
|
}
|
|
|
|
return count
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
}
|