mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Ensure subscribe button appears only on relevant models
This commit is contained in:
parent
4f0cc950bc
commit
aa8a891122
@ -77,7 +77,7 @@ Context:
|
||||
{% if perms.extras.add_bookmark and object.bookmarks %}
|
||||
{% bookmark_button object %}
|
||||
{% endif %}
|
||||
{% if perms.extras.add_subscription %}
|
||||
{% if perms.extras.add_subscription and object.subscriptions %}
|
||||
{% subscribe_button object %}
|
||||
{% endif %}
|
||||
{% if request.user|can_add:object %}
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% load i18n %}
|
||||
{% if form_url %}
|
||||
<form action="{{ form_url }}?return_url={{ return_url }}" method="post">
|
||||
{% csrf_token %}
|
||||
{% for field, value in form_data.items %}
|
||||
@ -14,3 +15,4 @@
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
|
@ -4,6 +4,7 @@ from django.urls import NoReverseMatch, reverse
|
||||
|
||||
from core.models import ObjectType
|
||||
from extras.models import Bookmark, ExportTemplate, Subscription
|
||||
from netbox.models.features import NotificationsMixin
|
||||
from utilities.querydict import prepare_cloned_fields
|
||||
from utilities.views import get_viewname
|
||||
|
||||
@ -97,6 +98,10 @@ def delete_button(instance):
|
||||
|
||||
@register.inclusion_tag('buttons/subscribe.html', takes_context=True)
|
||||
def subscribe_button(context, instance):
|
||||
# Skip for objects which don't support notifications
|
||||
if not (issubclass(instance.__class__, NotificationsMixin)):
|
||||
return {}
|
||||
|
||||
# Check if this user has already subscribed to the object
|
||||
content_type = ContentType.objects.get_for_model(instance)
|
||||
subscription = Subscription.objects.filter(
|
||||
|
Loading…
Reference in New Issue
Block a user