Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
2c13bf22
Commit
2c13bf22
authored
Jul 16, 2019
by
Okhin
Browse files
Adding the unpublish api call
parent
85ceb07a
Changes
2
Hide whitespace changes
Inline
Side-by-side
apps/rp/models.py
View file @
2c13bf22
...
@@ -174,6 +174,14 @@ class Article(models.Model):
...
@@ -174,6 +174,14 @@ class Article(models.Model):
else
:
else
:
return
self
.
status
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'
,
@
transition
(
field
=
status
,
source
=
'NEW'
,
target
=
'NEW'
,
permission
=
"rp.can_vote"
)
permission
=
"rp.can_vote"
)
@
transition
(
field
=
status
,
source
=
'DRAFT'
,
target
=
'DRAFT'
,
@
transition
(
field
=
status
,
source
=
'DRAFT'
,
target
=
'DRAFT'
,
...
...
apps/rp/tests/test_article.py
View file @
2c13bf22
...
@@ -62,6 +62,11 @@ class TestArticle(TestCase):
...
@@ -62,6 +62,11 @@ class TestArticle(TestCase):
self
.
article
.
refresh_from_db
()
self
.
article
.
refresh_from_db
()
assert
self
.
article
.
title
!=
old_title
assert
self
.
article
.
title
!=
old_title
def
test_unpublish
(
self
):
a
=
ArticleFactory
(
status
=
'PUBLISHED'
)
a
.
unpublish
()
assert
a
.
status
==
'DRAFT'
class
TestArticleViews
(
TestCase
):
class
TestArticleViews
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -336,3 +341,17 @@ class TestArticleApi(TestCase):
...
@@ -336,3 +341,17 @@ class TestArticleApi(TestCase):
r
=
self
.
client
.
post
(
'/api/articles/{}/unset-priority/'
.
format
(
a
.
id
))
r
=
self
.
client
.
post
(
'/api/articles/{}/unset-priority/'
.
format
(
a
.
id
))
assert
r
.
status_code
==
200
assert
r
.
status_code
==
200
assert
r
.
data
[
'priority'
]
is
False
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'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment