From 1eb47a45840a115b6cea160e1f91340467201b40 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 3 Dec 2019 00:00:15 -0600 Subject: [PATCH] onboarding work --- greetings.yml | 13 ------------- src/config/onboarding.py | 14 ++++++++++---- src/httpapi/__init__.py | 5 +++++ src/onionrplugins/__init__.py | 22 +++++++++++----------- src/onionrplugins/onionrevents.py | 2 ++ static-data/default_config.json | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 greetings.yml diff --git a/greetings.yml b/greetings.yml deleted file mode 100644 index 6714c6d5..00000000 --- a/greetings.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Greetings - -on: [pull_request, issues] - -jobs: - greeting: - runs-on: ubuntu-latest - steps: - - uses: actions/first-interaction@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: 'Message that will be displayed on users'' first issue' - pr-message: 'Hi, please make the PR at https://gitlab.com/beardog/Onionr'' first pr' diff --git a/src/config/onboarding.py b/src/config/onboarding.py index 217f5903..a47348b0 100644 --- a/src/config/onboarding.py +++ b/src/config/onboarding.py @@ -37,15 +37,21 @@ def set_config_from_onboarding(config_settings: OnboardingConfig): network_security_level = 0 theme = "dark" + get = _get_val_or_none - if _get_val_or_none(config_settings, 'stateTarget') == True: + if get(config_settings, 'stateTarget') or not get(config_settings, + 'networkContribution'): config.set('general.security_level', 1) - if _get_val_or_none(config_settings, 'useDark') == False: - config.set('ui.theme', 'light') + config.set('ui.theme', 'light') + if get(config_settings, 'useDark'): + config.set('ui.theme', 'dark') + + if not get(config_settings, 'useMail'): + config.set('plugins.disabled', ['pms']) config.set('general.store_plaintext_blocks', - _get_val_or_none(config_settings, 'plainContrib')) + get(config_settings, 'plainContrib')) config.set('onboarding.done', True, savefile=True) diff --git a/src/httpapi/__init__.py b/src/httpapi/__init__.py index 7f45cd5b..101a20c6 100755 --- a/src/httpapi/__init__.py +++ b/src/httpapi/__init__.py @@ -18,10 +18,15 @@ along with this program. If not, see . """ import onionrplugins +import config def load_plugin_blueprints(flaskapp, blueprint: str = 'flask_blueprint'): """Iterate enabled plugins and load any http endpoints they have""" + config.reload() + disabled = config.get('plugins.disabled') for plugin in onionrplugins.get_enabled_plugins(): + if plugin in disabled: + continue plugin = onionrplugins.get_plugin(plugin) try: flaskapp.register_blueprint(getattr(plugin, blueprint)) diff --git a/src/onionrplugins/__init__.py b/src/onionrplugins/__init__.py index 7c70484c..67aacd33 100755 --- a/src/onionrplugins/__init__.py +++ b/src/onionrplugins/__init__.py @@ -30,7 +30,7 @@ _pluginsfolder = dataDir + 'plugins/' _instances = dict() config.reload() -def reload(onionr = None, stop_event = True): +def reload(stop_event = True): ''' Reloads all the plugins ''' @@ -47,10 +47,10 @@ def reload(onionr = None, stop_event = True): if stop_event is True: for plugin in enabled_plugins: - stop(plugin, onionr) + stop(plugin) for plugin in enabled_plugins: - start(plugin, onionr) + start(plugin) return True except: @@ -58,7 +58,7 @@ def reload(onionr = None, stop_event = True): return False -def enable(name, onionr = None, start_event = True): +def enable(name, start_event = True): ''' Enables a plugin ''' @@ -69,7 +69,7 @@ def enable(name, onionr = None, start_event = True): enabled_plugins = get_enabled_plugins() if not name in enabled_plugins: try: - events.call(get_plugin(name), 'enable', onionr) + events.call(get_plugin(name), 'enable') except ImportError as e: # Was getting import error on Gitlab CI test "data" # NOTE: If you are experiencing issues with plugins not being enabled, it might be this resulting from an error in the module # can happen inconsistently (especially between versions) @@ -92,7 +92,7 @@ def enable(name, onionr = None, start_event = True): return False -def disable(name, onionr = None, stop_event = True): +def disable(name, stop_event = True): ''' Disables a plugin ''' @@ -105,12 +105,12 @@ def disable(name, onionr = None, stop_event = True): config.set('plugins.enabled', enabled_plugins, True) if exists(name): - events.call(get_plugin(name), 'disable', onionr) + events.call(get_plugin(name), 'disable') if stop_event is True: stop(name) -def start(name, onionr = None): +def start(name): ''' Starts the plugin ''' @@ -124,7 +124,7 @@ def start(name, onionr = None): if plugin is None: raise Exception('Failed to import module.') else: - events.call(plugin, 'start', onionr) + events.call(plugin, 'start') return plugin except: @@ -134,7 +134,7 @@ def start(name, onionr = None): return None -def stop(name, onionr = None): +def stop(name): ''' Stops the plugin ''' @@ -148,7 +148,7 @@ def stop(name, onionr = None): if plugin is None: raise Exception('Failed to import module.') else: - events.call(plugin, 'stop', onionr) + events.call(plugin, 'stop') return plugin except: diff --git a/src/onionrplugins/onionrevents.py b/src/onionrplugins/onionrevents.py index 2680cad2..d07656cf 100755 --- a/src/onionrplugins/onionrevents.py +++ b/src/onionrplugins/onionrevents.py @@ -32,7 +32,9 @@ def __event_caller(event_name, data = {}): DO NOT call this function, this is for threading code only. Instead, call onionrevents.event ''' + disabled = config.get('plugins.disabled') for plugin in plugins.get_enabled_plugins(): + if plugin in disabled: continue try: call(plugins.get_plugin(plugin), event_name, data, get_pluginapi(data)) except ModuleNotFoundError as e: diff --git a/static-data/default_config.json b/static-data/default_config.json index 05c89fc6..27e62d47 100755 --- a/static-data/default_config.json +++ b/static-data/default_config.json @@ -76,6 +76,6 @@ }, "onboarding": { - "done": false + "done": true } }