Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions webex_bot/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ def build_actions_and_hints(self, thread_parent_id):
# Sort list by keyword
sorted_commands_list = sorted(self.commands, key=lambda command: (
command.command_keyword is not None, command.command_keyword))

for command in sorted_commands_list:
if command.help_message and command.command_keyword != HELP_COMMAND_KEYWORD:
action = Submit(
title=f"{command.help_message}",
data={COMMAND_KEYWORD_KEY: command.command_keyword,
'thread_parent_id': thread_parent_id},
)
help_actions.append(action)

hint = Fact(title=command.command_keyword,
value=command.help_message)

hint_texts.append(hint)
if not command.admin_command:
if command.help_message and command.command_keyword != HELP_COMMAND_KEYWORD:
action = Submit(
title=f"{command.help_message}",
data={COMMAND_KEYWORD_KEY: command.command_keyword,
'thread_parent_id': thread_parent_id},
)
help_actions.append(action)

hint = Fact(title=command.command_keyword,
value=command.help_message)

hint_texts.append(hint)
return help_actions, hint_texts
4 changes: 3 additions & 1 deletion webex_bot/models/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Command(ABC):

def __init__(self, command_keyword=None, chained_commands=[], card=None, help_message=None,
delete_previous_message=False,
card_callback_keyword=None, approved_rooms=None):
card_callback_keyword=None, approved_rooms=None, approved_admins=None, admin_command=None):
"""
Create a new bot command.

Expand Down Expand Up @@ -45,6 +45,8 @@ def __init__(self, command_keyword=None, chained_commands=[], card=None, help_me
self.delete_previous_message = delete_previous_message
self.approved_rooms = approved_rooms
self.chained_commands = chained_commands
self.admin_command = admin_command
self.approved_admins = approved_admins

# Now, if this card has a Action.Submit action, let's read the callback keyword,
# or if it doesnt exist, add it.
Expand Down
16 changes: 16 additions & 0 deletions webex_bot/webex_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self,
approved_users=[],
approved_domains=[],
approved_rooms=[],
approved_admins=[],
device_url=DEFAULT_DEVICE_URL,
include_demo_commands=False,
bot_name="Webex Bot",
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self,
self.approved_users = approved_users
self.approved_domains = approved_domains
self.approved_rooms = approved_rooms
self.approved_admins = approved_admins
# Set default help message
self.help_message = "Hello! I understand the following commands: \n"
self.approval_parameters_check()
Expand Down Expand Up @@ -147,6 +149,16 @@ def check_user_approved(self, user_email, approved_rooms):
log.warning(f"{user_email} is not approved to interact at this time. Ignoring.")
return user_approved

def check_user_admin(self, user_email, approved_admins):
is_an_admin = False

if approved_admins is None:
is_an_admin = False
elif user_email in approved_admins:
is_an_admin = True

return is_an_admin

def is_user_member_of_room(self, user_email, approved_rooms):
is_user_member = False

Expand Down Expand Up @@ -243,6 +255,10 @@ def process_raw_command(self, raw_message, teams_message, user_email, activity,
log.info(f"{user_email} is not allowed to run command: '{command.command_keyword}'")
return

if command.admin_command and not self.check_user_admin(user_email=user_email,approved_admins=command.approved_admins):
log.info(f"{user_email} is not allowed to run command: '{command.command_keyword}' as it is an admin command")
return

# Build the reply to the user
reply = ""
reply_one_to_one = False
Expand Down