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:
- Create a new atom of
party
, which is in thedraft
state - After submitted, this atom is in the
normal
state - In the
normal
state, users granted theread
permission can view this atom - In the
normal
state, users granted theprint
permission canprint
this atom
For the custom action
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 bereviewed
before
- Create a new atom of
party
, which is in thedraft
state - After submitted, this atom is in the
normal
state, and setatom flag
=1
- When
atom flag
=1
, users granted thereview
permission canreview
this atom - After
reviewed
, setatom flag
=2
- When
atom flag
=2
, users granted theprint
permission canprint
this atom
Name | Description |
---|---|
atom flag=1 | waiting for review |
atom flag=2 | has been reviewed |
Characteristics of Atom Flag
Atom action
is associated withatom flag
- If
atom action
not specifiedatom flag
: in thenormal
state, users granted anyaction
permission can perform the correspondingaction
on this atom - If
atom action
specifiedatom flag
: in thenormal
state, obtain theatom actions
corresponding to thecurrent atom flag
, and then judge whether users has permission to perform theseatom actions
Atom action
can be associated with multipleatom 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 bereview
. But at this time, whether users granted theread
permission can be allowed toread
this atom?
- By enable the
simple workflow
, we can ensure that only after the actionreview
is completed(meaning the workflow is done), can the atom beread
by the users with theread
permission
Definition of Simple Workflow
By default, the simple workflow
is not enabled. Definition of simple workflow
is as folows:
src/suite-vendor/test-party/modules/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:
- When create a new atom , the atom will be set
atomFlow
=1
automatically - After the atom is submitted to the
normal
state, it will automatically enter thesimple workflow
processing - The
current atom flag
indicates the correspondingatom actions
to be processed - At this time, users with permission can process these
atom actions
corresponding to thecurrent atom flag
- When the last
atom action
is processed, you need to set the currentatom flag
=0
, so as to indicate that thesimple workflow
has been processed completely - 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/suite-vendor/test-party/modules/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;
};
Comments: