# plugins_api.utils.level_from_plugin

*module*

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/level_from_plugin.py#L1-1)

## plugins_api.utils.level_from_plugin.resolve_field_level_by_plugin_slug

*function*

```python
def resolve_field_level_by_plugin_slug(field_slug: str, source: str) -> str | None
```

Resolve the most restrictive level of a plugin field by scanning all MetadataObjectTypes.

Useful when only the plugin slug is available (e.g. from a serializer context
or a DB source name), without a direct reference to the plugin class or a
specific metadata object instance.

The most restrictive level wins across all object types:
``mandatory`` (0) > ``recommended`` (1) > ``optional`` (2).

**Parameters**

- `field_slug` (`str`) — The slug of the plugin field to look up.
- `source` (`str`) — The source plugin that owns the field.

**Returns**

- (`str or None`) — The most restrictive level (``"mandatory"``, ``"recommended"``, or ``"optional"``) across all MetadataObjectTypes, or ``None`` if the field is not declared in any of them.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/level_from_plugin.py#L1-44)

## plugins_api.utils.level_from_plugin.resolve_field_level_in_metadata_object

*function*

```python
def resolve_field_level_in_metadata_object(plugin_class, metadata_object, field_slug: str, metadata_object_types: dict | None = None) -> str | None
```

Resolve the level of a plugin field within a specific MetadataObjectType.

Useful in contexts where both the plugin class and the metadata object are
already available (e.g. during submission validation or promotion), avoiding
a full scan across all object types.

**Parameters**

- `plugin_class` (`type`) — The plugin class (not an instance) returned by ``get_plugin_class()``.
- `metadata_object` (`SubmissionMetadataObject`) — The metadata object whose type is used to look up the correct MetadataObjectType on the plugin.
- `field_slug` (`str`) — The slug of the plugin field to look up.

**Returns**

- (`str or None`) — The level (``"mandatory"``, ``"recommended"``, or ``"optional"``) of the field within the matching MetadataObjectType, or ``None`` if the object type is not found on the plugin or the field is not declared in it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/plugins-api-v2.0.1/plugin_api/plugins_api/utils/level_from_plugin.py#L47-85)
