mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +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):
|
def __str__(self):
|
||||||
return str(self.user)
|
return str(self.user)
|
||||||
|
|
||||||
|
def is_owned_by(self, user):
|
||||||
|
return user.is_owner(self.trombi)
|
||||||
|
|
||||||
def make_memberships(self):
|
def make_memberships(self):
|
||||||
self.memberships.all().delete()
|
self.memberships.all().delete()
|
||||||
for m in self.user.memberships.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE).order_by('end_date'):
|
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">
|
<img src="{{ file }}" alt="" style="max-width: 100px">
|
||||||
</div>
|
</div>
|
||||||
<div>{{ u.user.get_display_name() }}</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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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]+)/edit$', TrombiEditView.as_view(), name='edit'),
|
||||||
url(r'^(?P<trombi_id>[0-9]+)/moderate_comments$', TrombiModerateCommentsView.as_view(), name='moderate_comments'),
|
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<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<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]+)/new_comment$', TrombiCommentCreateView.as_view(), name='new_comment'),
|
||||||
url(r'^(?P<user_id>[0-9]+)/profile$', UserTrombiProfileView.as_view(), name='user_profile'),
|
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'
|
pk_url_kwarg = 'trombi_id'
|
||||||
current_tab = "admin_tools"
|
current_tab = "admin_tools"
|
||||||
|
|
||||||
class TrombiDeleteUserView(CanEditPropMixin, SingleObjectMixin, RedirectView):
|
class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
|
||||||
model = Trombi
|
model = TrombiUser
|
||||||
pk_url_kwarg = 'trombi_id'
|
pk_url_kwarg = 'user_id'
|
||||||
permanent = False
|
template_name = 'core/delete_confirm.jinja'
|
||||||
|
current_tab = "admin_tools"
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get_success_url(self):
|
||||||
self.object = self.get_object()
|
return reverse('trombi:detail', kwargs={'trombi_id': self.object.trombi.id}) + "?qn_success"
|
||||||
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")
|
|
||||||
|
|
||||||
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
||||||
model = Trombi
|
model = Trombi
|
||||||
|
Loading…
Reference in New Issue
Block a user