options.gno
0.85 Kb · 38 lines
1package permissions
2
3import (
4 "strings"
5
6 "gno.land/p/gnoland/boards/v0"
7)
8
9// Option configures permissions.
10type Option func(*Permissions)
11
12// UseSingleUserRole configures permissions to only allow one role per user.
13func UseSingleUserRole() Option {
14 return func(p *Permissions) {
15 p.singleUserRole = true
16 }
17}
18
19// WithSuperRole configures permissions to have a super role.
20// A super role is the one that have all permissions.
21// This type of role doesn't need to be mapped to any permission.
22func WithSuperRole(r boards.Role) Option {
23 return func(p *Permissions) {
24 if p.superRole != "" {
25 panic("permissions super role can be assigned only once")
26 }
27
28 name := string(r)
29 if strings.TrimSpace(name) == "" {
30 panic("permissions super role name is required")
31 }
32
33 if _, err := p.group.AddRole(name); err != nil {
34 panic(err)
35 }
36 p.superRole = r
37 }
38}