Skip to content

Make permissions available in PluginTemplateExtension #4652

@steffann

Description

@steffann

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

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions