mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
trombi: add safeguard on user deletion
Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
parent
f85ce96225
commit
38026025af
@ -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'):
|
||||
|
@ -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>
|
||||
|
@ -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'),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user