Skip to content

Commit

Permalink
fix add entry route
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoolano committed Jan 23, 2024
1 parent a6a27a7 commit e7aadef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions feedi/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def autocomplete():
# we can reasonably assume this is a url

options += [
('Add to feed', flask.url_for('entry_add', url=term), 'fas fa-download'),
('View in reader', flask.url_for('entry_add', url=term, redirect=1), 'fas fa-book-reader'),
('Add to feed', flask.url_for('entry_add', url=term), 'fas fa-download', 'POST'),
('View in reader', flask.url_for('entry_add', url=term, redirect=1), 'fas fa-book-reader', 'POST'),
('Send to backlog', flask.url_for('entry_backlog_url', url=term), 'fas fa-archive', 'POST'),
('Discover feed', flask.url_for('feed_add', url=term), 'fas fa-rss'),
]
Expand Down Expand Up @@ -485,8 +485,7 @@ def feed_sync(feed_name):
return response


# this should be a .post but that complicates utilization from hyperscipt
@app.get("/entries/")
@app.post("/entries/")
@login_required
def entry_add():
"""
Expand All @@ -495,16 +494,20 @@ def entry_add():
"""
# TODO sanitize?
url = flask.request.args['url']
redirect = flask.request.args.get('redirect')

try:
entry = models.Entry.from_url(current_user.id, url)
except Exception:
return redirect_response(url)
if redirect:
return redirect_response(url)
else:
return 'failed to parse entry', 500

db.session.add(entry)
db.session.commit()

if flask.request.args.get('redirect'):
if redirect:
return redirect_response(flask.url_for('entry_view', id=entry.id))
else:
return '', 204
Expand Down
4 changes: 2 additions & 2 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ def test_add_external_entry(client):
mock_request(content_url, body=body)

# add a standalone entry for that url, check that browser redirects to view content
response = client.get(
response = client.post(
'/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True)
assert response.status_code == 200
assert 'reclaiming-the-web' in response.text
assert 'I had some ideas of what I wanted' in response.text

# add same url again, verify that redirected entry url is the same as before
previous_entry_url = response.request.path
response = client.get(
response = client.post(
'/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True)
assert response.status_code == 200
assert response.request.path == previous_entry_url
Expand Down

0 comments on commit e7aadef

Please sign in to comment.