permissions.gno
1.68 Kb · 61 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 // It panics on error.
32 //
33 // An inline crossing function call can be used by the implementation if
34 // crossing is required to update its internal state, for example to create
35 // proposals that when approved execute the callback:
36 //
37 // func(realm) {
38 // // Update internal realm state
39 // // ...
40 // }(cross)
41 WithPermission(address, Permission, Args, func())
42
43 // SetUserRoles adds a new user when it doesn't exist and sets its roles.
44 // Method can also be called to change the roles of an existing user.
45 // It panics on error.
46 SetUserRoles(address, ...Role)
47
48 // RemoveUser removes a user from the permissioner.
49 // It panics on error.
50 RemoveUser(address) (removed bool)
51
52 // HasUser checks if a user exists.
53 HasUser(address) bool
54
55 // UsersCount returns the total number of users the permissioner contains.
56 UsersCount() int
57
58 // IterateUsers iterates permissions' users.
59 IterateUsers(start, count int, fn UsersIterFn) bool
60 }
61)