# Boards Permissions Extension
This is a `gno.land/p/gnoland/boards/v0` package extension that provides a custom
`Permissions` implementation that uses an underlying `gno.land/p/nt/groups`
group to manage users and roles.
It also supports optionally setting validation functions to be triggered by the
`WithPermission()` method before a callback is called. Validators allows adding
custom checks and requirements before the callback is called.
Usage Example:
[embedmd]:# (example_test.gno go)
```go
package permissions
import (
"errors"
"gno.land/p/gnoland/boards/v0"
)
// Example user account
const user address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
// Define a role
const RoleExample boards.Role = "example"
// Define a permission
const PermissionFoo boards.Permission = 42
func ExamplePermission() {
// Define a custom foo permission validation function
validateFoo := func(_ boards.Permissions, args boards.Args) error {
// Check that the first argument is the string "bob"
if name, ok := args[0].(string); !ok || name != "bob" {
return errors.New("unauthorized")
}
return nil
}
// Create a permissions instance and assign the custom validator to it
perms := New()
perms.ValidateFunc(PermissionFoo, validateFoo)
// Add foo permission to example role
perms.AddRole(RoleExample, PermissionFoo)
// Add a guest user
perms.SetUserRoles(user, RoleExample)
// Call a permissioned callback
args := boards.Args{"bob"}
perms.WithPermission(user, PermissionFoo, args, func() {
println("Hello Bob!")
})
// Output:
// Hello Bob!
}
```
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.