39 lines
918 B
Go
39 lines
918 B
Go
package models
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type Permissions []Permission
|
|
|
|
func (r *Permissions) DefaultPermissions() {
|
|
*r = append(*r,
|
|
Permission{Name: "settings", Permission: 7},
|
|
Permission{Name: "userSettings", Permission: 7},
|
|
Permission{Name: "members", Permission: 7},
|
|
Permission{Name: "events", Permission: 7},
|
|
Permission{Name: "responsible", Permission: 7},
|
|
)
|
|
}
|
|
|
|
// --- Implement driver.Valuer (for saving to DB)
|
|
func (r Permissions) Value() (driver.Value, error) {
|
|
return json.Marshal(r)
|
|
}
|
|
|
|
// --- Implement sql.Scanner (for reading from DB)
|
|
func (r *Permissions) Scan(value any) error {
|
|
bytes, ok := value.([]byte)
|
|
if !ok {
|
|
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
|
}
|
|
return json.Unmarshal(bytes, r)
|
|
}
|
|
|
|
type Permission struct {
|
|
Name string `json:"name"`
|
|
Permission int `json:"permission"`
|
|
}
|