From 88a4422e29b8eb7a3b9c07df584f6076c2684755 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 25 Mar 2021 15:51:31 -0500 Subject: [PATCH] Create delete plugin path --- stashr/api.py | 105 ++++++++++++++++++++ stashr/templates/settings_page_plugins.html | 51 ++++++++-- 2 files changed, 147 insertions(+), 9 deletions(-) diff --git a/stashr/api.py b/stashr/api.py index d584c0a..8e33a4f 100644 --- a/stashr/api.py +++ b/stashr/api.py @@ -2064,6 +2064,7 @@ def api_get_plugins(): list_item['plugin_url'] = item.plugin_url list_item['plugin_license'] = item.plugin_license list_item['plugin_state'] = item.plugin_state + list_item['plugin_package_name'] = item.plugin_package_name # list_item[] data.append(list_item) @@ -2311,6 +2312,110 @@ def api_post_upload_plugin(): return jsonify(create_json_return('200')) + +@api.route('/plugins/enable/', methods=['POST']) +def api_post_plugin_enable(plugin): + """To Update Later + This is using docstrings for specifications. + --- + tags: + - plugins + """ + + user = current_user + + if not user.is_authenticated: + if not request.json: + return jsonify(create_json_return('400')) + if "api_key" not in request.json: + return jsonify(create_json_return('400')) + if request.json['api_key'] == "": + return jsonify(create_json_return('100')) + + user = database.session \ + .query(database.Users) \ + .filter(database.Users.api_key == request.json['api_key']) \ + .first() + + if user is None: + return jsonify(create_json_return('100')) + + if user.role != 'admin': + return jsonify(create_json_return('401')) + + utils.enable_plugin(plugin) + + return jsonify(create_json_return('200')) + + +@api.route('/plugins/disable/', methods=['POST']) +def api_post_plugin_disable(plugin): + """To Update Later + This is using docstrings for specifications. + --- + tags: + - plugins + """ + + user = current_user + + if not user.is_authenticated: + if not request.json: + return jsonify(create_json_return('400')) + if "api_key" not in request.json: + return jsonify(create_json_return('400')) + if request.json['api_key'] == "": + return jsonify(create_json_return('100')) + + user = database.session \ + .query(database.Users) \ + .filter(database.Users.api_key == request.json['api_key']) \ + .first() + + if user is None: + return jsonify(create_json_return('100')) + + if user.role != 'admin': + return jsonify(create_json_return('401')) + + utils.disable_plugin(plugin) + + return jsonify(create_json_return('200')) + +@api.route('/plugins/remove/', methods=['POST']) +def api_post_plugin_remove(plugin): + """To Update Later + This is using docstrings for specifications. + --- + tags: + - plugins + """ + + user = current_user + + if not user.is_authenticated: + if not request.json: + return jsonify(create_json_return('400')) + if "api_key" not in request.json: + return jsonify(create_json_return('400')) + if request.json['api_key'] == "": + return jsonify(create_json_return('100')) + + user = database.session \ + .query(database.Users) \ + .filter(database.Users.api_key == request.json['api_key']) \ + .first() + + if user is None: + return jsonify(create_json_return('100')) + + if user.role != 'admin': + return jsonify(create_json_return('401')) + + utils.uninstall_plugin(plugin) + + return jsonify(create_json_return('200')) + """ --- RESTART SERVER --- """ @api.route('/restart', methods=['POST']) diff --git a/stashr/templates/settings_page_plugins.html b/stashr/templates/settings_page_plugins.html index ec0459c..cef4412 100644 --- a/stashr/templates/settings_page_plugins.html +++ b/stashr/templates/settings_page_plugins.html @@ -77,7 +77,8 @@ Vue.component('plugin',{ [[ plugin.plugin_url ]] [[ plugin.plugin_license ]] [[ plugin.plugin_state ]] - + +