permissions.gno

2.92 Kb ยท 85 lines
 1package boards2
 2
 3const (
 4	PermissionBoardCreate         Permission = "board:create"
 5	PermissionBoardFlaggingUpdate            = "board:flagging-update"
 6	PermissionBoardFreeze                    = "board:freeze"
 7	PermissionBoardRename                    = "board:rename"
 8	PermissionMemberInvite                   = "member:invite"
 9	PermissionMemberInviteRevoke             = "member:invite-remove"
10	PermissionMemberRemove                   = "member:remove"
11	PermissionPermissionsUpdate              = "permissions:update"
12	PermissionRealmHelp                      = "realm:help"
13	PermissionRealmLock                      = "realm:lock"
14	PermissionRealmNotice                    = "realm:notice"
15	PermissionReplyCreate                    = "reply:create"
16	PermissionReplyDelete                    = "reply:delete"
17	PermissionReplyFlag                      = "reply:flag"
18	PermissionReplyFreeze                    = "reply:freeze"
19	PermissionRoleChange                     = "role:change"
20	PermissionThreadCreate                   = "thread:create"
21	PermissionThreadDelete                   = "thread:delete"
22	PermissionThreadEdit                     = "thread:edit"
23	PermissionThreadFlag                     = "thread:flag"
24	PermissionThreadFreeze                   = "thread:freeze"
25	PermissionThreadRepost                   = "thread:repost"
26	PermissionUserBan                        = "user:ban"
27	PermissionUserUnban                      = "user:unban"
28)
29
30const (
31	RoleGuest     Role = ""
32	RoleOwner          = "owner"
33	RoleAdmin          = "admin"
34	RoleModerator      = "moderator"
35)
36
37type (
38	// Permission defines the type for permissions.
39	Permission string
40
41	// Role defines the type for user roles.
42	Role string
43
44	// Args is a list of generic arguments.
45	Args []interface{}
46
47	// User contains user info.
48	User struct {
49		Address address
50		Roles   []Role
51	}
52
53	// UsersIterFn defines a function type to iterate users.
54	UsersIterFn func(User) bool
55
56	// Permissions define an interface to for permissioned execution.
57	// TODO: Add crossing support to Permissions
58	Permissions interface {
59		// HasRole checks if a user has a specific role assigned.
60		HasRole(address, Role) bool
61
62		// HasPermission checks if a user has a specific permission.
63		HasPermission(address, Permission) bool
64
65		// WithPermission calls a callback when a user has a specific permission.
66		// It panics on error.
67		WithPermission(address, Permission, Args, func(Args))
68
69		// SetUserRoles adds a new user when it doesn't exist and sets its roles.
70		// Method can also be called to change the roles of an existing user.
71		SetUserRoles(address, ...Role) error
72
73		// RemoveUser removes a user from the permissioner.
74		RemoveUser(address) (removed bool)
75
76		// HasUser checks if a user exists.
77		HasUser(address) bool
78
79		// UsersCount returns the total number of users the permissioner contains.
80		UsersCount() int
81
82		// IterateUsers iterates permissions' users.
83		IterateUsers(start, count int, fn UsersIterFn) bool
84	}
85)