strapi-plugin-route-permission

2.0.1 • Public • Published

strapi-plugin-route-permission

🚀   Overview

This plugin implements a simple way to seed strapi permission::users-permissions table from routes configuration. It means that you can define your routes permissions direcly on yours routes.json files. So every time your server ups, it will recreate yours routes permissions from routes.json file, allowing you to migrate your application without worrying about redefine your routes permissions over strapi panel.


  Installation

With npm:

npm install strapi-plugin-route-permission

With yarn:

yarn add strapi-plugin-route-permission

  Getting Started

In many cases, you will lost your database data while your application is in development, but strapi has a tiny problem, for each route action you want to get permission for a role, you need to configure it over strapi panel, and if you reset your database for any reason, every configuration is lost, and after some time, you can forgot about what route needs to target some specific role, broking your logic application and taking your time to reconfigure everything again.

Because this little detail, this plugin implements a simple route config rule, the roles, that can receive the default strapi roles (public, authenticated or both) or any other role that you should want to create. With that, every time yours server startup, it read all your routes and recreate the permissions for target roles on database, keeping your application always updated.

Example:

See the property on routes.*.config.roles parameter.

{
  "routes": [
    {
      "method": "GET",
      "path": "/plans",
      "handler": "plan.find",
      "config": {
        "roles": "authenticated",
        "policies": []
      }
    }
  ]
}

You can also, set more then one role to be target by your route permission:

{
  "routes": [
    {
      "method": "GET",
      "path": "/plans",
      "handler": "plan.find",
      "config": {
        "roles": ["authenticated", "public"],
        "policies": []
      }
    }
  ]
}

Result:

* If the specified role does not exists on database, it will be created automatically.

On strapi startup it reconfigure your permission table

On strapi permission panel, you can see the result applyed for the specified route.


🎉   Congradulations, You're done.

I hope this plugin helps you in your strapi projects and save a lot of time and code.


📜   License

This project is under the MIT license. See the LICENSE for details.


💻   Developed by André Ciornavei - Get in touch!

Package Sidebar

Install

npm i strapi-plugin-route-permission

Weekly Downloads

5

Version

2.0.1

License

MIT

Unpacked Size

86 kB

Total Files

8

Last publish

Collaborators

  • andreciornavei