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-09 21:51:26 +00:00
|
|
|
PermissionLookup Permission = 1 << iota
|
|
|
|
PermissionBan
|
|
|
|
PermissionInformation
|
|
|
|
PermissionItemControl
|
|
|
|
PermissionLockerControl
|
|
|
|
PermissionPermissionControl
|
|
|
|
// 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
|
|
|
|
PermissionAll = PermissionLookup | PermissionBan | PermissionInformation | PermissionItemControl | PermissionLockerControl | PermissionPermissionControl
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if p&PermissionBan != 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
|
|
|
}
|