Meaning of Atom Flags

Two scenarios can be used to illustrate the meaning of Atom Flags

Do not use atom flags

Define a scenario requirement. The workflow and permissions are as follows:

  1. Create a new atom of party, which is in the draft state
  2. After submitted, this atom is in the normal state
  3. In the normal state, users granted the read permission can view this atom
  4. In the normal state, users granted the print permission can print this atom

For the custom action print, there is no need to set atom flag

Use atom flags

Add a new task to the scenario requirements defined earlier:

When the atom is in the normal state, it needs to be reviewed before print is allowed

  1. Create a new atom of party, which is in the draft state
  2. After submitted, this atom is in the normal state, and set atom flag=1
  3. When atom flag=1, users granted the review permission can review this atom
  4. After reviewed, set atom flag=2
  5. When atom flag=2, users granted the print permission can print this atom
Name Description
atom flag=1 waiting for review
atom flag=2 has been reviewed

Characteristics of Atom Flag

  1. Atom action is associated with atom flag
  2. If atom action not specified atom flag: in the normal state, users granted any action permission can perform the corresponding action on this atom
  3. If atom action specified atom flag: in the normal state, obtain the atom actions corresponding to the current atom flag, and then judge whether users has permission to perform these atom actions
  4. Atom action can be associated with multiple atom flags

Definition of Atom Flags

For example, the atom actions and atom flags in the module test-party are as follows:

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

const meta = {
  base: {
    atoms: {
      party: {
        actions: {
          review: {
            code: 101,
            title: 'Review',
            flag: '1',
          },
        },
        flags: {
          1: {
            title: 'Reviewing',
          },
          2: {
            title: 'Reviewed',
          },
        },
      },
    },
  },
};
Name Description
review.code custom action’s code, started from 101
review.title custom action’s title
review.flag review will valid when flag=1. supporting multiple flags
flags definition of flags

Simple Workflow

The coordination of atom flags and atom actions can realize a simple workflow, but there is another detail to be dealt with:

In the previous scenario 2, when an atom is submitted to the normal state, it needs to be review. But at this time, whether users granted the read permission can be allowed to read this atom?

  • By enable the simple workflow, we can ensure that only after the action review is completed(meaning the workflow is done), can the atom be read by the users with the read permission

Definition of Simple Workflow

By default, the simple workflow is not enabled. Definition of simple workflow is as folows:

src/module/test-party/backend/src/meta.js

base: {
  atoms: {
    party: {
      info: {
        title: 'Party',
        tableName: 'testPartyView',
        flow: 1,
      },
    },
  },
},
Name Description
info.flow=1 Enable Simple Workflow

Logic of Simple Workflow

If enabled simple workflow, the operation logics are as follows:

  1. When create a new atom , the atom will be set atomFlow=1 automatically
  2. After the atom is submitted to the normal state, it will automatically enter the simple workflow processing
  3. The current atom flag indicates the corresponding atom actions to be processed
  4. At this time, users with permission can process these atom actions corresponding to the current atom flag
  5. When the last atom action is processed, you need to set the current atom flag=0, so as to indicate that the simple workflow has been processed completely
  6. At this time, users with permission can read this atom

Development of Simple Workflow

We need to do a little processing in the businss API routes of enable and action, so as to combine the whole simple workflow processing

src/module/test-party/backend/src/service/party.js

module.exports = app => {

  class Party extends app.Service {

    async enable({ atomClass, key, atom, user }) {
      // set atom flag = 1
      await this.ctx.meta.atom.flag({
        key,
        atom: { atomFlag: 1 },
        user,
      });
    }

    async action({ action, atomClass, key, user }) {
      // atom action: review
      if (action === 101) {
        // set atom flag = 2
        await this.ctx.meta.atom.flag({
          key,
          atom: { atomFlag: 2 },
          user,
        });
        // set atom flow = 0, 
        //   indicate that the simple workflow is completed
        await this.ctx.meta.atom.flow({
          key,
          atom: { atomFlow: 0 },
          user,
        });
      }
    }

  }

  return Party;
};