Metadata-Version: 2.4
Name: netbox-hidebox
Version: 2.1.1
Summary: NetBox plugin to hide form fields per user group from the UI
Author-email: Sofien Aouni <contact@sofien.meme>
Maintainer: AOS
License: AGPL-3.0-or-later
Keywords: netbox,netbox-plugin,forms,permissions
Classifier: Framework :: Django
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

[![PyPI Downloads](https://static.pepy.tech/personalized-badge/netbox-hidebox?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads)](https://pepy.tech/projects/netbox-hidebox)
![Static Badge](https://img.shields.io/badge/release-v2.1.1-blue)

# NetBox HideBox Plugin

**NetBox HideBox** is a powerful utility for NetBox administrators to clean up and customize the user interface. It allows you to dynamically hide specific **form fields** and **detail-page panels, attributes and custom fields** on a per-model basis, filtered by User Groups.

Whether you want to hide internal metadata from specific teams or simplify complex forms for non-technical users, HideBox provides a managed, UI-driven way to do it.

## Features

*   **UI-Driven Configuration:** No need to edit Python files to hide things; manage everything through the "HideBox" menu.
*   **Two kinds of rule:**
    *   **Field Hide Rules** hide fields on edit/add **forms**.
    *   **Detail View Rules** hide whole panels, single attributes or custom fields on an object's **detail page** — always, or only when they would render empty.
*   **Dynamic Field Discovery:** Automatically inspects NetBox forms and panels to list the available targets for any selected Content Type (Device, IP Address, Virtual Machine, etc.).
*   **Group-Based Visibility:**
    *   Hide for **all users**.
    *   Hide **only for specific User Groups**.
*   **Safe Integration:** Uses safe monkey-patching on the base `NetBoxModelForm` and on panel rendering, so a rule can never break a NetBox page.
*   **Toggleable Rules:** Easily enable or disable rules without deleting them.
*   **Per-Session Reveal Toggle:** A navbar dropdown lets any logged-in user temporarily show what is hidden — form fields and detail-view panels independently — for their current session, without changing any rules.

## Compatibility

| NetBox Version | Plugin Version |
|----------------|----------------|
| 4.3.0+         | 2.1.1          |
| 4.3.0+         | 2.0.2          |
| 4.3.0+         | 1.3.0          |
| 4.2.0 – 4.2.8  | 1.2.3          |
| 4.2.0 – 4.2.6  | 1.2.1          |

## Installation

### 1. Install via Pip

pip install netbox-hidebox

*(Alternatively, if installing from source: `pip install .` from the root of the repository)*

### 2. Enable in NetBox
Add the plugin to your `configuration.py`:

PLUGINS = [
    'netbox_hidebox',
]

### 3. Run Migrations

python3 manage.py migrate netbox_hidebox

### 4. Restart NetBox

sudo systemctl restart netbox netbox-rq

## How It Works

1.  **Middleware:** The plugin includes a lightweight middleware that tracks the current user in the request thread.
2.  **Form Patching:** Upon startup, the plugin patches the `__init__` method of the core `NetBoxModelForm`, and the rendering of detail-page panels.
3.  **Dynamic Logic:** Every time a form or detail page is rendered, the plugin checks the active rules matching that model. If the current user falls under a rule, the targeted form fields are converted to `HiddenInput` widgets, and the targeted panels/attributes/custom fields are dropped from the page.
4.  **Cheap by Default:** Rules are held in NetBox's shared cache, so a model with no rules costs zero extra database queries.

## Usage

### Creating a Field Hide Rule (forms)

1.  Navigate to **Plugins > HideBox > Field Hide Rules (forms)**.
2.  Click **Add**.
3.  **Name:** A descriptive name (e.g., "Hide VM Sensitive Tags").
4.  **Content Type:** Select the model you want to target (e.g., `virtualization | virtual machine`).
5.  **Fields to Hide:** Once the Content Type is selected, the plugin will load all available form fields. Check the boxes for fields you want to disappear.
6.  **Hide for Groups:**
    *   The fields are hidden **only for members** of the groups you select here.
    *   If left empty, the fields are hidden for **everyone**.
7.  **Enabled:** Keep checked to activate the rule.

Hidden fields keep their stored value: the widget is swapped, the field is not removed, so saving an object never wipes what a user could not see.

### Creating a Detail View Rule (panels / attributes / custom fields)

1.  Navigate to **Plugins > HideBox > Detail View Rules (panels/fields)**.
2.  Click **Add**.
3.  **Content Type:** The model this applies to. Leave blank to match **any** model.
4.  **Target Kind:** *Whole panel*, *Single attribute*, or *Custom field*.
5.  **Target Name:** Picked from the discovered targets for that model and kind. Use `*` to match **every** target of that kind — for example target kind *Single attribute* + `*` + *Hide when empty* hides every blank built-in field, with no need for one rule per field. A rule naming a specific target always wins over a `*` rule of the same kind.
6.  **Mode:**
    *   **Always hide** — the target never renders.
    *   **Hide when empty** — it renders only when it has content. For whole panels this is a best-effort check covering the known panel types (info cards, list/table cards, Custom Fields, Comments, Tags, Related Objects); an unrecognised panel type is left alone, so target it by name with *Always hide* instead.
7.  **Hide for Groups** and **Enabled** work exactly as for field hide rules.

### Revealing What Is Hidden

An eye icon in the **top navbar** opens a dropdown with two independent switches:

*   **Form fields** — reveal the fields hidden by field-hide rules.
*   **Detail view** — reveal the panels, attributes and custom fields hidden by detail-view rules.

A **Show everything / Hide everything** entry flips both at once. The icon reflects the state: eye-off (nothing revealed), a hollow eye (one of the two revealed) or a solid eye (both revealed).

Revealing is temporary and useful when you occasionally need to see or edit something hidden. The state is per-session and per-user, and does not modify any rules. Note that reveal is available to **all** authenticated users, consistent with HideBox being a UI tool rather than a security control.

## Security Note

**HideBox is a UI/UX enhancement tool.** 

Hiding a field or panel prevents it from appearing in the browser-based UI. However, this plugin **does not** modify API permissions or database-level constraints. A user with API access and the correct NetBox permissions could still theoretically read and modify hidden fields via the REST API or custom scripts — and any logged-in user can flip the reveal toggle. For strict security enforcement, always use NetBox's built-in **Permissions** and **Constraints** system.
