Skip to content

Commit

Permalink
Addressed some comments.
Browse files Browse the repository at this point in the history
Changed the model ObjectState to Diode.
  • Loading branch information
Julio-Oliveira-Encora committed Mar 1, 2024
1 parent 097d313 commit fb97219
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions diode-netbox-plugin/netbox_diode_plugin/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class IsDiodeViewer(BasePermission):
"""Custom permission to allow users that has permission "netbox_diode_plugin.view_objectstate" to view the object type."""

def has_permission(self, request, view):
"""Check if the request is in SAFE_METHODS and user has netbox_diode_plugin.view_objectstate permission."""
"""Check if the request is in SAFE_METHODS and user has netbox_diode_plugin.view_diode permission."""
return request.method in SAFE_METHODS and request.user.has_perm(
"netbox_diode_plugin.view_objectstate"
"netbox_diode_plugin.view_diode"
)


class IsDiodePost(BasePermission):
"""Custom permission to allow users that has permission "netbox_diode_plugin.add_objectstate" and POST requests."""
"""Custom permission to allow users that has permission "netbox_diode_plugin.add_diode" and POST requests."""

def has_permission(self, request, view):
"""Check if the request is in POST and user has netbox_diode_plugin.add_objectstate permission."""
"""Check if the request is in POST and user has netbox_diode_plugin.add_diode permission."""
return request.method in ["POST"] and request.user.has_perm(
"netbox_diode_plugin.add_objectstate"
"netbox_diode_plugin.add_diode"
)
5 changes: 3 additions & 2 deletions diode-netbox-plugin/netbox_diode_plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import models


class ObjectState(models.Model):
class Diode(models.Model):
"""Dummy model used to generate permissions for Diode NetBox Plugin. Does not exist in the database."""

class Meta:
Expand All @@ -16,5 +16,6 @@ class Meta:
default_permissions = ()

permissions = (
("view_objectstate", "Can view ObjectState"),
("view_diode", "Can view Diode"),
("add_diode", "Can apply change sets from Diode"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BaseApplyChangeSet(APITestCase):
def setUp(self):
"""Set up test."""
self.user = User.objects.create_user(username="testcommonuser")
self.add_permissions("netbox_diode_plugin.add_objectstate")
self.add_permissions("netbox_diode_plugin.add_diode")
self.user_token = Token.objects.create(user=self.user)

self.user_header = {"HTTP_AUTHORIZATION": f"Token {self.user_token.key}"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
self.root_token = Token.objects.create(user=self.root_user)

self.user = User.objects.create_user(username="testcommonuser")
self.add_permissions("netbox_diode_plugin.view_objectstate")
self.add_permissions("netbox_diode_plugin.view_diode")
self.user_token = Token.objects.create(user=self.user)

# another_user does not have permission.
Expand Down

0 comments on commit fb97219

Please sign in to comment.