Urgent board permissions

This adds a feature for Urgent board permissions where you can limit who can post to the urgent board via a list in config.ini
This commit is contained in:
TC² 2024-07-09 14:05:33 -04:00
parent ab154b2934
commit ed90448164
3 changed files with 33 additions and 14 deletions

View file

@ -129,7 +129,7 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes):
if message.lower() == 'e':
handle_help_command(sender_id, interface, 'bbs')
return
board_name = state['board']
board_name = boards[int(message)]
response = f"What would you like to do in the {board_name} board?\n[R]ead [P]ost"
send_message(response, sender_id, interface)
update_user_state(sender_id, {'command': 'BULLETIN_ACTION', 'step': 2, 'board': board_name})
@ -147,6 +147,12 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes):
send_message(f"No bulletins in {board_name}.", sender_id, interface)
handle_bb_steps(sender_id, 'e', 1, state, interface, bbs_nodes)
elif message.lower() == 'p':
if board_name.lower() == 'urgent':
node_id = get_node_id_from_num(sender_id, interface)
allowed_nodes = interface.allowed_nodes
if allowed_nodes and node_id not in allowed_nodes:
send_message("You don't have permission to post to this board.", sender_id, interface)
return
send_message("What is the subject of your bulletin? Keep it short.", sender_id, interface)
update_user_state(sender_id, {'command': 'BULLETIN_POST', 'step': 4, 'board': board_name})
@ -182,7 +188,6 @@ def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes):
update_user_state(sender_id, state)
def handle_mail_steps(sender_id, message, step, state, interface, bbs_nodes):
if step == 1:
choice = message.lower()

View file

@ -80,8 +80,10 @@ def merge_config(system_config:dict[str, Any], args:argparse.Namespace) -> dict[
return system_config
def initialize_config(config_file: str = None) -> dict[str, Any]:
"""Function reads and parses system configuration file
"""
Function reads and parses system configuration file
Returns a dict with the following entries:
config - parsed config file
@ -110,11 +112,25 @@ def initialize_config(config_file:str = None) -> dict[str, Any]:
if bbs_nodes == ['']:
bbs_nodes = []
return {'config':config, 'interface_type': interface_type, 'hostname': hostname, 'port': port, 'bbs_nodes': bbs_nodes, 'mqtt_topic': 'meshtastic.receive'}
allowed_nodes = config.get('allow_list', 'allowed_nodes', fallback='').split(',')
if allowed_nodes == ['']:
allowed_nodes = []
return {
'config': config,
'interface_type': interface_type,
'hostname': hostname,
'port': port,
'bbs_nodes': bbs_nodes,
'allowed_nodes': allowed_nodes,
'mqtt_topic': 'meshtastic.receive'
}
def get_interface(system_config:dict[str, Any]) -> meshtastic.stream_interface.StreamInterface:
"""Function opens and returns an instance meshtastic interface of type specified by the configuration
"""
Function opens and returns an instance meshtastic interface of type specified by the configuration
Function creates and returns an instance of a class inheriting from meshtastic.stream_interface.StreamInterface.
The type of the class depends on the type of the interface specified by the system configuration.

View file

@ -39,7 +39,6 @@ Meshtastic Version
def main():
display_banner()
# config, interface_type, hostname, port, bbs_nodes = initialize_config()
args = init_cli_parser()
config_file = None
if args.config is not None:
@ -48,10 +47,9 @@ def main():
merge_config(system_config, args)
# print(f"{system_config=}")
interface = get_interface(system_config)
interface.bbs_nodes = system_config['bbs_nodes']
interface.allowed_nodes = system_config['allowed_nodes']
logging.info(f"TC²-BBS is running on {system_config['interface_type']} interface...")