Skip to content

Commit

Permalink
Ensure links are prepended with base URL on receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 26, 2024
1 parent 331692b commit b5fa7be
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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),
]
39 changes: 39 additions & 0 deletions src/backend/InvenTree/common/migrations/0031_auto_20241026_0024.py
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.startswith('/'):
entry.link = settings.INVENTREE_BASE_URL + entry

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

0 comments on commit b5fa7be

Please sign in to comment.