options.gno
0.71 Kb ยท 30 lines
1package permissions
2
3import (
4 "gno.land/p/gnoland/boards"
5)
6
7// Option configures permissions.
8type Option func(*Permissions)
9
10// UseSingleUserRole configures permissions to only allow one role per user.
11func UseSingleUserRole() Option {
12 return func(p *Permissions) {
13 p.singleUserRole = true
14 }
15}
16
17// WithSuperRole configures permissions to have a super role.
18// A super role is the one that have all permissions.
19// This type of role doesn't need to be mapped to any permission.
20func WithSuperRole(r boards.Role) Option {
21 return func(p *Permissions) {
22 if p.superRole != "" {
23 panic("permissions super role can be assigned only once")
24 }
25
26 name := string(r)
27 p.dao.Members().Grouping().Add(name)
28 p.superRole = r
29 }
30}