mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-23 12:08:43 -06:00
Compare commits
2 Commits
19129-mac-
...
21242-admi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d94b41554b | ||
|
|
3dcca73ecc |
@@ -732,25 +732,6 @@ class BaseInterface(models.Model):
|
|||||||
if self.primary_mac_address:
|
if self.primary_mac_address:
|
||||||
return self.primary_mac_address.mac_address
|
return self.primary_mac_address.mac_address
|
||||||
|
|
||||||
@property
|
|
||||||
def mac_address_display(self):
|
|
||||||
"""
|
|
||||||
Rich representation of MAC addresses for use in table columns (e.g. InterfaceTable).
|
|
||||||
Handles various configurations of MAC addresses for an interface:
|
|
||||||
11:22:33:44:55:66 <-- Single MAC address on interface, assigned as primary
|
|
||||||
11:22:33:44:55:66 (2) <-- Multiple MAC addresses on interface, one assigned as primary
|
|
||||||
2 available <-- 1 or more MAC addresses on interface, none assigned as primary
|
|
||||||
- <-- No MAC addresses on interface
|
|
||||||
"""
|
|
||||||
available_mac_count = self.mac_addresses.count()
|
|
||||||
if self.primary_mac_address:
|
|
||||||
if available_mac_count > 1:
|
|
||||||
return f"{self.primary_mac_address} ({available_mac_count})"
|
|
||||||
return self.primary_mac_address
|
|
||||||
if available_mac_count:
|
|
||||||
return f"{available_mac_count} available"
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class Interface(
|
class Interface(
|
||||||
InterfaceValidationMixin,
|
InterfaceValidationMixin,
|
||||||
|
|||||||
@@ -616,7 +616,6 @@ class BaseInterfaceTable(NetBoxTable):
|
|||||||
)
|
)
|
||||||
primary_mac_address = tables.Column(
|
primary_mac_address = tables.Column(
|
||||||
verbose_name=_('MAC Address'),
|
verbose_name=_('MAC Address'),
|
||||||
accessor=Accessor('mac_address_display'),
|
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def enqueue_event(queue, instance, request, event_type):
|
|||||||
|
|
||||||
|
|
||||||
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
|
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
|
||||||
user = User.objects.get(username=username) if username else None
|
user = None # To be resolved from the username if needed
|
||||||
|
|
||||||
for event_rule in event_rules:
|
for event_rule in event_rules:
|
||||||
|
|
||||||
@@ -134,6 +134,10 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
|
|||||||
# Resolve the script from action parameters
|
# Resolve the script from action parameters
|
||||||
script = event_rule.action_object.python_class()
|
script = event_rule.action_object.python_class()
|
||||||
|
|
||||||
|
# Retrieve the User if not already resolved
|
||||||
|
if user is None:
|
||||||
|
user = User.objects.get(username=username)
|
||||||
|
|
||||||
# Enqueue a Job to record the script's execution
|
# Enqueue a Job to record the script's execution
|
||||||
from extras.jobs import ScriptJob
|
from extras.jobs import ScriptJob
|
||||||
params = {
|
params = {
|
||||||
|
|||||||
@@ -409,60 +409,10 @@ ADMIN_MENU = Menu(
|
|||||||
MenuGroup(
|
MenuGroup(
|
||||||
label=_('Authentication'),
|
label=_('Authentication'),
|
||||||
items=(
|
items=(
|
||||||
MenuItem(
|
get_model_item('users', 'user', _('Users')),
|
||||||
link='users:user_list',
|
get_model_item('users', 'group', _('Groups')),
|
||||||
link_text=_('Users'),
|
get_model_item('users', 'token', _('API Tokens')),
|
||||||
staff_only=True,
|
get_model_item('users', 'objectpermission', _('Permissions'), actions=['add']),
|
||||||
permissions=['users.view_user'],
|
|
||||||
buttons=(
|
|
||||||
MenuItemButton(
|
|
||||||
link='users:user_add',
|
|
||||||
title='Add',
|
|
||||||
icon_class='mdi mdi-plus-thick',
|
|
||||||
permissions=['users.add_user']
|
|
||||||
),
|
|
||||||
MenuItemButton(
|
|
||||||
link='users:user_bulk_import',
|
|
||||||
title='Import',
|
|
||||||
icon_class='mdi mdi-upload',
|
|
||||||
permissions=['users.add_user']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
link='users:group_list',
|
|
||||||
link_text=_('Groups'),
|
|
||||||
staff_only=True,
|
|
||||||
permissions=['users.view_group'],
|
|
||||||
buttons=(
|
|
||||||
MenuItemButton(
|
|
||||||
link='users:group_add',
|
|
||||||
title='Add',
|
|
||||||
icon_class='mdi mdi-plus-thick',
|
|
||||||
permissions=['users.add_group']
|
|
||||||
),
|
|
||||||
MenuItemButton(
|
|
||||||
link='users:group_bulk_import',
|
|
||||||
title='Import',
|
|
||||||
icon_class='mdi mdi-upload',
|
|
||||||
permissions=['users.add_group']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
link='users:token_list',
|
|
||||||
link_text=_('API Tokens'),
|
|
||||||
staff_only=True,
|
|
||||||
permissions=['users.view_token'],
|
|
||||||
buttons=get_model_buttons('users', 'token')
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
link='users:objectpermission_list',
|
|
||||||
link_text=_('Permissions'),
|
|
||||||
staff_only=True,
|
|
||||||
permissions=['users.view_objectpermission'],
|
|
||||||
buttons=get_model_buttons('users', 'objectpermission', actions=['add'])
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MenuGroup(
|
MenuGroup(
|
||||||
|
|||||||
@@ -143,11 +143,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "MAC Address" %}</th>
|
<th scope="row">{% trans "MAC Address" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.mac_address_display %}
|
{% if object.primary_mac_address %}
|
||||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
<span class="font-monospace">{{ object.primary_mac_address|linkify }}</span>
|
||||||
{% if object.primary_mac_address %}
|
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ ''|placeholder }}
|
{{ ''|placeholder }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -78,11 +78,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "MAC Address" %}</th>
|
<th scope="row">{% trans "MAC Address" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{% if object.mac_address_display %}
|
{% if object.mac_address %}
|
||||||
<span class="font-monospace">{{ object.mac_address_display|linkify }}</span>
|
<span class="font-monospace">{{ object.mac_address }}</span>
|
||||||
{% if object.primary_mac_address %}
|
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
||||||
<span class="badge text-bg-primary">{% trans "Primary" %}</span>
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ ''|placeholder }}
|
{{ ''|placeholder }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user