mirror of
https://github.com/ae-utbm/sith.git
synced 2025-01-31 03:11:10 +00:00
Set the moderator when moderating news
This commit is contained in:
parent
4a2fdb8ef7
commit
96f5874786
@ -45,6 +45,7 @@ class NewsController(ControllerBase):
|
|||||||
news = self.get_object_or_exception(News, id=news_id)
|
news = self.get_object_or_exception(News, id=news_id)
|
||||||
if not news.is_moderated:
|
if not news.is_moderated:
|
||||||
news.is_moderated = True
|
news.is_moderated = True
|
||||||
|
news.moderator = self.context.request.user
|
||||||
news.save()
|
news.save()
|
||||||
|
|
||||||
@route.delete(
|
@route.delete(
|
||||||
|
@ -136,13 +136,21 @@ class TestModerateNews:
|
|||||||
# The API call should work even if the news is initially moderated.
|
# The API call should work even if the news is initially moderated.
|
||||||
# In the latter case, the result should be a noop, rather than an error.
|
# In the latter case, the result should be a noop, rather than an error.
|
||||||
news = baker.make(News, is_moderated=news_is_moderated)
|
news = baker.make(News, is_moderated=news_is_moderated)
|
||||||
|
initial_moderator = news.moderator
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
response = client.patch(
|
response = client.patch(
|
||||||
reverse("api:moderate_news", kwargs={"news_id": news.id})
|
reverse("api:moderate_news", kwargs={"news_id": news.id})
|
||||||
)
|
)
|
||||||
|
# if it wasn't moderated, it should now be moderated and the moderator should
|
||||||
|
# be the user that made the request.
|
||||||
|
# If it was already moderated, it should be a no-op, but not an error
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
news.refresh_from_db()
|
news.refresh_from_db()
|
||||||
assert news.is_moderated
|
assert news.is_moderated
|
||||||
|
if not news_is_moderated:
|
||||||
|
assert news.moderator == user
|
||||||
|
else:
|
||||||
|
assert news.moderator == initial_moderator
|
||||||
|
|
||||||
def test_moderation_forbidden(self, client: Client):
|
def test_moderation_forbidden(self, client: Client):
|
||||||
user = baker.make(User)
|
user = baker.make(User)
|
||||||
|
Loading…
Reference in New Issue
Block a user