mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
tt-rss: Allow selection of a domain name
Fixes: #2136 Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net> [james: Fix comment] Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
a912c867c8
commit
aaea6bf00e
@ -29,6 +29,13 @@ def parse_arguments():
|
||||
subparsers.add_parser('dump-database', help='Dump database to file')
|
||||
subparsers.add_parser('restore-database',
|
||||
help='Restore database from file')
|
||||
subparsers.add_parser('get-domain',
|
||||
help='Get the domain set for Tiny Tiny RSS.')
|
||||
set_domain = subparsers.add_parser(
|
||||
'set-domain', help='Set the domain to be used by Tiny Tiny RSS.')
|
||||
set_domain.add_argument(
|
||||
'domain_name',
|
||||
help='The domain name that will be used by Tiny Tiny RSS.')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
@ -40,6 +47,29 @@ def subcommand_pre_setup(_):
|
||||
['tt-rss tt-rss/database-type string pgsql'])
|
||||
|
||||
|
||||
def subcommand_get_domain(_):
|
||||
"""Get the domain set for Tiny Tiny RSS."""
|
||||
aug = load_augeas()
|
||||
|
||||
from urllib.parse import urlparse
|
||||
for match in aug.match('/files' + CONFIG_FILE + '/define'):
|
||||
if aug.get(match) == 'SELF_URL_PATH':
|
||||
url = aug.get(match + '/value').strip("'")
|
||||
print(urlparse(url).netloc)
|
||||
|
||||
|
||||
def subcommand_set_domain(args):
|
||||
"""Set the domain to be used by Tiny Tiny RSS."""
|
||||
url = f"'https://{args.domain_name}/tt-rss/'"
|
||||
aug = load_augeas()
|
||||
|
||||
for match in aug.match('/files' + CONFIG_FILE + '/define'):
|
||||
if aug.get(match) == 'SELF_URL_PATH':
|
||||
aug.set(match + '/value', url)
|
||||
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_setup(_):
|
||||
"""Setup Tiny Tiny RSS configuration."""
|
||||
aug = load_augeas()
|
||||
@ -49,9 +79,7 @@ def subcommand_setup(_):
|
||||
skip_self_url_path_exists = False
|
||||
|
||||
for match in aug.match('/files' + CONFIG_FILE + '/define'):
|
||||
if aug.get(match) == 'SELF_URL_PATH':
|
||||
aug.set(match + '/value', "'http://localhost/tt-rss/'")
|
||||
elif aug.get(match) == 'PLUGINS':
|
||||
if aug.get(match) == 'PLUGINS':
|
||||
aug.set(match + '/value', "'auth_remote, note'")
|
||||
elif aug.get(match) == '_SKIP_SELF_URL_PATH_CHECKS':
|
||||
skip_self_url_path_exists = True
|
||||
|
||||
@ -102,6 +102,13 @@ class TTRSSApp(app_module.App):
|
||||
super().enable()
|
||||
actions.superuser_run('ttrss', ['enable-api-access'])
|
||||
|
||||
# Try to set the domain to one of the available TLS domains
|
||||
domain = get_domain()
|
||||
if not domain or domain == 'localhost':
|
||||
from plinth.modules import names
|
||||
domain = next(names.get_available_tls_domains(), None)
|
||||
set_domain(domain)
|
||||
|
||||
|
||||
class TTRSSBackupRestore(BackupRestore):
|
||||
"""Component to backup/restore TT-RSS"""
|
||||
@ -136,3 +143,14 @@ def force_upgrade(helper, packages):
|
||||
helper.install(['tt-rss'], force_configuration='new')
|
||||
actions.superuser_run('ttrss', ['setup'])
|
||||
return True
|
||||
|
||||
|
||||
def get_domain():
|
||||
"""Read TLS domain from tt-rss config file."""
|
||||
return actions.superuser_run('ttrss', ['get-domain']).strip()
|
||||
|
||||
|
||||
def set_domain(domain):
|
||||
"""Set the TLS domain in tt-rss configuration file."""
|
||||
if domain:
|
||||
actions.superuser_run('ttrss', ['set-domain', domain])
|
||||
|
||||
@ -5,8 +5,6 @@ URLs for the Tiny Tiny RSS module.
|
||||
|
||||
from django.urls import re_path
|
||||
|
||||
from plinth.views import AppView
|
||||
from .views import TTRSSAppView
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^apps/ttrss/$', AppView.as_view(app_id='ttrss'), name='index')
|
||||
]
|
||||
urlpatterns = [re_path(r'^apps/ttrss/$', TTRSSAppView.as_view(), name='index')]
|
||||
|
||||
28
plinth/modules/ttrss/views.py
Normal file
28
plinth/modules/ttrss/views.py
Normal file
@ -0,0 +1,28 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plinth.forms import TLSDomainForm
|
||||
from plinth.modules import ttrss
|
||||
from plinth.views import AppView
|
||||
|
||||
|
||||
class TTRSSAppView(AppView):
|
||||
app_id = 'ttrss'
|
||||
form_class = TLSDomainForm
|
||||
|
||||
def get_initial(self):
|
||||
"""Return the values to fill in the form."""
|
||||
initial = super().get_initial()
|
||||
initial['domain'] = ttrss.get_domain()
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Change the domain of TT-RSS app."""
|
||||
data = form.cleaned_data
|
||||
if ttrss.get_domain() != data['domain']:
|
||||
ttrss.set_domain(data['domain'])
|
||||
messages.success(self.request, _('Configuration updated'))
|
||||
|
||||
return super().form_valid(form)
|
||||
Loading…
x
Reference in New Issue
Block a user