Permissions Roles, permissions, and policies for NetPress
NetPressv0.1.7 Permissionsv0.2.3 Docsv0.2.2
Overview Installation Policies Auth Guard
Getting Started

Installation

@admicaa/netpress-permissions is published as a standalone package that depends on @admicaa/netpress as a peer. This page walks through installing it and getting the tables in place.

Requirements

  • Node.js 18 or newer
  • A running NetPress application (@admicaa/netpress >=0.1.6)
  • A configured database connection (SQL or Mongo)

If you have not set up the framework itself yet, start with the core NetPress package and app scaffold first: <https://github.com/admicaa/netpress>

Install The Package

npm install @admicaa/netpress-permissions

The package ships with no runtime dependencies of its own. Knex and Better SQLite are devDependencies used for the test suite only.

Publish The Package Assets

Run the vendor:publish command from your NetPress application:

npm run artisan -- vendor:publish --provider=NetpressPermissionsServiceProvider

This will prompt you to pick a database connection (if you have more than one configured) and will create:

  • config/permissions.js — the application-level configuration
  • database/migrations/*_create_permission_tables.js — the migration
  • app/Providers/PermissionsServiceProvider.js — a thin wrapper you can customise
  • registers the provider automatically in bootstrap/providers.js

If you pick a Mongo connection the generated migration automatically targets that Mongo connection (schema.connection('mongo')).

Run The Migration

npm run migrate

The migration creates five tables (or collections) derived from your config:

  • roles
  • permissions
  • role_has_permissions
  • model_has_roles
  • model_has_permissions

See Migrations for a deeper dive on the schema.

Verify

Fire up a quick REPL or write a minimal test:

import { Role, Permission } from '@admicaa/netpress-permissions';

const editor = await Role.findOrCreate('editor');
const publish = await Permission.findOrCreate('posts.publish');

await editor.givePermissionTo(publish);

If the findOrCreate calls succeed, the package is wired up correctly and you are ready to head to Roles and Permissions.