feat(config): Moved delete_allowed to [bot] section,

Now it works for both command and web interface.

Implemented #293.
This commit is contained in:
Terry Geng 2022-01-21 22:27:15 -05:00
parent a034d2a85d
commit 81b78fa8e3
3 changed files with 15 additions and 6 deletions

View File

@ -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:

View File

@ -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]

View File

@ -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)