mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
80376abedf
* Introduce 'accounts' app for user-specific views & resources * Move UserTokenTable to account app * Move login & logout views to account app
56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from django.utils.translation import gettext as _
|
|
|
|
from account.models import UserToken
|
|
from netbox.tables import NetBoxTable, columns
|
|
|
|
__all__ = (
|
|
'UserTokenTable',
|
|
)
|
|
|
|
|
|
TOKEN = """<samp><span id="token_{{ record.pk }}">{{ record }}</span></samp>"""
|
|
|
|
ALLOWED_IPS = """{{ value|join:", " }}"""
|
|
|
|
COPY_BUTTON = """
|
|
{% if settings.ALLOW_TOKEN_RETRIEVAL %}
|
|
{% copy_content record.pk prefix="token_" color="success" %}
|
|
{% endif %}
|
|
"""
|
|
|
|
|
|
class UserTokenTable(NetBoxTable):
|
|
"""
|
|
Table for users to manager their own API tokens under account views.
|
|
"""
|
|
key = columns.TemplateColumn(
|
|
verbose_name=_('Key'),
|
|
template_code=TOKEN,
|
|
)
|
|
write_enabled = columns.BooleanColumn(
|
|
verbose_name=_('Write Enabled')
|
|
)
|
|
created = columns.DateColumn(
|
|
verbose_name=_('Created'),
|
|
)
|
|
expires = columns.DateColumn(
|
|
verbose_name=_('Expires'),
|
|
)
|
|
last_used = columns.DateTimeColumn(
|
|
verbose_name=_('Last Used'),
|
|
)
|
|
allowed_ips = columns.TemplateColumn(
|
|
verbose_name=_('Allowed IPs'),
|
|
template_code=ALLOWED_IPS
|
|
)
|
|
actions = columns.ActionsColumn(
|
|
actions=('edit', 'delete'),
|
|
extra_buttons=COPY_BUTTON
|
|
)
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = UserToken
|
|
fields = (
|
|
'pk', 'id', 'key', 'description', 'write_enabled', 'created', 'expires', 'last_used', 'allowed_ips',
|
|
)
|