Introduce 'sync' permission for synced data models

This commit is contained in:
jeremystretch 2023-02-07 15:24:29 -05:00
parent 5f73b55623
commit 283a7d6da8
3 changed files with 5 additions and 5 deletions

View File

@ -142,7 +142,7 @@ class ObjectSyncDataView(View):
""" """
qs = model.objects.all() qs = model.objects.all()
if hasattr(model.objects, 'restrict'): if hasattr(model.objects, 'restrict'):
qs = qs.restrict(request.user, 'change') qs = qs.restrict(request.user, 'sync')
obj = get_object_or_404(qs, **kwargs) obj = get_object_or_404(qs, **kwargs)
if not obj.data_file: if not obj.data_file:
@ -151,7 +151,7 @@ class ObjectSyncDataView(View):
obj.sync_data() obj.sync_data()
obj.save() obj.save()
messages.success(request, f"Synchronized data for {model._meta._verbose_name} {obj}.") messages.success(request, f"Synchronized data for {model._meta.verbose_name} {obj}.")
return redirect(obj.get_absolute_url()) return redirect(obj.get_absolute_url())
@ -161,7 +161,7 @@ class BulkSyncDataView(GetReturnURLMixin, BaseMultiObjectView):
Synchronize multiple instances of a model inheriting from SyncedDataMixin. Synchronize multiple instances of a model inheriting from SyncedDataMixin.
""" """
def get_required_permission(self): def get_required_permission(self):
return get_permission_for_model(self.queryset.model, 'change') return get_permission_for_model(self.queryset.model, 'sync')
def post(self, request): def post(self, request):
selected_objects = self.queryset.filter( selected_objects = self.queryset.filter(

View File

@ -89,7 +89,7 @@
{% if object.data_file and object.data_file.last_updated > object.data_synced %} {% if object.data_file and object.data_file.last_updated > object.data_synced %}
<div class="alert alert-warning" role="alert"> <div class="alert alert-warning" role="alert">
<i class="mdi mdi-alert"></i> Data is out of sync with upstream file (<a href="{{ object.data_file.get_absolute_url }}">{{ object.data_file }}</a>). <i class="mdi mdi-alert"></i> Data is out of sync with upstream file (<a href="{{ object.data_file.get_absolute_url }}">{{ object.data_file }}</a>).
{% if perms.extras.change_configcontext %} {% if perms.extras.sync_configcontext %}
<div class="float-end"> <div class="float-end">
<form action="{% url 'extras:configcontext_sync' pk=object.pk %}" method="post"> <form action="{% url 'extras:configcontext_sync' pk=object.pk %}" method="post">
{% csrf_token %} {% csrf_token %}

View File

@ -1,7 +1,7 @@
{% extends 'generic/object_list.html' %} {% extends 'generic/object_list.html' %}
{% block bulk_buttons %} {% block bulk_buttons %}
{% if perms.extras.change_configcontext %} {% if perms.extras.sync_configcontext %}
<button type="submit" name="_sync" formaction="{% url 'extras:configcontext_bulk_sync' %}" class="btn btn-primary btn-sm"> <button type="submit" name="_sync" formaction="{% url 'extras:configcontext_bulk_sync' %}" class="btn btn-primary btn-sm">
<i class="mdi mdi-sync" aria-hidden="true"></i> Sync Data <i class="mdi mdi-sync" aria-hidden="true"></i> Sync Data
</button> </button>