Merge pull request #121 from taigaio/cancel-account-signal
Launching cancel_account signal when neededremotes/origin/enhancement/email-actions
commit
7da975d992
|
@ -44,6 +44,7 @@ from taiga.projects.serializers import StarredSerializer
|
||||||
from . import models
|
from . import models
|
||||||
from . import serializers
|
from . import serializers
|
||||||
from . import permissions
|
from . import permissions
|
||||||
|
from .signals import user_cancel_account as user_cancel_account_signal
|
||||||
|
|
||||||
|
|
||||||
class MembersFilterBackend(BaseFilterBackend):
|
class MembersFilterBackend(BaseFilterBackend):
|
||||||
|
@ -273,14 +274,21 @@ class UsersViewSet(ModelCrudViewSet):
|
||||||
max_age_cancel_account = getattr(settings, "MAX_AGE_CANCEL_ACCOUNT", None)
|
max_age_cancel_account = getattr(settings, "MAX_AGE_CANCEL_ACCOUNT", None)
|
||||||
user = get_user_for_token(serializer.data["cancel_token"], "cancel_account",
|
user = get_user_for_token(serializer.data["cancel_token"], "cancel_account",
|
||||||
max_age=max_age_cancel_account)
|
max_age=max_age_cancel_account)
|
||||||
|
|
||||||
except exc.NotAuthenticated:
|
except exc.NotAuthenticated:
|
||||||
raise exc.WrongArguments(_("Invalid, are you sure the token is correct?"))
|
raise exc.WrongArguments(_("Invalid, are you sure the token is correct?"))
|
||||||
|
|
||||||
|
if not user.is_active:
|
||||||
|
raise exc.WrongArguments(_("Invalid, are you sure the token is correct?"))
|
||||||
|
|
||||||
user.cancel()
|
user.cancel()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
def destroy(self, request, pk=None):
|
def destroy(self, request, pk=None):
|
||||||
user = self.get_object()
|
user = self.get_object()
|
||||||
self.check_permissions(request, "destroy", user)
|
self.check_permissions(request, "destroy", user)
|
||||||
|
stream = request.stream
|
||||||
|
request_data = stream is not None and stream.GET or None
|
||||||
|
user_cancel_account_signal.send(sender=user.__class__, user=user, request_data=request_data)
|
||||||
user.cancel()
|
user.cancel()
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||||
|
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
|
||||||
|
# Copyright (C) 2014 David Barragán <bameda@dbarragan.com>
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import django.dispatch
|
||||||
|
|
||||||
|
|
||||||
|
user_cancel_account = django.dispatch.Signal(providing_args=["user", "request_data"])
|
Loading…
Reference in New Issue