PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/gnoland/boards/exts/permissions/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
gnoland / boards / exts / permissions
Files
6 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/gnoland/boards/exts/permissions/v0
gno
0.9

Files (6)

  • README.mdmarkdown
  • gnomod.tomltoml
  • options.gnogno
  • permissions.gnogno
  • example_test.gnogno
  • permissions_test.gnogno
README.mdPreviewRaw
# 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!
}
```

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.