snow/person/permissions.go

76 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-12-14 19:47:54 +00:00
package person
2024-02-09 21:51:26 +00:00
type Permission int64
2023-12-14 19:47:54 +00:00
2024-02-09 21:51:26 +00:00
// DO NOT MOVE THE ORDER OF THESE PERMISSIONS AS THEY ARE USED IN THE DATABASE
2023-12-14 19:47:54 +00:00
const (
2024-02-10 01:55:56 +00:00
// random utility permissions
2024-02-09 21:51:26 +00:00
PermissionLookup Permission = 1 << iota
PermissionInformation
2024-02-10 01:55:56 +00:00
// control permissions
PermissionBansControl
2024-02-09 21:51:26 +00:00
PermissionItemControl
PermissionLockerControl
PermissionPermissionControl
2024-02-10 01:55:56 +00:00
2024-02-09 21:51:26 +00:00
// user roles, not really permissions but implemented as such
PermissionOwner
PermissionDonator
2023-12-14 19:47:54 +00:00
2024-02-10 00:33:10 +00:00
// special permissions
2024-02-10 01:55:56 +00:00
PermissionAll = PermissionLookup | PermissionBansControl | PermissionInformation | PermissionItemControl | PermissionLockerControl | PermissionPermissionControl
2024-02-10 00:33:10 +00:00
PermissionAllWithRoles = PermissionAll | PermissionOwner | PermissionDonator
2024-02-09 23:56:06 +00:00
)
2024-02-10 00:33:10 +00:00
func (p Permission) GetName() string {
if p == 0 {
return "None"
}
if p == PermissionAll {
return "All"
}
if p == PermissionAllWithRoles {
return "AllWithRoles"
}
if p&PermissionLookup != 0 {
2024-02-09 23:56:06 +00:00
return "Lookup"
2024-02-10 00:33:10 +00:00
}
2024-02-10 01:55:56 +00:00
if p&PermissionBansControl != 0 {
2024-02-09 23:56:06 +00:00
return "Ban"
2024-02-10 00:33:10 +00:00
}
if p&PermissionInformation != 0 {
2024-02-09 23:56:06 +00:00
return "Information"
2024-02-10 00:33:10 +00:00
}
if p&PermissionItemControl != 0 {
2024-02-09 23:56:06 +00:00
return "ItemControl"
2024-02-10 00:33:10 +00:00
}
if p&PermissionLockerControl != 0 {
2024-02-09 23:56:06 +00:00
return "LockerControl"
2024-02-10 00:33:10 +00:00
}
if p&PermissionPermissionControl != 0 {
2024-02-09 23:56:06 +00:00
return "PermissionControl"
2024-02-10 00:33:10 +00:00
}
if p&PermissionOwner != 0 {
2024-02-09 23:56:06 +00:00
return "Owner"
2024-02-10 00:33:10 +00:00
}
if p&PermissionDonator != 0 {
2024-02-09 23:56:06 +00:00
return "Donator"
}
2024-02-10 00:33:10 +00:00
return "Unknown"
}
func IntToPermission(i int64) Permission {
return Permission(i)
2024-02-09 23:56:06 +00:00
}