Draft

Atom has two states: Draft, Normal

The new atom is in the draft state and in the normal state after submission

State Description
Draft only the creator can operate, others can’t see it
Normal Only users with corresponding permissions can operate the corresponding actions. The creator can always view the atoms he has created, but if no permission assigned, the creator cannot even operate the actions of update, delete and other custom actions

Submission of Darft

The atom is submitted from the draft to the normal state, which is realized by the basic API route of the system. The module only needs to provide the business API route for customization

Basic API Route

CabloyJS provides a set of basic API routes, encapsulates atom actions, so that middleware such as database transaction, validator', right` can be configured uniformly

The core module a-base encapsulates the draft logic. The basic API route is as follows:

a-base/backend/src/routes.js

{ method: 'post', path: 'atom/enable', controller: atom },

Business API Route

The module only needs to provide business API route, so as to do some special processing when submit to normal state. For example, the business API route of the module test-party is as follows:

src/suite-vendor/test-party/modules/test-party/backend/src/routes.js

{ method: 'post', path: 'party/enable',
  controller: party, 
  middlewares: 'inner',
  meta: { auth: { enable: false } } 
},

Business Logic Codes

Generally, it is not necessary to add business logic codes for API enable. When the custom actions and atom flags are used, the value of atom flag is generally changed in the api enable, so as to perform the next custom action

src/suite-vendor/test-party/modules/test-party/backend/src/service/party.js

async enable({ atomClass, key, atom, user }) {
  // enable
  const atomFlag = atom.atomEnabled ? 1 : 0;
  // change flag
  await this.ctx.meta.atom.flag({
    key,
    atom: { atomFlag },
    user,
  });
}
Name Description
atomClass object of Atom Class
key the key of atom: { atomId, itemId }
atom object of atom
user object of the current user

Public Access

By default, in the normal state, only users granted the read permission can read the corresponding atoms. CabloyJS provides a simple feature that allows users to directly access atoms without granting permission in a normal state

For example, to realize the function of announcement and set public access, you can bypass the judgment of data permission, so as to improve the performance of data access

There is only one step to enable public access:

src/suite-vendor/test-party/modules/test-party/backend/src/meta.js

base: {
  atoms: {
    partyPublic: {
      info: {
        tableName: 'testPartyPublic',
        public: 1,
      },
    },
  },
},
Name Description
info.public=1 enable public access