2021-04-22 21:46:02 +00:00
|
|
|
__filename__ = "webapp_accesskeys.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.2.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2021-04-22 21:46:02 +00:00
|
|
|
__status__ = "Production"
|
2021-06-26 11:27:14 +00:00
|
|
|
__module_group__ = "Accessibility"
|
2021-04-22 21:46:02 +00:00
|
|
|
|
|
|
|
import os
|
2021-12-26 18:46:43 +00:00
|
|
|
from utils import is_account_dir
|
2021-12-26 15:13:34 +00:00
|
|
|
from utils import load_json
|
2021-12-26 14:08:58 +00:00
|
|
|
from utils import get_config_param
|
2021-12-26 12:02:29 +00:00
|
|
|
from utils import acct_dir
|
2021-12-29 21:55:09 +00:00
|
|
|
from webapp_utils import html_header_with_external_style
|
|
|
|
from webapp_utils import html_footer
|
2021-04-22 21:46:02 +00:00
|
|
|
|
|
|
|
|
2022-01-01 15:11:42 +00:00
|
|
|
def load_access_keys_for_accounts(base_dir: str, key_shortcuts: {},
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysTemplate: {}) -> None:
|
2021-04-22 21:46:02 +00:00
|
|
|
"""Loads key shortcuts for each account
|
|
|
|
"""
|
2021-12-25 16:17:53 +00:00
|
|
|
for subdir, dirs, files in os.walk(base_dir + '/accounts'):
|
2021-04-22 21:46:02 +00:00
|
|
|
for acct in dirs:
|
2021-12-26 18:46:43 +00:00
|
|
|
if not is_account_dir(acct):
|
2021-04-22 21:46:02 +00:00
|
|
|
continue
|
2021-12-25 16:17:53 +00:00
|
|
|
accountDir = os.path.join(base_dir + '/accounts', acct)
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysFilename = accountDir + '/access_keys.json'
|
|
|
|
if not os.path.isfile(access_keysFilename):
|
2021-04-22 21:46:02 +00:00
|
|
|
continue
|
|
|
|
nickname = acct.split('@')[0]
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keys = load_json(access_keysFilename)
|
|
|
|
if access_keys:
|
2022-01-01 15:11:42 +00:00
|
|
|
key_shortcuts[nickname] = access_keysTemplate.copy()
|
2021-12-31 21:18:12 +00:00
|
|
|
for variableName, key in access_keysTemplate.items():
|
|
|
|
if access_keys.get(variableName):
|
2022-01-01 15:11:42 +00:00
|
|
|
key_shortcuts[nickname][variableName] = \
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keys[variableName]
|
2021-04-22 21:46:02 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
def html_access_keys(css_cache: {}, base_dir: str,
|
|
|
|
nickname: str, domain: str,
|
2021-12-31 21:18:12 +00:00
|
|
|
translate: {}, access_keys: {},
|
2021-12-29 21:55:09 +00:00
|
|
|
defaultAccessKeys: {},
|
2021-12-31 23:50:29 +00:00
|
|
|
default_timeline: str) -> str:
|
2021-04-22 21:46:02 +00:00
|
|
|
"""Show and edit key shortcuts
|
|
|
|
"""
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysFilename = \
|
|
|
|
acct_dir(base_dir, nickname, domain) + '/access_keys.json'
|
|
|
|
if os.path.isfile(access_keysFilename):
|
|
|
|
access_keysFromFile = load_json(access_keysFilename)
|
|
|
|
if access_keysFromFile:
|
|
|
|
access_keys = access_keysFromFile
|
2021-04-22 21:46:02 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm = ''
|
|
|
|
css_filename = base_dir + '/epicyon-profile.css'
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
2021-12-31 21:18:12 +00:00
|
|
|
css_filename = base_dir + '/epicyon.css'
|
2021-04-22 21:46:02 +00:00
|
|
|
|
|
|
|
instanceTitle = \
|
2021-12-26 14:08:58 +00:00
|
|
|
get_config_param(base_dir, 'instanceTitle')
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm = \
|
|
|
|
html_header_with_external_style(css_filename, instanceTitle, None)
|
|
|
|
access_keysForm += '<div class="container">\n'
|
2021-04-22 21:46:02 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += \
|
2021-04-22 21:46:02 +00:00
|
|
|
' <h1>' + translate['Key Shortcuts'] + '</h1>\n'
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += \
|
2021-04-23 19:59:55 +00:00
|
|
|
'<p>' + translate['These access keys may be used'] + \
|
|
|
|
'<label class="labels"></label></p>'
|
2021-04-22 21:46:02 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += ' <form method="POST" action="' + \
|
2021-04-22 21:46:02 +00:00
|
|
|
'/users/' + nickname + '/changeAccessKeys">\n'
|
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
timelineKey = access_keys['menuTimeline']
|
|
|
|
submitKey = access_keys['submitButton']
|
|
|
|
access_keysForm += \
|
2021-04-22 22:28:16 +00:00
|
|
|
' <center>\n' + \
|
2021-04-22 22:37:52 +00:00
|
|
|
' <button type="submit" class="button" ' + \
|
2021-04-23 09:15:53 +00:00
|
|
|
'name="submitAccessKeysCancel" accesskey="' + timelineKey + '">' + \
|
2021-04-22 22:37:52 +00:00
|
|
|
translate['Go Back'] + '</button>\n' + \
|
2021-04-23 09:15:53 +00:00
|
|
|
' <button type="submit" class="button" ' + \
|
|
|
|
'name="submitAccessKeys" accesskey="' + submitKey + '">' + \
|
2021-04-22 22:28:16 +00:00
|
|
|
translate['Submit'] + '</button>\n </center>\n'
|
2021-04-22 21:46:02 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += ' <table class="accesskeys">\n'
|
|
|
|
access_keysForm += ' <colgroup>\n'
|
|
|
|
access_keysForm += ' <col span="1" class="accesskeys-left">\n'
|
|
|
|
access_keysForm += ' <col span="1" class="accesskeys-center">\n'
|
|
|
|
access_keysForm += ' </colgroup>\n'
|
|
|
|
access_keysForm += ' <tbody>\n'
|
2021-04-22 21:46:02 +00:00
|
|
|
|
|
|
|
for variableName, key in defaultAccessKeys.items():
|
|
|
|
if not translate.get(variableName):
|
|
|
|
continue
|
|
|
|
keyStr = '<tr>'
|
|
|
|
keyStr += \
|
|
|
|
'<td><label class="labels">' + \
|
|
|
|
translate[variableName] + '</label></td>'
|
2021-12-31 21:18:12 +00:00
|
|
|
if access_keys.get(variableName):
|
|
|
|
key = access_keys[variableName]
|
2021-04-23 14:21:57 +00:00
|
|
|
if len(key) > 1:
|
|
|
|
key = key[0]
|
2021-04-22 21:46:02 +00:00
|
|
|
keyStr += \
|
2021-04-23 14:21:57 +00:00
|
|
|
'<td><input type="text" ' + \
|
|
|
|
'name="' + variableName.replace(' ', '_') + '" ' + \
|
|
|
|
'value="' + key + '">'
|
2021-04-22 22:15:25 +00:00
|
|
|
keyStr += '</td></tr>\n'
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += keyStr
|
2021-04-22 21:46:02 +00:00
|
|
|
|
2021-12-31 21:18:12 +00:00
|
|
|
access_keysForm += ' </tbody>\n'
|
|
|
|
access_keysForm += ' </table>\n'
|
|
|
|
access_keysForm += ' </form>\n'
|
|
|
|
access_keysForm += '</div>\n'
|
|
|
|
access_keysForm += html_footer()
|
|
|
|
return access_keysForm
|