Skip to content

Commit

Permalink
add the ability to disable subscribers
Browse files Browse the repository at this point in the history
Closes-Bug: #1278014

Change-Id: I2fda89edb4f579dcb4a83b7872a3bc663a09ba84
  • Loading branch information
sir-sigurd committed Feb 10, 2014
1 parent 63eec25 commit a1a79be
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -9,5 +9,5 @@ horizon>=2013.2
-f http://tarballs.kickstand-project.org/python-payloadclient/python-payloadclient-0.0.1a2.tar.gz#egg=python-payloadclient-0.0.1a2
python-payloadclient>=0.0.1a2

-f http://tarballs.kickstand-project.org/python-ripcordclient/python-ripcordclient-0.0.1a1.tar.gz#egg=python-ripcordclient-0.0.1a1
python-ripcordclient>=0.0.1a1
-f http://tarballs.kickstand-project.org/python-ripcordclient/python-ripcordclient-0.0.1a2.tar.gz#egg=python-ripcordclient-0.0.1a2
python-ripcordclient>=0.0.1a2
30 changes: 29 additions & 1 deletion wildcard/dashboards/project/subscribers/tables.py
Expand Up @@ -34,6 +34,29 @@ class EditSubscriberLink(tables.LinkAction):
classes = ("ajax-modal", "btn-edit")


class ToggleEnabled(tables.BatchAction):
name = "toggle"
action_present = (_("Enable"), _("Disable"))
action_past = (_("Enabled"), _("Disabled"))
data_type_singular = _("Subscriber")
data_type_plural = _("Subscribers")
classes = ("btn-toggle",)

def allowed(self, request, subscriber=None):
if subscriber:
self.disabled = subscriber.disabled
self.current_present_action = int(not self.disabled)
return True

def action(self, request, obj_id):
api.ripcord.subscriber_update(
request,
obj_id,
disabled=not self.disabled
)
self.current_past_action = int(not self.disabled)


class DeleteSubscribersAction(tables.DeleteAction):
data_type_singular = _("Subscriber")
data_type_plural = _("Subscribers")
Expand All @@ -52,11 +75,16 @@ class SubscribersTable(tables.DataTable):
)
domain = tables.Column('domain', verbose_name=_("Domain"))
rpid = tables.Column('rpid', verbose_name=_("Remote Party ID"))
disabled = tables.Column("disabled", verbose_name=_("Disabled"))

class Meta:
name = "subscribers"
verbose_name = _("Subscribers")
row_actions = (EditSubscriberLink, DeleteSubscribersAction)
row_actions = (
EditSubscriberLink,
ToggleEnabled,
DeleteSubscribersAction,
)
table_actions = (CreateSubscriberLink, DeleteSubscribersAction)

def get_object_id(self, datum):
Expand Down
42 changes: 42 additions & 0 deletions wildcard/dashboards/project/subscribers/tests.py
Expand Up @@ -122,3 +122,45 @@ def test_delete(self):
res = self.client.post(INDEX_URL, form_data)

self.assertRedirectsNoFollow(res, INDEX_URL)

@test.create_stubs({api.ripcord: ('subscriber_update', 'subscriber_list')})
def test_enable_subscriber(self):
subscriber = self.subscribers.get(uuid='1')
subscriber.disabled = True

api.ripcord.subscriber_list(
IsA(http.HttpRequest),
).AndReturn(self.subscribers.list())
api.ripcord.subscriber_update(
IsA(http.HttpRequest),
subscriber.uuid,
disabled=False
).AndReturn(None)

self.mox.ReplayAll()

formData = {'action': 'subscribers__toggle__%s' % subscriber.uuid}
res = self.client.post(INDEX_URL, formData)

self.assertRedirectsNoFollow(res, INDEX_URL)

@test.create_stubs({api.ripcord: ('subscriber_update', 'subscriber_list')})
def test_disable_subscriber(self):
subscriber = self.subscribers.get(uuid="1")
subscriber.disabled = False

api.ripcord.subscriber_list(
IsA(http.HttpRequest),
).AndReturn(self.subscribers.list())
api.ripcord.subscriber_update(
IsA(http.HttpRequest),
subscriber.uuid,
disabled=True
).AndReturn(None)

self.mox.ReplayAll()

formData = {'action': 'subscribers__toggle__%s' % subscriber.uuid}
res = self.client.post(INDEX_URL, formData)

self.assertRedirectsNoFollow(res, INDEX_URL)

0 comments on commit a1a79be

Please sign in to comment.