Frontend and Backend Separation & API Route Permission

CabloyJS is a framework of frontend and backend separation. The separation of frontend and backend puts forward higher requirements for permission control of backend API routes. Therefore, the core of permissions is to control the permissions of backend API routes

Relationship between Resource and API Route

The purpose of API route is to provide corresponding API service to the frontend, which is called resource. Therefore, one or more API routes correspond to one resource

In practice, it is for resource authorization, and then specify which resource this route corresponds to in API route, so as to realize access control of API route

For example, the resource of tag management includes the following groups of API routes

a-baseadmin/backend/src/routes.js

  1. 1{
  2. 2 method: 'post',
  3. 3 path: 'tag/add',
  4. 4 controller: 'tag',
  5. 5 meta: { right: { type: 'resource', module: 'a-settings', name: 'settings' } },
  6. 6 },
  7. 7 {
  8. 8 method: 'post',
  9. 9 path: 'tag/save',
  10. 10 controller: 'tag',
  11. 11 meta: { right: { type: 'resource', module: 'a-settings', name: 'settings' } },
  12. 12 },
  13. 13 {
  14. 14 method: 'post',
  15. 15 path: 'tag/delete',
  16. 16 controller: 'tag',
  17. 17 meta: { right: { type: 'resource', module: 'a-settings', name: 'settings' } },
  18. 18 }

Resource Means More

Generally speaking, Resources mainly manage API routes and Menus. In addition, Resources can also manage various authenticable objects, such as sidebar panels and head buttons in the PC layout, widgets in the dashboard, and so on. As a resource management, you can control different roles to use different resources through Resource Authorization

Resource & Atom

Because Atom itself has a lot of basic features, CabloyJS 4.0 implements an atom class: resource, which makes resource easy to use and expand

src/module-system/a-base-sync/backend/src/meta.js

  1. 1const meta = {
  2. 2 base: {
  3. 3 atoms: {
  4. 4 resource: {
  5. 5 info: {
  6. 6 bean: 'resource',
  7. 7 title: 'Resource',
  8. 8 tableName: 'aResource',
  9. 9 tableNameModes: {
  10. 10 },
  11. 11 category: true,
  12. 12 tag: true,
  13. 13 },
  14. 14 },
  15. 15 },
  16. 16 },
  17. 17};

Features

Because the resource itself is an atom class, it has the following features:

1. Support sorting: adjust the display order of resources

2. Support category: the display order of the directory can be adjusted, and the hidden directory can be set

3. Support tag

4. Support static atom: it can provide built-in resources, provide initial authorization, and realize version control

5. Any business module can provide its own resource type, which is automatically included in the unified management structure of resources