Search Apps Documentation Source Content File Folder Download Copy Actions Download

README.md

1.25 Kb ยท 44 lines

Boards2 Permissions

This realm provides a custom gno.land/p/gnoland/boards package Permissions implementation.

This implementation is used by default when creating non open boards, to organize board members, roles and permissions. It uses an underlying DAO to manage users and roles.

The Permissions type also supports optionally setting validation functions to be triggered within WithPermission() method before a permissioned callback is called.

Permissioned call example:

 1import (
 2  "errors"
 3
 4  "gno.land/p/gnoland/boards"
 5
 6  "gno.land/r/gnoland/boards/permissions"
 7)
 8
 9// Define a foo permissions
10const PermissionFoo boards.Permissions = "foo"
11
12// Define a custom foo permission validation function
13validateFoo := func(_ boards.Permissions, args boards.Args) error {
14    if name, ok := args[0].(string); !ok || name != "bar" {
15        return errors.New("unauthorized")
16    }
17    return nil
18}
19
20// Create a permissions instance and assign the custom validator to it
21perms := permissions.New()
22perms.ValidateFunc(PermisionFoo, validateFoo)
23
24// Call a permissioned callback
25args := boards.Args{"bar"}
26user := address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
27perms.WithPermission(cross, user, PermisionFoo, args, func(realm) {
28    println("Hello bar!")
29})