From b8cedfcc083971f601177b465bf7d1aef58756d5 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Wed, 17 Apr 2024 07:09:50 -0700 Subject: [PATCH] 15582 check permissions on specific object when sync request (#15704) * 15582 check permissions on specific object when sync request * 15582 move permission check * Enable translation of error message --------- Co-authored-by: Jeremy Stretch --- netbox/core/api/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/netbox/core/api/views.py b/netbox/core/api/views.py index 7bf2f87a6..39c922eb6 100644 --- a/netbox/core/api/views.py +++ b/netbox/core/api/views.py @@ -1,5 +1,5 @@ from django.shortcuts import get_object_or_404 - +from django.utils.translation import gettext_lazy as _ from rest_framework.decorators import action from rest_framework.exceptions import PermissionDenied from rest_framework.response import Response @@ -33,10 +33,11 @@ class DataSourceViewSet(NetBoxModelViewSet): """ Enqueue a job to synchronize the DataSource. """ - if not request.user.has_perm('core.sync_datasource'): - raise PermissionDenied("Syncing data sources requires the core.sync_datasource permission.") - datasource = get_object_or_404(DataSource, pk=pk) + + if not request.user.has_perm('core.sync_datasource', obj=datasource): + raise PermissionDenied(_("This user does not have permission to synchronize this data source.")) + datasource.enqueue_sync_job(request) serializer = serializers.DataSourceSerializer(datasource, context={'request': request})