Display custom links based on user permission #4158

Closed
opened 2025-12-29 18:33:31 +01:00 by adam · 5 comments
Owner

Originally created by @bistraque on GitHub (Oct 1, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.9.2

Proposed Functionality

Custom links currently appear unconditionally whether or not the user has permission to follow the link. By having the possibility to associate a Custom Link with a specific Permission, it would be possible to hide the corresponding button/link in the UI if the user would ultimately fail using it (e.g. not allowed to execute scripts). A single Permission would suffice as it is possible to create a new specific permission rule if needed. The semantics would be:

  • if null, display custom link
  • else if required permission is a subset of user permissions display link/button
  • else hide link/button
  • if all links in a group are hidden, hide group button

Use Case

Our Netbox deployment is becoming a central source of truth with contributions from several external tools and environments. We use custom scripts to automate import and export of specific elements/attributes but not all users are involved in this, and not all users have the same domain in charge. This feature is a way to avoid a crowded custom link area if the number of custom script increases with time.

Database Changes

Not familiar with Netbox DB but I guess a Permission reference, possibly null, in Custom Link table is needed

External Dependencies

None

Originally created by @bistraque on GitHub (Oct 1, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.9 * NetBox version: 2.9.2 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Custom links currently appear unconditionally whether or not the user has permission to follow the link. By having the possibility to associate a _Custom Link_ with a specific _Permission_, it would be possible to hide the corresponding button/link in the UI if the user would ultimately fail using it (e.g. not allowed to execute scripts). A single Permission would suffice as it is possible to create a new specific permission rule if needed. The semantics would be: - if null, display custom link - else if required permission is a subset of user permissions display link/button - else hide link/button - if all links in a group are hidden, hide group button <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Our Netbox deployment is becoming a central source of truth with contributions from several external tools and environments. We use custom scripts to automate import and export of specific elements/attributes but not all users are involved in this, and not all users have the same domain in charge. This feature is a way to avoid a crowded custom link area if the number of custom script increases with time. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes Not familiar with Netbox DB but I guess a Permission reference, possibly null, in Custom Link table is needed <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 18:33:31 +01:00
adam closed this issue 2025-12-29 18:33:31 +01:00
Author
Owner

@DanSheps commented on GitHub (Oct 2, 2020):

Could you clarify, are you saying a single permission total (can_view_customlink) or a single permission per custom link(can_view_customlink_x)?

Either way, the object based permissions were never meant to be this granular to apply to a single element on a page. I think the technical requirements for implementation would far out weigh the benefits received.

@DanSheps commented on GitHub (Oct 2, 2020): Could you clarify, are you saying a single permission total (can_view_customlink) or a single permission per custom link(can_view_customlink_x)? Either way, the object based permissions were never meant to be this granular to apply to a single element on a page. I think the technical requirements for implementation would far out weigh the benefits received.
Author
Owner

@jeremystretch commented on GitHub (Oct 2, 2020):

It's possible today to toggle the display of a custom link by rendering an empty link text. We don't currently pass any context to the link template beyond the object itself, though it's possible to change that. Any support for the consideration of permissions when rendering a custom link must be done through the use of template tags/context: We won't be adding any direct relationship between the CustomLink and ObjectPermission models.

@jeremystretch commented on GitHub (Oct 2, 2020): It's possible today to toggle the display of a custom link by rendering an empty link text. We don't currently pass any context to the link template beyond the object itself, though it's possible to change that. Any support for the consideration of permissions when rendering a custom link must be done through the use of template tags/context: We won't be adding any direct relationship between the CustomLink and ObjectPermission models.
Author
Owner

@jeremystretch commented on GitHub (Oct 9, 2020):

Permissions available to the current user can now be referenced using the perms context variable within a custom link text or URL. For example, to check for the dcim.add_site permission, check {{ perms.dcim.add_site }}. For more detail on referencing permissions within templates, see the Django documentation.

@jeremystretch commented on GitHub (Oct 9, 2020): Permissions available to the current user can now be referenced using the `perms` context variable within a custom link text or URL. For example, to check for the `dcim.add_site` permission, check `{{ perms.dcim.add_site }}`. For more detail on referencing permissions within templates, see [the Django documentation](https://docs.djangoproject.com/en/stable/topics/auth/default/#permissions).
Author
Owner

@bistraque commented on GitHub (Oct 9, 2020):

Thanks, this perms object is perfect for the intended objective. I admit my approach was a bit naive...

One question: in this implementation, assuming all custom links belonging to a given group render as empty, would the group button be hidden as well?

@bistraque commented on GitHub (Oct 9, 2020): Thanks, this `perms` object is perfect for the intended objective. I admit my approach was a bit naive... One question: in this implementation, assuming all custom links belonging to a given group render as empty, would the group button be hidden as well?
Author
Owner

@bistraque commented on GitHub (Oct 13, 2020):

For the record, tested with v2.9.7: when all custom links of a group render as empty, the corresponding dropdown group button is not rendered.

@bistraque commented on GitHub (Oct 13, 2020): For the record, tested with v2.9.7: when all custom links of a group render as empty, the corresponding dropdown group button is not rendered.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4158