Permission update

This commit is contained in:
Eccentric 2024-02-10 00:33:10 +00:00
parent 04fa8f53e1
commit 69e30bf10f
3 changed files with 59 additions and 32 deletions

View File

@ -10,6 +10,7 @@ import (
type CS struct { type CS struct {
Accounts struct { Accounts struct {
Gods []string Gods []string
Owners []string
} }
Database struct { Database struct {
URI string URI string
@ -62,6 +63,7 @@ func LoadConfig(file []byte) {
} }
Config.Accounts.Gods = cfg.Section("accounts").Key("gods").Strings(",") Config.Accounts.Gods = cfg.Section("accounts").Key("gods").Strings(",")
Config.Accounts.Owners = cfg.Section("accounts").Key("owners").Strings(",")
Config.Database.DropAllTables = cfg.Section("database").Key("drop").MustBool(false) Config.Database.DropAllTables = cfg.Section("database").Key("drop").MustBool(false)
Config.Database.URI = cfg.Section("database").Key("uri").String() Config.Database.URI = cfg.Section("database").Key("uri").String()
if Config.Database.URI == "" { if Config.Database.URI == "" {
@ -166,6 +168,6 @@ func LoadConfig(file []byte) {
Config.Fortnite.Season = parsedSeason Config.Fortnite.Season = parsedSeason
Config.Fortnite.Everything = cfg.Section("fortnite").Key("everything").MustBool(false) Config.Fortnite.Everything = cfg.Section("fortnite").Key("everything").MustBool(false)
Config.Fortnite.Password = cfg.Section("fortnite").Key("password").MustBool(false) Config.Fortnite.Password = cfg.Section("fortnite").Key("disable_password").MustBool(false)
Config.Fortnite.DisableClientCredentials = cfg.Section("fortnite").Key("disable_client_credentials").MustBool(false) Config.Fortnite.DisableClientCredentials = cfg.Section("fortnite").Key("disable_client_credentials").MustBool(false)
} }

View File

@ -1,7 +1,5 @@
package person package person
import "github.com/ectrc/snow/aid"
type Permission int64 type Permission int64
// DO NOT MOVE THE ORDER OF THESE PERMISSIONS AS THEY ARE USED IN THE DATABASE // DO NOT MOVE THE ORDER OF THESE PERMISSIONS AS THEY ARE USED IN THE DATABASE
@ -16,33 +14,59 @@ const (
PermissionOwner PermissionOwner
PermissionDonator PermissionDonator
permissionRealAll = 1<<iota - 1 // special permissions
// every permission except owner PermissionAll = PermissionLookup | PermissionBan | PermissionInformation | PermissionItemControl | PermissionLockerControl | PermissionPermissionControl
PermissionAll Permission = permissionRealAll ^ PermissionOwner PermissionAllWithRoles = PermissionAll | PermissionOwner | PermissionDonator
) )
func (p Permission) StringifyMe() string { func (p Permission) GetName() string {
aid.Print(p) if p == 0 {
switch p { return "None"
case PermissionLookup:
return "Lookup"
case PermissionBan:
return "Ban"
case PermissionInformation:
return "Information"
case PermissionItemControl:
return "ItemControl"
case PermissionLockerControl:
return "LockerControl"
case PermissionPermissionControl:
return "PermissionControl"
case PermissionOwner:
return "Owner"
case PermissionDonator:
return "Donator"
case PermissionAll:
return "All"
default:
return "Unknown"
} }
if p == PermissionAll {
return "All"
}
if p == PermissionAllWithRoles {
return "AllWithRoles"
}
if p&PermissionLookup != 0 {
return "Lookup"
}
if p&PermissionBan != 0 {
return "Ban"
}
if p&PermissionInformation != 0 {
return "Information"
}
if p&PermissionItemControl != 0 {
return "ItemControl"
}
if p&PermissionLockerControl != 0 {
return "LockerControl"
}
if p&PermissionPermissionControl != 0 {
return "PermissionControl"
}
if p&PermissionOwner != 0 {
return "Owner"
}
if p&PermissionDonator != 0 {
return "Donator"
}
return "Unknown"
}
func IntToPermission(i int64) Permission {
return Permission(i)
} }

View File

@ -293,9 +293,9 @@ func (p *Person) RemovePermission(permission Permission) {
} }
func (p *Person) HasPermission(permission Permission) bool { func (p *Person) HasPermission(permission Permission) bool {
if permission == PermissionAll { // if permission == PermissionAll && permission != PermissionOwner {
return p.Permissions == PermissionAll // return p.Permissions == PermissionAll
} // }
return p.Permissions & permission != 0 return p.Permissions & permission != 0
} }
@ -406,6 +406,7 @@ func (p *Person) Snapshot() *PersonSnapshot {
func (p *Person) Delete() { func (p *Person) Delete() {
storage.Repo.DeletePerson(p.ID) storage.Repo.DeletePerson(p.ID)
cache.DeletePerson(p.ID)
} }
func (p *Person) SetPurchaseHistoryAttribute() { func (p *Person) SetPurchaseHistoryAttribute() {