ITADN

Add "not" lookups for use in Permissions

#22899Closedsburlappp 创建于 18 天前
type: featurenetboxstatus: declined
S
sburlapppcommented
### NetBox version 4.6.6 ### Feature type Change to existing functionality ### Proposed functionality Add additional "not" lookups to enable Permissions rules that can only work via negation. See: https://github.com/netbox-community/netbox/discussions/8756 https://github.com/netbox-community/netbox/issues/4949 ### Use case For example, to grant someone access to all IPs *except* from one subnet: ``` from django.db.models import Lookup class NetNotContainedOrEqual(Lookup): lookup_name = 'net_not_contained_or_equal' def as_sql(self, qn, connection): lhs, lhs_params = self.process_lhs(qn, connection) rhs, rhs_params = self.process_rhs(qn, connection) params = lhs_params + rhs_params return f'NOT ({lhs} <<= {rhs})', params from ipam.fields import IPAddressField IPAddressField.register_lookup(NetNotContainedOrEqual) ``` ...then use an IP Address View Permission like: ``` { "address__net_not_contained_or_equal": "10.0.0.0/8" } ``` ### Database changes None ### External dependencies None
关闭于 15 天前 1 条评论