Teams: Improve handling of revoked keys and team deletion (Z#23163674) (#4414)

This commit is contained in:
Raphael Michel
2024-08-28 09:27:53 +02:00
committed by GitHub
parent 7f7c95aedb
commit 02a4ed4be2
2 changed files with 32 additions and 13 deletions
@@ -102,16 +102,24 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for t in team.active_tokens %} {% for t in tokens %}
<tr> <tr>
<td> <td {% if not t.active %}class="text-muted"{% endif %}>
{% if not t.active %}
<del>
{% endif %}
{{ t.name }} {{ t.name }}
{% if not t.active %}
</del>
{% endif %}
</td> </td>
<td class="text-right flip"> <td class="text-right flip">
<button type="submit" name="remove-token" value="{{ t.id }}" {% if t.active %}
class="btn btn-danger btn-sm btn-block"> <button type="submit" name="remove-token" value="{{ t.id }}"
<i class="fa fa-times"></i> {% trans "Remove" %} class="btn btn-danger btn-sm btn-block">
</button> <i class="fa fa-times"></i> {% trans "Remove" %}
</button>
{% endif %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
+18 -7
View File
@@ -686,14 +686,24 @@ class TeamDeleteView(OrganizerDetailViewMixin, OrganizerPermissionRequiredMixin,
try: try:
self.object.log_action('pretix.team.deleted', user=self.request.user) self.object.log_action('pretix.team.deleted', user=self.request.user)
self.object.delete() self.object.delete()
except ProtectedError: except ProtectedError as e:
messages.error( is_logs = any(isinstance(e, LogEntry) for e in e.protected_objects)
self.request, if is_logs:
_( messages.error(
'The team could not be deleted as some constraints (e.g. data created by ' self.request,
'plug-ins) do not allow it.' _(
"The team could not be deleted because the team or one of its API tokens is part of "
"historical audit logs."
)
)
else:
messages.error(
self.request,
_(
'The team could not be deleted as some constraints (e.g. data created by '
'plug-ins) do not allow it.'
)
) )
)
return redirect(success_url) return redirect(success_url)
messages.success(request, _('The selected team has been deleted.')) messages.success(request, _('The selected team has been deleted.'))
@@ -723,6 +733,7 @@ class TeamMemberView(OrganizerDetailViewMixin, OrganizerPermissionRequiredMixin,
ctx = super().get_context_data(**kwargs) ctx = super().get_context_data(**kwargs)
ctx['add_form'] = self.add_form ctx['add_form'] = self.add_form
ctx['add_token_form'] = self.add_token_form ctx['add_token_form'] = self.add_token_form
ctx['tokens'] = self.object.tokens.order_by("-active", "name", "pk")
return ctx return ctx
def _send_invite(self, instance): def _send_invite(self, instance):