Skip to content

Commit 69b6536

Browse files
Ahtesham QuraishAhtesham Quraish
authored andcommitted
address the feedback
1 parent bdeedd1 commit 69b6536

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

news_events/tasks.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ def get_website_content_news():
5454
clear_views_cache()
5555

5656

57-
# Backward-compatible alias so any queued Celery tasks using the old name still work.
58-
get_articles_news = get_website_content_news
57+
@app.task(name="news_events.tasks.get_articles_news")
58+
def get_articles_news():
59+
"""Backward-compatible alias for get_website_content_news."""
60+
pipelines.articles_news_etl()
61+
clear_views_cache()
5962

6063

6164
@app.task(
@@ -105,5 +108,11 @@ def sync_website_content_to_news(self, content_id: int):
105108
raise
106109

107110

108-
# Backward-compatible alias so any queued Celery tasks using the old name still work.
109-
sync_article_to_news = sync_website_content_to_news
111+
@app.task(
112+
name="news_events.tasks.sync_article_to_news",
113+
autoretry_for=(Exception,),
114+
retry_kwargs={"max_retries": 3, "countdown": 5},
115+
)
116+
def sync_article_to_news(article_id: int):
117+
"""Backward-compatible alias for sync_website_content_to_news."""
118+
sync_website_content_to_news.apply(args=[article_id], throw=True)

website_content/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from named_enum import ExtendedEnum
44

5-
GROUP_STAFF_ARTICLE_EDITORS = "article_editors"
5+
GROUP_WEBSITE_CONTENT_EDITORS = "website_content_editors"
66

77

88
class WebsiteContentType(ExtendedEnum):

website_content/migrations/0003_add_editors_group.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
"""
2-
Ensure the article_editors Group exists in the database.
2+
Ensure the website_content_editors Group exists in the database.
33
4-
Reuses the same group name as the old articles app so that existing users
5-
already in the group retain their permissions without any manual intervention.
4+
If the legacy article_editors Group exists, copy its members into the new group
5+
so existing editors retain access after the rename.
66
"""
77

8-
from django.contrib.auth.models import Group
98
from django.db import migrations
109

11-
from website_content.constants import GROUP_STAFF_ARTICLE_EDITORS
10+
OLD_GROUP_NAME = "article_editors"
11+
NEW_GROUP_NAME = "website_content_editors"
1212

1313

14-
def add_editors_group(apps, schema_editor): # noqa: ARG001
15-
Group.objects.get_or_create(name=GROUP_STAFF_ARTICLE_EDITORS)
14+
def add_editors_group(apps, schema_editor):
15+
Group = apps.get_model("auth", "Group")
1616

17+
new_group, _ = Group.objects.get_or_create(name=NEW_GROUP_NAME)
18+
old_group = Group.objects.filter(name=OLD_GROUP_NAME).first()
1719

18-
def remove_editors_group(apps, schema_editor): # noqa: ARG001
19-
Group.objects.filter(name=GROUP_STAFF_ARTICLE_EDITORS).delete()
20+
if old_group and old_group.pk != new_group.pk:
21+
new_group.user_set.add(*old_group.user_set.all())
22+
23+
24+
def remove_editors_group(apps, schema_editor):
25+
Group = apps.get_model("auth", "Group")
26+
Group.objects.filter(name=NEW_GROUP_NAME).delete()
2027

2128

2229
class Migration(migrations.Migration):

website_content/permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from rest_framework.permissions import SAFE_METHODS, BasePermission
22

33
from learning_resources.permissions import is_admin_user
4-
from website_content.constants import GROUP_STAFF_ARTICLE_EDITORS
4+
from website_content.constants import GROUP_WEBSITE_CONTENT_EDITORS
55

66

77
def is_website_content_editor(request):
88
"""
9-
Return True if the request user belongs to the article_editors group.
9+
Return True if the request user belongs to the website_content_editors group.
1010
1111
Args:
1212
request (HTTPRequest): django request object
@@ -16,7 +16,7 @@ def is_website_content_editor(request):
1616
"""
1717
return (
1818
request.user is not None
19-
and request.user.groups.filter(name=GROUP_STAFF_ARTICLE_EDITORS).first()
19+
and request.user.groups.filter(name=GROUP_WEBSITE_CONTENT_EDITORS).first()
2020
is not None
2121
)
2222

0 commit comments

Comments
 (0)