Strapi 插件路由默认权限 [英] Strapi Plugin Route Default Permission

查看:72
本文介绍了Strapi 插件路由默认权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为带有多个路由的 Strapi 构建一个插件,例如:

I am building a plugin for Strapi with several routes, for example:

    {
      "method": "GET",
      "path": "/preAnalyzeImportFile",
      "handler": "ImportConfig.preAnalyzeImportFile",
      "config": {
        "policies": ["global.isAuthenticated"]
      }
    }

安装插件后,任何经过身份验证的用户都应该能够使用新路由.我可以手动更改权限以使路由正常工作,但这不应该是使用插件所需的工作流程.

When the plugin is installed, any authenticated user should be able to use the new routes. I can change the permissions manually so that the routes work, but that should not be a required workflow to use the plugin.

如何为插件路由设置默认权限?

How do I set default permissions for plugin routes?

推荐答案

没有关于如何在 Strapi 中执行此操作的文档.

There is no documentation about how to do it in Strapi but.

这里是如何使用permissions 函数来获取、创建、更新权限strapi.plugins['users-permissions'].models.permission.那么如何处理.

Here is how to use permissions function to get, create, update permissions strapi.plugins['users-permissions'].models.permission. So how to deal with.

您必须在 ./config/function/bootstrap.js 中编写代码.每次服务器启动时都会执行此代码.

You will have to write your code in the ./config/function/bootstrap.js. This code is executed every time your server start.

要创建您的权限,您必须找到要更新的角色(类型为 authenticated)strapi.plugins['users-permissions'].models.role.find.

To create your permission you will have to find the role you want to update (with the type authenticated) strapi.plugins['users-permissions'].models.role.find.

当您拥有角色的 id 后,您将使用 strapi.plugins['users-permissions'].models.permission.create

When you have the id of the role you will create a permission with strapi.plugins['users-permissions'].models.permission.create

要发送的对象参数:

  • type:将是您插件的名称
  • controller:将是您的控制器的名称 importconfig 在您的情况下
  • action:函数名称 preanalyzeimportfile 在你的情况下
  • 启用:真
  • role:要应用此策略的角色 ID
  • type: will be the name of your plugin
  • controller: will be the name of your controller importconfig in your case
  • action: the name of the function preanalyzeimportfile in your case
  • enabled: true
  • role: the role id you want to apply this policy

这篇关于Strapi 插件路由默认权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆