aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-27 11:03:55 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 14:03:18 +0200
commitba580db6b07d6fcb4877259f13052ddee34afb90 (patch)
tree9ab109cefad0ee276f696788ea24aad3390eea17 /src/hydrilla/proxy/state_impl
parentd42379c189c33dac732a1a1341395a9f5683260b (diff)
downloadhaketilo-hydrilla-ba580db6b07d6fcb4877259f13052ddee34afb90.tar.gz
haketilo-hydrilla-ba580db6b07d6fcb4877259f13052ddee34afb90.zip
[proxy] make some (possibly confusing) web UI parts only display to advanced users
Diffstat (limited to 'src/hydrilla/proxy/state_impl')
-rw-r--r--src/hydrilla/proxy/state_impl/concrete_state.py102
1 files changed, 53 insertions, 49 deletions
diff --git a/src/hydrilla/proxy/state_impl/concrete_state.py b/src/hydrilla/proxy/state_impl/concrete_state.py
index d08a821..04bb67f 100644
--- a/src/hydrilla/proxy/state_impl/concrete_state.py
+++ b/src/hydrilla/proxy/state_impl/concrete_state.py
@@ -58,21 +58,67 @@ from . import _operations
here = Path(__file__).resolve().parent
+def _prepare_database(connection: sqlite3.Connection) -> None:
+ cursor = connection.cursor()
+
+ try:
+ cursor.execute(
+ '''
+ SELECT
+ COUNT(name)
+ FROM
+ sqlite_master
+ WHERE
+ name = 'general' AND type = 'table';
+ '''
+ )
+
+ (db_initialized,), = cursor.fetchall()
+
+ if not db_initialized:
+ cursor.executescript((here.parent / 'tables.sql').read_text())
+ else:
+ cursor.execute(
+ '''
+ SELECT
+ haketilo_version
+ FROM
+ general;
+ '''
+ )
+
+ (db_haketilo_version,) = cursor.fetchone()
+ if db_haketilo_version != '3.0b1':
+ raise HaketiloException(_('err.proxy.unknown_db_schema'))
+
+ cursor.execute('PRAGMA FOREIGN_KEYS;')
+ if cursor.fetchall() == []:
+ raise HaketiloException(_('err.proxy.no_sqlite_foreign_keys'))
+
+ cursor.execute('PRAGMA FOREIGN_KEYS=ON;')
+ finally:
+ cursor.close()
+
+
def load_settings(cursor: sqlite3.Cursor) -> st.HaketiloGlobalSettings:
cursor.execute(
'''
SELECT
- default_allow_scripts, repo_refresh_seconds, mapping_use_mode
+ default_allow_scripts,
+ advanced_user,
+ repo_refresh_seconds,
+ mapping_use_mode
FROM
general
'''
)
- (default_allow_scripts, repo_refresh_seconds,
+ (default_allow_scripts, advanced_user, repo_refresh_seconds,
mapping_use_mode), = cursor.fetchall()
return st.HaketiloGlobalSettings(
default_allow_scripts = default_allow_scripts,
+ advanced_user = advanced_user,
repo_refresh_seconds = repo_refresh_seconds,
mapping_use_mode = st.MappingUseMode(mapping_use_mode)
)
@@ -80,55 +126,8 @@ def load_settings(cursor: sqlite3.Cursor) -> st.HaketiloGlobalSettings:
@dc.dataclass
class ConcreteHaketiloState(base.HaketiloStateWithFields):
def __post_init__(self) -> None:
- sqlite3.enable_callback_tracebacks(True)
-
- self._prepare_database()
-
self.rebuild_structures()
- def _prepare_database(self) -> None:
- """...."""
- cursor = self.connection.cursor()
-
- try:
- cursor.execute(
- '''
- SELECT
- COUNT(name)
- FROM
- sqlite_master
- WHERE
- name = 'general' AND type = 'table';
- '''
- )
-
- (db_initialized,), = cursor.fetchall()
-
- if not db_initialized:
- cursor.executescript((here.parent / 'tables.sql').read_text())
-
- else:
- cursor.execute(
- '''
- SELECT
- haketilo_version
- FROM
- general;
- '''
- )
-
- (db_haketilo_version,) = cursor.fetchone()
- if db_haketilo_version != '3.0b1':
- raise HaketiloException(_('err.proxy.unknown_db_schema'))
-
- cursor.execute('PRAGMA FOREIGN_KEYS;')
- if cursor.fetchall() == []:
- raise HaketiloException(_('err.proxy.no_sqlite_foreign_keys'))
-
- cursor.execute('PRAGMA FOREIGN_KEYS=ON;')
- finally:
- cursor.close()
-
def import_items(self, malcontent_path: Path, repo_id: int = 1) -> None:
with self.cursor(transaction=(repo_id == 1)) as cursor:
# This method without the repo_id argument exposed is part of the
@@ -305,6 +304,7 @@ class ConcreteHaketiloState(base.HaketiloStateWithFields):
*,
mapping_use_mode: t.Optional[st.MappingUseMode] = None,
default_allow_scripts: t.Optional[bool] = None,
+ advanced_user: t.Optional[bool] = None,
repo_refresh_seconds: t.Optional[int] = None
) -> None:
with self.cursor(transaction=True) as cursor:
@@ -315,6 +315,8 @@ class ConcreteHaketiloState(base.HaketiloStateWithFields):
set_opt('mapping_use_mode', mapping_use_mode.value)
if default_allow_scripts is not None:
set_opt('default_allow_scripts', default_allow_scripts)
+ if advanced_user is not None:
+ set_opt('advanced_user', advanced_user)
if repo_refresh_seconds is not None:
set_opt('repo_refresh_seconds', repo_refresh_seconds)
@@ -328,6 +330,8 @@ class ConcreteHaketiloState(base.HaketiloStateWithFields):
check_same_thread = False
)
+ _prepare_database(connection)
+
global_settings = load_settings(connection.cursor())
return ConcreteHaketiloState(