Commit 2c13bf22 authored by okhin's avatar okhin 🚴

Adding the unpublish api call

parent 85ceb07a
......@@ -174,6 +174,14 @@ class Article(models.Model):
else:
return self.status
@transition(field=status, source='PUBLISHED', target='DRAFT',
permission="rp.can_change_status")
def unpublish(self):
"""
Unpublish an article from the RP, and reset it back to a _DRAFT_.
"""
pass
@transition(field=status, source='NEW', target='NEW',
permission="rp.can_vote")
@transition(field=status, source='DRAFT', target='DRAFT',
......
......@@ -62,6 +62,11 @@ class TestArticle(TestCase):
self.article.refresh_from_db()
assert self.article.title != old_title
def test_unpublish(self):
a = ArticleFactory(status='PUBLISHED')
a.unpublish()
assert a.status == 'DRAFT'
class TestArticleViews(TestCase):
def setUp(self):
......@@ -336,3 +341,17 @@ class TestArticleApi(TestCase):
r = self.client.post('/api/articles/{}/unset-priority/'.format(a.id))
assert r.status_code == 200
assert r.data['priority'] is False
def test_api_unpublish_unauth(self):
a = ArticleFactory(status='PUBLISHED')
r = self.client.post('/api/articles/{}/unpublish/'.format(a.id))
assert r.status_code == 401
def test_api_unpublish(self):
self.jedi.user_permissions.add(Permission.objects.get(
codename='can_change_status'))
self.client.force_login(self.jedi)
a = ArticleFactory(status='PUBLISHED')
r = self.client.post('/api/articles/{}/unpublish/'.format(a.id))
assert r.status_code == 200
assert r.data['status'] == 'DRAFT'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment