Permalink
Browse files

Canceling for dissociation request state

  • Loading branch information...
1 parent 8dc7236 commit 5a7a7b1e96d5e7ee0dd3354d535b996731fcbb94 @guaq guaq committed Sep 29, 2013
View
14 membership/models.py
@@ -316,6 +316,20 @@ def request_dissociation(self, user):
self.save()
log_change(self, user, change_message="Dissociation requested")
+ def cancel_dissociation_request(self, user):
+ if self.status != 'S':
+ raise MembershipOperationError("A membership has to be in dissociation requested state for the state to be canceled.")
+ if user == None:
+ msg = "Membership.cancel_dissociation_request() needs user object as a parameter"
+ logger.critical("%s" % traceback.format_exc())
+ logger.critical(msg)
+ raise MembershipOperationError(msg)
+
+ self.status = 'A'
+ self.dissociation_requested = None
+ self.save()
+ log_change(self, user, change_message="Dissociation request state reverted")
+
def dissociate(self, user):
if self.status not in ('A', 'S'):
raise MembershipOperationError("A membership from other state than dissociation requested or approved can't be dissociated.")
View
16 membership/templates/membership/membership_cancel_dissociation_request.html
@@ -0,0 +1,16 @@
+{% extends "base.html" %}
+{% load i18n %}
+{% load comments %}
+
+{% block content %}
+<p>
+ {% trans "Canceling dissociation request for member" %} <strong>{{ membership }} ({{ membership.id }})</strong>.
+</p>
+<form method="POST">{% csrf_token %}
+{{ form.as_p }}
+<p>
+ <input id="submit_button" type="submit" value="{% trans "Move member back to approved state" %}" />
+</p>
+
+</form>
+{% endblock %}
View
27 membership/templates/membership/membership_edit_inline.html
@@ -36,14 +36,31 @@
<hr />
<h2>{% trans "Actions" %}</h2>
+{% if membership.status == "A" %}
+ <a href="{% url services.views.alias_add_for_member membership.id %}">{% trans "Add an alias" %}</a>
+ <a href="{% url membership_request_dissociation membership.id %}">{% trans "Request dissociation" %}</a>
+{% endif %}
+
+{% if membership.status == "S" %}
+ <a href="{% url membership_cancel_dissociation_request membership.id %}">{% trans "Cancel dissociation request" %}</a>
+{% endif %}
+
+{% if membership.status == "A" or membership.status == "S" %}
+ <a href="{% url membership_dissociate membership.id %}">{% trans "Dissociate" %}</a>
+{% endif %}
+
{% if membership.status != "D" %}
-<a href="{% url services.views.alias_add_for_member membership.id %}">{% trans "Add an alias" %}</a>
-<a href="{% url membership_request_dissociation membership.id %}">{% trans "Request dissociation" %}</a>
-<a href="{% url membership_dissociate membership.id %}">{% trans "Dissociate" %}</a>
-<a href="{% url membership_delete membership.id %}">{% trans "Delete" %}</a>
-{% if not membership.organization %}<a href="{% url membership_convert_to_organization membership.id %}">{% trans "Convert to an organization" %}</a>{% endif %}
+ <a href="{% url membership_delete membership.id %}">{% trans "Delete" %}</a>
+{% endif %}
+
+{% if membership.status == "A" and not membership.organization %}
+ <a href="{% url membership_convert_to_organization membership.id %}">
+ {% trans "Convert to an organization" %}
+ </a>
{% endif %}
+
+
<h2>{% trans "Aliases" %}</h2>
<ul>{% for alias in membership.alias_set.all %}
<li>
View
36 membership/tests.py
@@ -1016,6 +1016,42 @@ def test_dissociated_request_dissociation(self):
m.dissociate(self.user)
self.assertRaises(MembershipOperationError, m.request_dissociation, self.user)
+class MemberCancelDissociationRequestTest(TestCase):
+ fixtures = ['membership_fees.json', 'test_user.json']
+ def setUp(self):
+ self.user = User.objects.get(id=1)
+
+ def test_application_request_dissociation(self):
+ m = create_dummy_member('N')
+ self.assertRaises(MembershipOperationError, m.cancel_dissociation_request, self.user)
+
+ def test_preapproved_request_dissociation(self):
+ m = create_dummy_member('N')
+ m.preapprove(self.user)
+ self.assertRaises(MembershipOperationError, m.cancel_dissociation_request, self.user)
+
+ def test_approved_request_dissociation(self):
+ m = create_dummy_member('N')
+ m.preapprove(self.user)
+ m.approve(self.user)
+ self.assertRaises(MembershipOperationError, m.cancel_dissociation_request, self.user)
+
+ def test_approved_request_dissociation(self):
+ m = create_dummy_member('N')
+ m.preapprove(self.user)
+ m.approve(self.user)
+ m.request_dissociation(self.user)
+ m.cancel_dissociation_request(self.user)
+ self.assertIsNone(m.dissociation_requested)
+
+ def test_dissociated_request_dissociation(self):
+ m = create_dummy_member('N')
+ m.preapprove(self.user)
+ m.approve(self.user)
+ m.request_dissociation(self.user)
+ m.dissociate(self.user)
+ self.assertRaises(MembershipOperationError, m.cancel_dissociation_request, self.user)
+
class MemberDissociationTest(TestCase):
fixtures = ['membership_fees.json', 'test_user.json']
def setUp(self):
View
1 membership/urls.py
@@ -44,6 +44,7 @@
url(r'memberships/delete/(\d+)/$', 'membership.views.membership_delete', name='membership_delete'),
url(r'memberships/dissociate/(\d+)/$', 'membership.views.membership_dissociate', name='membership_dissociate'),
url(r'memberships/request_dissociation/(\d+)/$', 'membership.views.membership_request_dissociation', name='membership_request_dissociation'),
+ url(r'memberships/cancel_dissociation_request/(\d+)/$', 'membership.views.membership_cancel_dissociation_request', name='membership_cancel_dissociation_request'),
url(r'memberships/convert_to_an_organization/(\d+)/$', 'membership.views.membership_convert_to_organization', name='membership_convert_to_organization'),
url(r'bills/edit/(\d+)/$', 'membership.views.bill_edit', name='bill_edit'),
View
25 membership/views.py
@@ -886,6 +886,31 @@ class ConfirmForm(Form):
'membership': membership },
context_instance=RequestContext(request))
+@permission_required('membership.request_dissociation_for_member')
+@transaction.commit_on_success
+def membership_cancel_dissociation_request(request, id, template_name='membership/membership_cancel_dissociation_request.html'):
+ membership = get_object_or_404(Membership, id=id)
+ class ConfirmForm(Form):
+ confirm = BooleanField(label=_('To confirm state change, you must check this box:'),
+ required=True)
+
+ if request.method == 'POST':
+ form = ConfirmForm(request.POST)
+ if form.is_valid():
+ f = form.cleaned_data
+ membership_str = unicode(membership)
+ membership.cancel_dissociation_request(request.user)
+ messages.success(request, unicode(_('Member %s successfully transferred back to approved state.') % membership_str))
+ logger.info("User %s requested dissociation for member %s." % (request.user.username, membership))
+ return redirect('membership_edit', membership.id)
+ else:
+ form = ConfirmForm()
+
+ return render_to_response(template_name,
+ {'form': form,
+ 'membership': membership },
+ context_instance=RequestContext(request))
+
@permission_required('membership.manage_members')
@transaction.commit_on_success
def membership_convert_to_organization(request, id, template_name='membership/membership_convert_to_organization.html'):

0 comments on commit 5a7a7b1

Please sign in to comment.