> For the complete documentation index, see [llms.txt](https://razortheory.gitbook.io/third-party-monitoring-module-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://razortheory.gitbook.io/third-party-monitoring-module-documentation/technical-documentation/api-metadata.md).

# API Metadata

As far as we use dynamic list of fields in every specific case, we've reworked existing rest framework metadata mechanism (OPTIONS requests). By default only editable fields are shown here, so for clear understanding of current situation, viewable fields were added inside GET action (`unicef_restlib.metadata.CRUActionsMetadataMixin`). When fields lists are prepared, they can be filtered using permissions with `etools.applications.utils.permissions.metadata.PermissionsBasedMetadataMixin`. Also, transitions set can vary depending on the permissions, so they also should be available in the metadata. `etools.applications.permissions2.PermittedFSMTransitionActionMetadataMixin` was designed to do this. Additionally, transitions can be renamed on the fly using `name` in custom attribute of transition. For example:

```python
custom={ 'name': _('Cancel Visit') }
```

or lambda function

```python
custom={    
    'name': lambda obj: _('Re-assign') if obj.status == TPMVisit.STATUSES.tpm_rejected else _('Assign')
}
```

&#x20;If none is provided, function name will be used as the display name in the metadata.

So here is an example of the metadata class that can correctly communicate with permissions and correctly display information about the availability of each field.

```python
class ExampleMetadata(
    CRUActionsMetadataMixin,
    PermissionsBasedMetadataMixin,
    PermittedFSMTransitionActionMetadataMixin,
    SimpleMetadata
):
    def get_serializer_info(self, serializer):
        if serializer.instance:
            serializer.context['instance'] = serializer.instance
        return super(TPMPermissionBasedMetadata, self).get_serializer_info(serializer)
```

Example of metadata:&#x20;

![](https://3736791516-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LJxGPxbbRc1mv-_gOuP%2F-LMhIkDfgcfTtQQIUYS1%2F-LMhImwLGU7-BwN8ueqC%2F1uHkQK.jpg?alt=media\&token=00d816a9-e7ef-4886-a911-f8529613eb0c)

Example shows that visits could be added by partner field. If user is not allowed to create visits, POST will not appear:

![](https://3736791516-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LJxGPxbbRc1mv-_gOuP%2F-LMhIkDfgcfTtQQIUYS1%2F-LMhIv0EQMZ4HJU9SQt6%2FljwoGB.jpg?alt=media\&token=9f271264-9a5a-4196-a7d8-2b1dba386cfa)

Example of available instance fsm transitions:

![](https://3736791516-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LJxGPxbbRc1mv-_gOuP%2F-LMhIkDfgcfTtQQIUYS1%2F-LMhJ-MZZbipR17av9F3%2FFMNr52.jpg?alt=media\&token=8dfa8b36-e1da-4055-a316-14a90c65921e)

user can either accept or reject the Visit, but can't edit any details.
