Have a shortcut that appears only to logged in users

I’m looking for how to have an app that’s I have defined in the custom-shortcuts.json appear on the FreedomBox homepage ONLY AFTER a user has logged in.

Is this possible without me having to create a python app.

Unfortunately, we are not picking up the login_required field from custom shortcuts file and passing it on to the framework. So, this will require a tiny change to the framework in frontpage.py::add_custom_shortcuts(). Created an issue: https://salsa.debian.org/freedombox-team/freedombox/-/issues/1968 . Have a stab at it if you know Python.

Ok, so I found the file

ls /usr/lib/python3/dist-packages/plinth/frontpage.py

, and in the function add_custom_shortcuts(), I changed the line

component = Shortcut(component_id, shortcut['name'],
                             shortcut['short_description'],
                             icon=shortcut['icon_url'], url=web_app_url)

to

component = Shortcut(component_id, shortcut['name'],
                             shortcut['short_description'],
                             icon=shortcut['icon_url'], url=web_app_url,
                             login_required=shortcut['login_required'])

and restarted plinth with

sudo systemctl restart plinth

and it seems to work. One question. Will these changes be permanent, or will I have to make them everytime I update/upgrade plinth.

2 Likes

These changes will be overridden when new version of FreedomBox is automatically installed. The best thing to do is submit your change to the code repository as a merge request. Before you do:

  • Make sure that when login_required property is not provided, it is assumed to be False by doing shortcut.get(‘login_required’, False).
  • Run and fix any unit tests.

Checkout HACKING.md and CONTRIBUTORS.md for more details.