Make permissions available in PluginTemplateExtension #3696

Closed
opened 2025-12-29 18:30:39 +01:00 by adam · 1 comment
Owner

Originally created by @steffann on GitHub (May 16, 2020).

Originally assigned to: @steffann on GitHub.

Environment

  • Python version: 3.7.6
  • NetBox version: 2.8.4

Proposed Functionality

Currently each PluginTemplateExtension is provided a context containing object, requests, settings and config. I propose to add a method for checking permissions to the default context.

Use Case

Writers of plugins may want to check whether the current user has certain permissions to only show certain information based on that and to only provide edit/delete links to those that are allowed to do so.

A work-around is to make perms available is:

from django.contrib.auth.context_processors import PermWrapper

def left_page(self):
   context = {
       'perms': PermWrapper(self.context['request'].user),
   }
   return self.render('pluginname/test.html', context)

My feeling is that this shouldn't be necessary and that NetBox should provide a method to check permissions by default.

Considering the work being done on #554 I suggest leaving this feature request until that work has been completed. Otherwise we would very quickly end up with having to provide multiple ways to check permissions. Let's standardise on something that supports #554 style permissions.

Database Changes

None

External Dependencies

None

Originally created by @steffann on GitHub (May 16, 2020). Originally assigned to: @steffann on GitHub. ### Environment * Python version: 3.7.6 * NetBox version: 2.8.4 ### Proposed Functionality Currently each `PluginTemplateExtension` is provided a context containing `object`, `requests`, `settings` and `config`. I propose to add a method for checking permissions to the default context. ### Use Case Writers of plugins may want to check whether the current user has certain permissions to only show certain information based on that and to only provide edit/delete links to those that are allowed to do so. A work-around is to make `perms` available is: ``` from django.contrib.auth.context_processors import PermWrapper def left_page(self): context = { 'perms': PermWrapper(self.context['request'].user), } return self.render('pluginname/test.html', context) ``` My feeling is that this shouldn't be necessary and that NetBox should provide a method to check permissions by default. Considering the work being done on #554 I suggest leaving this feature request until that work has been completed. Otherwise we would very quickly end up with having to provide multiple ways to check permissions. Let's standardise on something that supports #554 style permissions. ### Database Changes None ### External Dependencies None
adam added the status: accepted label 2025-12-29 18:30:39 +01:00
adam closed this issue 2025-12-29 18:30:39 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 20, 2020):

I'd say I'm about 90% sure at this point that #554 will preserve the current behavior of the built-in perms context variable. Let's move ahead with this assumption, and if things do change, I'll make the necessary adjustments at a later point.

@jeremystretch commented on GitHub (May 20, 2020): I'd say I'm about 90% sure at this point that #554 will preserve the current behavior of the built-in `perms` context variable. Let's move ahead with this assumption, and if things do change, I'll make the necessary adjustments at a later point.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3696