Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peteeckel committed Nov 20, 2023
1 parent 35c9509 commit 7fdcebd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion netbox_dns/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def post_clean(self, sender, **kwargs):
record = new_address_record(ip_address)
if record is not None:
record.full_clean()
check_permission(user, "netbox_dns.add_record")
check_permission(user, "netbox_dns.add_record", record)
else:
#
# Handle updates to existing IP addresses
Expand Down
12 changes: 10 additions & 2 deletions netbox_dns/utilities/ipam_coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,13 @@ def update_address_record(record, ip_address):


def check_permission(user, permission, record=None):
if not user.has_perm(permission, record):
raise PermissionDenied()
if record is not None and record.pk is None:
check_record = None
else:
check_record = record

if not user.has_perm(permission, check_record):
action = action = resolve_permission(permission)[1]
item = "records" if check_record is None else f"record {check_record}"

raise PermissionDenied(f"User {user} is not allowed to {action} {item}")

0 comments on commit 7fdcebd

Please sign in to comment.