Skip to main content

OArepo FSM library for record state transitions

Project description

https://img.shields.io/travis/oarepo/oarepo-fsm.svg https://img.shields.io/coveralls/oarepo/oarepo-fsm.svg https://img.shields.io/github/tag/oarepo/oarepo-fsm.svg https://img.shields.io/pypi/dm/oarepo-fsm.svg https://img.shields.io/github/license/oarepo/oarepo-fsm.svg

OArepo FSM library for record state transitions built on top of the https://pypi.org/project/sqlalchemy-fsm/ library.

Quickstart

Run the following commands to bootstrap your environment

git clone https://github.com/oarepo/oarepo-fsm
cd oarepo-fsm
pip install -e .[devel]

Configuration

Check that correct record_class is being used on the RECORDS_REST_ENDPOINT’s item_route

item_route='/records/<pid(recid,record_class="yourapp.models:RecordModelFSM"):pid_value>',

To automatically add a link to the FSM endpoint to your record links, use the following links_factory_imp in your RECORDS_REST_ENDPOINTS config

links_factory_imp='oarepo_fsm.links:record_fsm_links_factory',

If you wish to activate FSM on a certain Record enpoints only, put in your config

OAREPO_FSM_ENABLED_REST_ENDPOINTS = ['recid']

Where recid is the prefix key into your RECORDS_REST_ENDPOINTS configuration. This library activates FSM on all endpoints using record_class inherited from FSMMixin otherwise.

Usage

In order to use this library, you need to define a Record model in your app, that inherits from a FSMMixin column

from invenio_records import Record
from oarepo_fsm.mixins import FSMMixin

class RecordModelFSM(FSMMixin, Record):
...

To define FSM transitions on this class, create methods decorated with @transition(..) e.g.

@transition(Transition(
    src=['open', 'archived'],
    dest='published',
    required=['id'],
    permissions=[editor_permission]))
def publish(self, **kwargs):
    print('record published')

Where Transition is defined as:

  • src: record must be in one of the source states before transition could happen

  • dest: target state of the transition

  • required: a list of required **kwargs that must be passed to the @transition decorated function

  • permissions: currently logged user must have at least one of the permissions to execute the transition

REST API Usage

To get current record state and possible transitions (only actions that you have permission to invoke will be returned)

GET <record_rest_item_endpoint>
>>>
{
    metadata: {
        state: <current state of the record>
        ... other record metadata
    }
    links: {
        self: ...
        <fsm_action1_name>: <action_url>,
        <fsm_action2_name>: <action_url>,
        ...
    }
}

To invoke a specific transition action, do

POST <record_rest_endpoint>/<fsm_action_name>

Further documentation is available on https://oarepo-fsm.readthedocs.io/

Changes

Version 0.1.0 (released TBD)

  • Initial public release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oarepo-fsm-1.0.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oarepo_fsm-1.0.1-py2.py3-none-any.whl (22.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file oarepo-fsm-1.0.1.tar.gz.

File metadata

  • Download URL: oarepo-fsm-1.0.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for oarepo-fsm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b2a038ac17cc3a886a9ca73edeeff6b912cf31d941dcd2051071d1783bb091e2
MD5 aaab7eafdf2ee2645742701199d02132
BLAKE2b-256 364cdc017349ac678aab359225146f2934ae2d8f17b7e07b492728ba03f47ff9

See more details on using hashes here.

File details

Details for the file oarepo_fsm-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: oarepo_fsm-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for oarepo_fsm-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d506c3e794dd5286c3a8123e80d51f00faf5eac8cc99779ebbce259ff49fd7e5
MD5 c3ba1baf92a100c4f91c654f9cd11ab7
BLAKE2b-256 e6e18ad6e940fe12ed8de50cba15f79766407b0cd0262c2e801d82c920d52ddf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page