From 81b78fa8e321ca1a6fbb43ec69d6a898c0b0898d Mon Sep 17 00:00:00 2001 From: Terry Geng Date: Fri, 21 Jan 2022 22:27:15 -0500 Subject: [PATCH] feat(config): Moved `delete_allowed` to [bot] section, Now it works for both command and web interface. Implemented #293. --- command.py | 5 +++++ configuration.example.ini | 10 +++++++--- interface.py | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/command.py b/command.py index 6bcaaad..d7de6fc 100644 --- a/command.py +++ b/command.py @@ -1148,6 +1148,11 @@ def cmd_shortlist(bot, user, text, command, parameter): def cmd_delete_from_library(bot, user, text, command, parameter): global song_shortlist, log + + if not var.config.getboolean("bot", "delete_allowed", fallback=True): + bot.mumble.users[text.actor].send_text_message(tr('not_admin')) + return + try: indexes = [int(i) for i in parameter.split(" ")] except ValueError: diff --git a/configuration.example.ini b/configuration.example.ini index b944a74..9f1fbad 100644 --- a/configuration.example.ini +++ b/configuration.example.ini @@ -95,6 +95,11 @@ port = 64738 #allow_other_channel_message = False #allow_private_message = True +# 'delete_allowed': Allow users to delete a file from the library (hard disk). +# Works both for command and web interface. After enabling this option, only +# admins are allowed to delete files. +#delete_allowded = True + # 'save_music_library': If this is set True, the bot will save the metadata of music into the database. #save_music_library = True @@ -166,12 +171,11 @@ port = 64738 # !! YOU NEED TO CHANGE IT IF auth_method IS 'token'!! # flask_secret = ChangeThisPassword -# 'upload_enabled': Enable the upload function of the web interface. +# 'upload_enabled': Enable the upload function of the web interface. If disabled, +# only admins can upload files. # 'maximum_upload_file_size': Unit can be 'B', 'KB', 'MB', 'GB', 'TB'. -# 'delete_allowed': Allow users to delete a file from the library(hard disk). #upload_enabled = True #max_upload_file_size = 30MB -#delete_allowded = True # [debug] stores some debug settings. [debug] diff --git a/interface.py b/interface.py index 08c74c6..7565da0 100644 --- a/interface.py +++ b/interface.py @@ -563,8 +563,8 @@ def library_info(): return jsonify(dict( dirs=get_all_dirs(), - upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True), - delete_allowed=var.config.getboolean("webinterface", "delete_allowed", fallback=True), + upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True) or var.bot.is_admin(user), + delete_allowed=var.config.getboolean("bot", "delete_allowed", fallback=True) or var.bot.is_admin(user), tags=tags, max_upload_file_size=max_upload_file_size )) @@ -609,7 +609,7 @@ def library(): return redirect("./", code=302) elif payload['action'] == 'delete': - if var.config.getboolean("webinterface", "delete_allowed", fallback=True): + if var.config.getboolean("bot", "delete_allowed", fallback=True): items = dicts_to_items(var.music_db.query_music(condition)) for item in items: var.playlist.remove_by_id(item.id)