permissions.gno
1.61 Kb ยท 55 lines
1package boards
2
3type (
4 // Permission defines the type for permissions.
5 Permission string
6
7 // Role defines the type for user roles.
8 Role string
9
10 // Args is a list of generic arguments.
11 Args []interface{}
12
13 // User contains user info.
14 User struct {
15 Address address
16 Roles []Role
17 }
18
19 // UsersIterFn defines a function type to iterate users.
20 UsersIterFn func(User) bool
21
22 // Permissions define an interface to for permissioned execution.
23 Permissions interface {
24 // HasRole checks if a user has a specific role assigned.
25 HasRole(address, Role) bool
26
27 // HasPermission checks if a user has a specific permission.
28 HasPermission(address, Permission) bool
29
30 // WithPermission calls a callback when a user has a specific permission.
31 // Crossing when calling this method is required to allow implementations
32 // to update their internal state, for example to create proposals that
33 // when approved execute the permissioned callback.
34 // It panics on error.
35 WithPermission(realm, address, Permission, Args, func(realm))
36
37 // SetUserRoles adds a new user when it doesn't exist and sets its roles.
38 // Method can also be called to change the roles of an existing user.
39 // It panics on error.
40 SetUserRoles(realm, address, ...Role)
41
42 // RemoveUser removes a user from the permissioner.
43 // It panics on error.
44 RemoveUser(realm, address) (removed bool)
45
46 // HasUser checks if a user exists.
47 HasUser(address) bool
48
49 // UsersCount returns the total number of users the permissioner contains.
50 UsersCount() int
51
52 // IterateUsers iterates permissions' users.
53 IterateUsers(start, count int, fn UsersIterFn) bool
54 }
55)