trombi: add safeguard on user deletion

Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
Skia 2017-06-13 00:35:49 +02:00
parent f85ce96225
commit 38026025af
4 changed files with 12 additions and 12 deletions

View File

@ -99,6 +99,9 @@ class TrombiUser(models.Model):
def __str__(self):
return str(self.user)
def is_owned_by(self, user):
return user.is_owner(self.trombi)
def make_memberships(self):
self.memberships.all().delete()
for m in self.user.memberships.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE).order_by('end_date'):

View File

@ -25,7 +25,7 @@
<img src="{{ file }}" alt="" style="max-width: 100px">
</div>
<div>{{ u.user.get_display_name() }}</div>
<div><a href="{{ url('trombi:delete_user', trombi_id=object.id, user_id=u.id) }}">{% trans %}Delete{% endtrans %}</a></div>
<div><a href="{{ url('trombi:delete_user', user_id=u.id) }}">{% trans %}Delete{% endtrans %}</a></div>
</div>
{% endfor %}
</div>

View File

@ -31,7 +31,7 @@ urlpatterns = [
url(r'^(?P<trombi_id>[0-9]+)/edit$', TrombiEditView.as_view(), name='edit'),
url(r'^(?P<trombi_id>[0-9]+)/moderate_comments$', TrombiModerateCommentsView.as_view(), name='moderate_comments'),
url(r'^(?P<comment_id>[0-9]+)/moderate$', TrombiModerateCommentView.as_view(), name='moderate_comment'),
url(r'^(?P<trombi_id>[0-9]+)/delete/(?P<user_id>[0-9]+)$', TrombiDeleteUserView.as_view(), name='delete_user'),
url(r'^user/(?P<user_id>[0-9]+)/delete$', TrombiDeleteUserView.as_view(), name='delete_user'),
url(r'^(?P<trombi_id>[0-9]+)$', TrombiDetailView.as_view(), name='detail'),
url(r'^(?P<user_id>[0-9]+)/new_comment$', TrombiCommentCreateView.as_view(), name='new_comment'),
url(r'^(?P<user_id>[0-9]+)/profile$', UserTrombiProfileView.as_view(), name='user_profile'),

View File

@ -118,17 +118,14 @@ class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailVie
pk_url_kwarg = 'trombi_id'
current_tab = "admin_tools"
class TrombiDeleteUserView(CanEditPropMixin, SingleObjectMixin, RedirectView):
model = Trombi
pk_url_kwarg = 'trombi_id'
permanent = False
class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
model = TrombiUser
pk_url_kwarg = 'user_id'
template_name = 'core/delete_confirm.jinja'
current_tab = "admin_tools"
def get(self, request, *args, **kwargs):
self.object = self.get_object()
user = get_object_or_404(TrombiUser, id=self.kwargs['user_id'])
user.delete()
# See if we need to also delete the comments on the user, or if we keep them
return redirect(self.object.get_absolute_url()+"?qn_success")
def get_success_url(self):
return reverse('trombi:detail', kwargs={'trombi_id': self.object.trombi.id}) + "?qn_success"
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
model = Trombi