Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.16.x] [Bug] Ensure links are prepended with base URL on receipt (#8367) #8370

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

checkMinPythonVersion()

INVENTREE_NEWS_URL = 'https://inventree.org/news/feed.atom'
INVENTREE_BASE_URL = 'https://inventree.org'
INVENTREE_NEWS_URL = f'{INVENTREE_BASE_URL}/news/feed.atom'

# Determine if we are running in "test" mode e.g. "manage.py test"
TESTING = 'test' in sys.argv or 'TESTING' in os.environ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(set_default_currency),
migrations.RunPython(set_default_currency, reverse_code=migrations.RunPython.noop),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 4.2.16 on 2024-10-26 00:24

from django.conf import settings
from django.db import migrations

import logging

logger = logging.getLogger('inventree')


def update_news_feed_urls(apps, schema_editor):
"""Update and validate the news feed URLs."""

from common.models import NewsFeedEntry

n = 0

for entry in NewsFeedEntry.objects.all():
if entry.link and entry.link.startswith('/'):
entry.link = settings.INVENTREE_BASE_URL + entry.link
entry.save()
n += 1

if n > 0:
logger.info("Updated link for %s NewsFeedEntry objects", n)


class Migration(migrations.Migration):

dependencies = [
('common', '0030_barcodescanresult'),
]

operations = [
migrations.RunPython(
update_news_feed_urls,
reverse_code=migrations.RunPython.noop
)
]
4 changes: 4 additions & 0 deletions src/backend/InvenTree/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def update_news_feed():
if entry.id in id_list:
continue

# Enforce proper links for the entries
if entry.link and str(entry.link).startswith('/'):
entry.link = settings.INVENTREE_BASE_URL + str(entry.link)

# Create entry
try:
NewsFeedEntry.objects.create(
Expand Down