Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CustomField UI visibility in 3.8 #1136

Draft
wants to merge 4 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 92 additions & 0 deletions docs/plugins/netbox_custom_field_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,98 @@ Parameters
- :ansible-option-choices-entry:`"multiobject"`


.. raw:: html

</div>

* - .. raw:: html

<div class="ansible-option-indent"></div><div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-data/ui_editable"></div>

.. _ansible_collections.netbox.netbox.netbox_custom_field_module__parameter-data/ui_editable:

.. rst-class:: ansible-option-title

**ui_editable**

.. raw:: html

<a class="ansibleOptionLink" href="#parameter-data/ui_editable" title="Permalink to this option"></a>

.. rst-class:: ansible-option-type-line

:ansible-option-type:`string`

:ansible-option-versionadded:`added in netbox.netbox 3.17.0`


.. raw:: html

</div>

- .. raw:: html

<div class="ansible-option-indent-desc"></div><div class="ansible-option-cell">

Whether the custom field is editable in the UI


.. rst-class:: ansible-option-line

:ansible-option-choices:`Choices:`

- :ansible-option-choices-entry:`"yes"`
- :ansible-option-choices-entry:`"no"`
- :ansible-option-choices-entry:`"hidden"`


.. raw:: html

</div>

* - .. raw:: html

<div class="ansible-option-indent"></div><div class="ansible-option-cell">
<div class="ansibleOptionAnchor" id="parameter-data/ui_visible"></div>

.. _ansible_collections.netbox.netbox.netbox_custom_field_module__parameter-data/ui_visible:

.. rst-class:: ansible-option-title

**ui_visible**

.. raw:: html

<a class="ansibleOptionLink" href="#parameter-data/ui_visible" title="Permalink to this option"></a>

.. rst-class:: ansible-option-type-line

:ansible-option-type:`string`

:ansible-option-versionadded:`added in netbox.netbox 3.17.0`


.. raw:: html

</div>

- .. raw:: html

<div class="ansible-option-indent-desc"></div><div class="ansible-option-cell">

Whether the custom field is displayed in the UI


.. rst-class:: ansible-option-line

:ansible-option-choices:`Choices:`

- :ansible-option-choices-entry:`"always"`
- :ansible-option-choices-entry:`"if-set"`
- :ansible-option-choices-entry:`"hidden"`


.. raw:: html

</div>
Expand Down
39 changes: 39 additions & 0 deletions plugins/modules/netbox_custom_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,30 @@
required: false
type: str
version_added: "3.10.0"
ui_editable:
description:
- Whether the custom field is editable in the UI
required: false
choices:
- "yes"
- "no"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are going to cause a lot of confusion, people are going to just use yes and no without strings and YAML will convert them to booleans, and then the module will throw an error and they'll come here asking why it doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly and that is what my comments above are about.
I 100% agree.

I need feedback on what is the preferred solution to work around this. I do not think forcing users to quote values to just one module parameter is reasonable, at all.

Two other possible options:

  1. Present 2 different boolean parameters instead of presenting ui_editable as a string value: ui_editable and ui_editable_hidden. Based on the combined value of these 2 parameters decide if give yes no or hidden to NetBox API.
  2. Use some other values than yes and no as values ui_editable: module parameters takes other values for example read-write and calls NetBox API with yes; value read-only means no and hidden stays the same.

Open to other suggestions or feedback on these 2. I had an open discussion item at the netbox project and suggestions to not use yes and no in the NetBox API were ignored.

Both will make the module API diverge from NetBox API which will be sad.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Option 1 of the other options is the best one. If we're diverging from the NetBox API we may as well do it the best way we can. Thanks for your work on this @bluikko

Copy link
Contributor

@sc68cal sc68cal Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think option 1 is the best solution. I'm not crazy about this trilean that the netbox API is exposing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will rework this to 2x boolean then.

- hidden
type: str
version_added: "3.17.0"
ui_visible:
description:
- Whether the custom field is displayed in the UI
required: false
choices:
- always
- if-set
- hidden
type: str
version_added: "3.17.0"
ui_visibility:
description:
- The UI visibility of the custom field
- Replaced by O(ui_visible) and O(ui_editable) in NetBox 3.7
required: false
choices:
- read-write
Expand Down Expand Up @@ -245,6 +266,24 @@ def main():
weight=dict(required=False, type="int"),
search_weight=dict(required=False, type="int"),
group_name=dict(required=False, type="str"),
ui_editable=dict(
required=False,
choices=[
"yes",
"no",
"hidden",
],
type="str",
),
ui_visible=dict(
required=False,
choices=[
"always",
"if-set",
"hidden",
],
type="str",
),
ui_visibility=dict(
required=False,
choices=[
Expand Down