Add better bans system + start purchase history

This commit is contained in:
Eccentric 2024-02-04 10:56:21 +00:00
parent 65ec590538
commit 09f7d2b891
3 changed files with 45 additions and 13 deletions

View File

@ -14,13 +14,22 @@ import (
func GetLightswitchBulkStatus(c *fiber.Ctx) error { func GetLightswitchBulkStatus(c *fiber.Ctx) error {
person := c.Locals("person").(*person.Person) person := c.Locals("person").(*person.Person)
isBanned := false
for _, ban := range person.BanHistory {
expres := time.Unix(ban.Expiry, 0)
if time.Now().Before(expres) {
isBanned = true
break
}
}
return c.Status(fiber.StatusOK).JSON([]aid.JSON{{ return c.Status(fiber.StatusOK).JSON([]aid.JSON{{
"serviceInstanceId": "fortnite", "serviceInstanceId": "fortnite",
"status" :"UP", "status" :"UP",
"message": "fortnite is up.", "message": "fortnite is up.",
"maintenanceUri": nil, "maintenanceUri": nil,
"allowedActions": []string{"PLAY","DOWNLOAD"}, "allowedActions": []string{"PLAY","DOWNLOAD"},
"banned": person.IsBanned, "banned": isBanned,
"launcherInfoDTO": aid.JSON{ "launcherInfoDTO": aid.JSON{
"appName":"Fortnite", "appName":"Fortnite",
"catalogItemId":"4fe75bbc5a674f4f9b356b5c90567da5", "catalogItemId":"4fe75bbc5a674f4f9b356b5c90567da5",

View File

@ -1,6 +1,8 @@
package person package person
import ( import (
"time"
"github.com/ectrc/snow/aid" "github.com/ectrc/snow/aid"
"github.com/ectrc/snow/storage" "github.com/ectrc/snow/storage"
"github.com/google/uuid" "github.com/google/uuid"
@ -10,7 +12,6 @@ type Person struct {
ID string ID string
DisplayName string DisplayName string
Permissions []string Permissions []string
IsBanned bool
AthenaProfile *Profile AthenaProfile *Profile
CommonCoreProfile *Profile CommonCoreProfile *Profile
CommonPublicProfile *Profile CommonPublicProfile *Profile
@ -18,6 +19,7 @@ type Person struct {
CollectionsProfile *Profile CollectionsProfile *Profile
CreativeProfile *Profile CreativeProfile *Profile
Discord *storage.DB_DiscordPerson Discord *storage.DB_DiscordPerson
BanHistory []storage.DB_BanStatus
Relationships aid.GenericSyncMap[Relationship] Relationships aid.GenericSyncMap[Relationship]
} }
@ -26,7 +28,6 @@ func NewPerson() *Person {
ID: uuid.New().String(), ID: uuid.New().String(),
DisplayName: uuid.New().String(), DisplayName: uuid.New().String(),
Permissions: []string{}, Permissions: []string{},
IsBanned: false,
AthenaProfile: NewProfile("athena"), AthenaProfile: NewProfile("athena"),
CommonCoreProfile: NewProfile("common_core"), CommonCoreProfile: NewProfile("common_core"),
CommonPublicProfile: NewProfile("common_public"), CommonPublicProfile: NewProfile("common_public"),
@ -41,7 +42,6 @@ func NewPersonWithCustomID(id string) *Person {
ID: id, ID: id,
DisplayName: uuid.New().String(), DisplayName: uuid.New().String(),
Permissions: []string{}, Permissions: []string{},
IsBanned: false,
AthenaProfile: NewProfile("athena"), AthenaProfile: NewProfile("athena"),
CommonCoreProfile: NewProfile("common_core"), CommonCoreProfile: NewProfile("common_core"),
CommonPublicProfile: NewProfile("common_public"), CommonPublicProfile: NewProfile("common_public"),
@ -185,7 +185,7 @@ func findHelper(databasePerson *storage.DB_Person, shallow bool, save bool) *Per
ID: databasePerson.ID, ID: databasePerson.ID,
DisplayName: databasePerson.DisplayName, DisplayName: databasePerson.DisplayName,
Permissions: databasePerson.Permissions, Permissions: databasePerson.Permissions,
IsBanned: databasePerson.IsBanned, BanHistory: databasePerson.BanHistory,
AthenaProfile: athenaProfile, AthenaProfile: athenaProfile,
CommonCoreProfile: commonCoreProfile, CommonCoreProfile: commonCoreProfile,
CommonPublicProfile: commonPublicProfile, CommonPublicProfile: commonPublicProfile,
@ -259,12 +259,22 @@ func (p *Person) SaveShallow() {
} }
func (p *Person) Ban() { func (p *Person) Ban() {
p.IsBanned = true p.BanHistory = append(p.BanHistory, storage.DB_BanStatus{
ID: uuid.New().String(),
PersonID: p.ID,
IssuedBy: "system",
Reason: "Banned by system",
Expiry: time.Now().AddDate(0, 0, 7).Unix(),
})
p.SaveShallow() p.SaveShallow()
} }
func (p *Person) Unban() { func (p *Person) Unban() {
p.IsBanned = false for _, ban := range p.BanHistory {
ban.Expiry = time.Now().Unix()
}
p.SaveShallow() p.SaveShallow()
} }
@ -302,7 +312,7 @@ func (p *Person) ToDatabase() *storage.DB_Person {
ID: p.ID, ID: p.ID,
DisplayName: p.DisplayName, DisplayName: p.DisplayName,
Permissions: p.Permissions, Permissions: p.Permissions,
IsBanned: p.IsBanned, BanHistory: p.BanHistory,
Profiles: []storage.DB_Profile{}, Profiles: []storage.DB_Profile{},
Stats: []storage.DB_SeasonStat{}, Stats: []storage.DB_SeasonStat{},
Discord: storage.DB_DiscordPerson{}, Discord: storage.DB_DiscordPerson{},
@ -370,7 +380,7 @@ func (p *Person) ToDatabaseShallow() *storage.DB_Person {
ID: p.ID, ID: p.ID,
DisplayName: p.DisplayName, DisplayName: p.DisplayName,
Permissions: p.Permissions, Permissions: p.Permissions,
IsBanned: p.IsBanned, BanHistory: p.BanHistory,
Profiles: []storage.DB_Profile{}, Profiles: []storage.DB_Profile{},
Stats: []storage.DB_SeasonStat{}, Stats: []storage.DB_SeasonStat{},
Discord: storage.DB_DiscordPerson{}, Discord: storage.DB_DiscordPerson{},
@ -401,13 +411,13 @@ func (p *Person) Snapshot() *PersonSnapshot {
ID: p.ID, ID: p.ID,
DisplayName: p.DisplayName, DisplayName: p.DisplayName,
Permissions: p.Permissions, Permissions: p.Permissions,
IsBanned: p.IsBanned,
AthenaProfile: *p.AthenaProfile.Snapshot(), AthenaProfile: *p.AthenaProfile.Snapshot(),
CommonCoreProfile: *p.CommonCoreProfile.Snapshot(), CommonCoreProfile: *p.CommonCoreProfile.Snapshot(),
CommonPublicProfile: *p.CommonPublicProfile.Snapshot(), CommonPublicProfile: *p.CommonPublicProfile.Snapshot(),
Profile0Profile: *p.Profile0Profile.Snapshot(), Profile0Profile: *p.Profile0Profile.Snapshot(),
CollectionsProfile: *p.CollectionsProfile.Snapshot(), CollectionsProfile: *p.CollectionsProfile.Snapshot(),
CreativeProfile: *p.CreativeProfile.Snapshot(), CreativeProfile: *p.CreativeProfile.Snapshot(),
BanHistory: p.BanHistory,
Discord: *p.Discord, Discord: *p.Discord,
} }
} }

View File

@ -10,10 +10,11 @@ type DB_Person struct {
ID string ID string
DisplayName string DisplayName string
Permissions pq.StringArray `gorm:"type:text[]"` Permissions pq.StringArray `gorm:"type:text[]"`
IsBanned bool
Profiles []DB_Profile `gorm:"foreignkey:PersonID"` Profiles []DB_Profile `gorm:"foreignkey:PersonID"`
Stats []DB_SeasonStat `gorm:"foreignkey:PersonID"` Stats []DB_SeasonStat `gorm:"foreignkey:PersonID"`
Purchases []DB_Purchase `gorm:"foreignkey:ProfileID"`
Discord DB_DiscordPerson `gorm:"foreignkey:PersonID"` Discord DB_DiscordPerson `gorm:"foreignkey:PersonID"`
BanHistory []DB_BanStatus `gorm:"foreignkey:PersonID"`
} }
func (DB_Person) TableName() string { func (DB_Person) TableName() string {
@ -102,8 +103,8 @@ type DB_Purchase struct {
PurchaseDate int64 PurchaseDate int64
FreeRefundExpiry int64 FreeRefundExpiry int64
RefundExpiry int64 RefundExpiry int64
Refundable bool RefundedAt int64
Refunded bool TotalPaid int
} }
func (DB_Purchase) TableName() string { func (DB_Purchase) TableName() string {
@ -203,3 +204,15 @@ type DB_SeasonStat struct {
func (DB_SeasonStat) TableName() string { func (DB_SeasonStat) TableName() string {
return "Stats" return "Stats"
} }
type DB_BanStatus struct {
ID string `gorm:"primary_key"`
PersonID string `gorm:"index"`
IssuedBy string
Expiry int64
Reason string
}
func (DB_BanStatus) TableName() string {
return "Bans"
}