Skip to content

Commit

Permalink
Update intratime clock error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jmv74211 committed Jan 11, 2021
1 parent 40b498c commit 45f72d2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 33 deletions.
3 changes: 3 additions & 0 deletions src/intratime_slack_bot/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os
import logging

# SERVER CONFIGURATION
APP_DOMAIN = 'jmv74211.makefile.es'

# DATABASE CONFIGURATION
MONGO_DB_USER = "<YOUR_MONGO_DB_USER>"
MONGO_DB_PASSWORD = "<YOUR_MONGO_DB_PASSWORD>"
Expand Down
38 changes: 19 additions & 19 deletions src/intratime_slack_bot/lib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,7 @@ def set_custom_message(key, parameters):
str:
Custom slack message
"""

if key == 'ADD_USER_ERROR':
return f":x: Could not add the user. Status code = {parameters[0]}. Please contact with app administrator :x:"
elif key == 'DELETE_USER_ERROR':
return f":x: Could not delete the user. Status code = {parameters[0]}. Please contact with app administrator"\
" :x:"
elif key == 'UPDATE_USER_ERROR':
return f":x: Could not update the user info. Status code = {parameters[0]}. Please contact with app " \
"administrator :x:"
elif key == 'CLOCKING_ERROR':
return f":x: Could not clock your action. Status code = {parameters[0]}. Please contact with app " \
"administrator :x:"
elif key == 'CLOCKING_CHECK_ERROR':
return f":x: Could not verify your last clocking. Status code = {parameters[0]}. Please, check manually or " \
"by consulting your last clocks to verify this clocking action :x:"
elif key == 'INVALID_CLOCKING_ACTION':
def get_error_template(title, status_code, error_description):
return [
{
"type": "divider"
Expand All @@ -177,22 +162,37 @@ def set_custom_message(key, parameters):
"type": "section",
"text": {
"type": "mrkdwn",
"text": f":x: Could not clock your action :x:\n *Status*: Failed\n *Reason*: {parameters[0]}\n"
"text": f":x: {title} :x:\n *Status*: Failed {status_code}\n *Reason*: {error_description}\n"
},
"accessory": {
"type": "image",
"image_url": f"{IMAGE_BASE_URL}x.png",
"alt_text": "Bad clocking action"
"alt_text": "Error"
}
},
{
"type": "divider"
}
]


if key == 'ADD_USER_ERROR':
return get_error_template('Could not add the user', parameters[0], 'Please contact with app administrator')
elif key == 'DELETE_USER_ERROR':
return get_error_template('Could not delete the user', parameters[0], 'Please contact with app administrator')
elif key == 'UPDATE_USER_ERROR':
return get_error_template('Could not update the user', parameters[0], 'Please contact with app administrator')
elif key == 'CLOCKING_ERROR':
return get_error_template('Could not clock your action', parameters[0], 'Please contact with app administrator')
elif key == 'CLOCKING_CHECK_ERROR':
return get_error_template('Could not verify this clocking request', parameters[0], 'Please, check manually ' \
'that the clock has been done correctly')
elif key == 'INVALID_CLOCKING_ACTION':
return get_error_template('Could not clock your action', '', parameters[0])
elif key == 'WORKED_TIME':
return f":timer_clock: Your working time {parameters[0]} is *{parameters[1]}* :timer_clock:"
else:
return ""
return ''

# ----------------------------------------------------------------------------------------------------------------------

Expand Down
14 changes: 8 additions & 6 deletions src/intratime_slack_bot/lib/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,17 @@ def process_interactive_data(data):
# Clock the action
request_status = intratime.clocking(data['submission']['action'], token, user_data['intratime_mail'])

if request_status != codes.SUCCESS:
if request_status == codes.SUCCESS:
post_ephemeral_response_message(messages.set_custom_message('CLOCKING_ERROR', [request_status]),
data['response_url'])
data['response_url'], 'blocks')
return
# Check the clock action in user history
clocking_check = intratime.get_user_clocks(token, time_utils.get_past_datetime_from_current_datetime(10),
time_utils.get_current_date_time(), data['submission']['action'])
if len(clocking_check) == 0:
post_ephemeral_response_message(messages.set_custom_message('CLOCKING_CHECK_ERROR', [request_status]),
data['response_url'])
data['response_url'], 'blocks')
return

clock_message = generate_clock_message({'intratime_mail': user_data['intratime_mail'],
'datetime': time_utils.get_current_date_time(),
Expand Down Expand Up @@ -527,7 +529,7 @@ def process_interactive_data(data):

if request_status != codes.SUCCESS:
post_ephemeral_response_message(messages.set_custom_message('ADD_USER_ERROR', [request_status]),
data['response_url'])
data['response_url'], 'blocks')

post_ephemeral_response_message(messages.ADD_USER_SUCCESS, data['response_url'])

Expand All @@ -541,7 +543,7 @@ def process_interactive_data(data):

if request_status != codes.SUCCESS:
post_ephemeral_response_message(messages.set_custom_message('UPDATE_USER_ERROR', [request_status]),
data['response_url'])
data['response_url'], 'blocks')

post_ephemeral_response_message(messages.UPDATE_USER_SUCCESS, data['response_url'])

Expand All @@ -551,6 +553,6 @@ def process_interactive_data(data):

if request_status != codes.SUCCESS:
post_ephemeral_response_message(messages.set_custom_message('DELETE_USER_ERROR', [request_status]),
data['response_url'])
data['response_url'], 'blocks')

post_ephemeral_response_message(messages.DELETE_USER_SUCCESS, data['response_url'])
2 changes: 1 addition & 1 deletion src/intratime_slack_bot/services/slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def wrapper(*args, **kwargs):
data['user'] = {'id': data['user_id'], 'name': data['user_name']}

headers = {"Content-Type": "application/x-www-form-urlencoded"}
url = f"{settings.PROTOCOL}://localhost:{settings.SLACK_SERVICE_PORT}{warehouse.INTERACTIVE_REQUEST}"
url = f"{settings.PROTOCOL}://{settings.APP_DOMAIN}{warehouse.INTERACTIVE_REQUEST}"
data = urllib.parse.urlencode({'payload': data})

requests.post(url, data=data, headers=headers)
Expand Down
109 changes: 102 additions & 7 deletions test/data/unit/messages/test_set_custom_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,130 @@
"parameters": [
15
],
"expected_result": ":x: Could not add the user. Status code = 15. Please contact with app administrator :x:"
"expected_result": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not add the user :x:\n *Status*: Failed 15\n *Reason*: Please contact with app administrator\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Error"
}
},
{
"type": "divider"
}
]
},
{
"key": "DELETE_USER_ERROR",
"parameters": [
15
],
"expected_result": ":x: Could not delete the user. Status code = 15. Please contact with app administrator :x:"
"expected_result": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not delete the user :x:\n *Status*: Failed 15\n *Reason*: Please contact with app administrator\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Error"
}
},
{
"type": "divider"
}
]
},
{
"key": "UPDATE_USER_ERROR",
"parameters": [
15
],
"expected_result": ":x: Could not update the user info. Status code = 15. Please contact with app administrator :x:"
"expected_result": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not update the user :x:\n *Status*: Failed 15\n *Reason*: Please contact with app administrator\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Error"
}
},
{
"type": "divider"
}
]
},
{
"key": "CLOCKING_ERROR",
"parameters": [
15
],
"expected_result": ":x: Could not clock your action. Status code = 15. Please contact with app administrator :x:"
"expected_result": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not clock your action :x:\n *Status*: Failed 15\n *Reason*: Please contact with app administrator\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Error"
}
},
{
"type": "divider"
}
]
},
{
"key": "CLOCKING_CHECK_ERROR",
"parameters": [
15
],
"expected_result": ":x: Could not verify your last clocking. Status code = 15. Please, check manually or by consulting your last clocks to verify this clocking action :x:"
"expected_result": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not verify this clocking request :x:\n *Status*: Failed 15\n *Reason*: Please, check manually that the clock has been done correctly\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Error"
}
},
{
"type": "divider"
}
]
},
{
"key": "INVALID_CLOCKING_ACTION",
Expand All @@ -47,12 +142,12 @@
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":x: Could not clock your action :x:\n *Status*: Failed\n *Reason*: test\n"
"text": ":x: Could not clock your action :x:\n *Status*: Failed \n *Reason*: test\n"
},
"accessory": {
"type": "image",
"image_url": "https://raw.githubusercontent.com/jmv74211/tools/master/images/repository/intratime-slack-app/ui/x.png",
"alt_text": "Bad clocking action"
"alt_text": "Error"
}
},
{
Expand Down

0 comments on commit 45f72d2

Please sign in to comment.