Skip to content

Commit

Permalink
Change: Require change permissions to view traceback and history
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Dec 11, 2021
1 parent de65e62 commit e777875
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ <h5 class="card-header bg-danger">
<ul class="list-group list-group-flush text-danger">
{% for error in errors %}
<li class="list-group-item">
<a href="{% url "traceback" automation.id error.id %}">{{ error.status }} =
<a href="{% url "history" automation.id %}">{{ error.status }} =
&hellip; <span class="float-right">({{ error.id|unlocalize }})</span>
{% if error.data %}
<br /><small><code>{{ error.data|truncatechars:40 }}</code></small></a>
<br /><small><code>{{ error.data|truncatechars:40 }}</code></small>
{% endif %}
</li>
</a>
</li>
{% endfor %}
</ul>
</div>
Expand Down
35 changes: 25 additions & 10 deletions src/automations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# Create your views here.
import datetime

from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.mixins import (
LoginRequiredMixin,
PermissionRequiredMixin,
UserPassesTestMixin,
)
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.forms import BaseForm
Expand Down Expand Up @@ -93,12 +97,11 @@ def test_func(self):
return self.request.user.is_staff


class SuperUserMixin(LoginRequiredMixin, UserPassesTestMixin):
def test_func(self):
return self.request.user.is_superuser


class TaskDashboardView(UserIsStaff, TemplateView):
class TaskDashboardView(PermissionRequiredMixin, TemplateView):
permission_required = (
"automations.view_automationmodel",
"automations.view_automationtaskmodel",
)
template_name = "automations/dashboard.html"

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -154,7 +157,11 @@ def get_context_data(self, **kwargs):
return dict(automations=automations, timespan=_("Last %d days") % days)


class AutomationHistoryView(UserIsStaff, TemplateView):
class AutomationHistoryView(PermissionRequiredMixin, TemplateView):
permission_required = (
"automations.change_automationmodel",
"automations.change_automationtaskmodel",
)
template_name = "automations/history.html"

def build_tree(self, task):
Expand Down Expand Up @@ -192,7 +199,11 @@ def get_context_data(self, **kwargs):
)


class AutomationTracebackView(UserIsStaff, TemplateView):
class AutomationTracebackView(PermissionRequiredMixin, TemplateView):
permission_required = (
"automations.change_automationmodel",
"automations.change_automationtaskmodel",
)
template_name = "automations/traceback.html"

def get_context_data(self, **kwargs):
Expand All @@ -213,7 +224,11 @@ def get_context_data(self, **kwargs):
return dict()


class AutomationErrorView(UserIsStaff, TemplateView):
class AutomationErrorView(PermissionRequiredMixin, TemplateView):
permission_required = (
"automations.change_automationmodel",
"automations.change_automationtaskmodel",
)
template_name = "automations/error_report.html"

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit e777875

Please sign in to comment.