Commit 12884ba6 authored by okhin's avatar okhin 🚴

Merge branch...

Merge branch '57-d-apres-les-transitions-possibles-un-article-publie-est-fortement-limite' into 'rp2'

Resolve "D'après les transitions possibles, un article publié est fortement limité"

See merge request !51
parents 85ceb07a 9bae6017
Pipeline #2662 passed with stages
in 3 minutes and 43 seconds
......@@ -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',
......
......@@ -28,9 +28,17 @@
<span class="btn-group" role="group" aria-label="Actions">
{% if object.status == 'PUBLISHED' %}
<a class="btn btn-outline-danger" href="{% url 'rp:article-edit' object.id %}">Edit</a>
{% if perms.rp.can_change_status %}
<a class="btn btn-outline-default" href="{% url 'api:article-unpublish' object.id %}">UnPublish</a>
<a class="btn btn-outline-danger" href="{% url 'api:article-reject' object.id %}">Reject</a>
{% endif %}
{% else %}
<a class="btn btn-outline-primary" href="{% url 'rp:article-edit' object.id %}">Edit</a>
<a class="btn btn-outline-warning" href="#">Publish</a>
{% if perms.rp.can_change_status %}
<a class="btn btn-outline-warning" href="{% url 'api:article-publish' object.id %}">Publish</a>
<a class="btn btn-outline-danger" href="{% url 'api:article-reject' object.id %}">Reject</a>
<a class="btn btn-outline-default" href="{% url 'api:article-recover' object.id %}">Recover</a>
{% endif %}
{% endif %}
</span>
</div>
......@@ -65,6 +73,12 @@
<a target="mailto:{{ article.created_by.user.email }}"><span class="glyphicon glyphicon-envelope" aria-label="{{ _("Contact this user by email")}}"></span>
</p>
<p>{{object.extracts |markdown}}</p>
{% if perms.rp.can_vote %}
<span>
<a href="{% url 'api:upvote' object.id %}" class="btn btn-outline-default">+1</a>
<a href="{% url 'api:downvote' object.id %}" class="btn btn-outline-default">-1</a>
</span>
{% endif %}
</div>
</div>
......
......@@ -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