From 30906e94da4c9a947bbda8bb2671759df20416a8 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 13 Oct 2023 12:07:42 +0200 Subject: [PATCH] matrix_cc_receivers_room_id to matrix_bcc_receivers_room_id --- cdci_data_analysis/analysis/matrix_helper.py | 16 ++--- .../config_dir/conf_env.yml.example | 2 +- cdci_data_analysis/configurer.py | 6 +- cdci_data_analysis/pytest_fixtures.py | 4 +- tests/conftest.py | 2 +- tests/test_matrix_messages.py | 68 +++++++++---------- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cdci_data_analysis/analysis/matrix_helper.py b/cdci_data_analysis/analysis/matrix_helper.py index dd2250d05..70992025a 100644 --- a/cdci_data_analysis/analysis/matrix_helper.py +++ b/cdci_data_analysis/analysis/matrix_helper.py @@ -196,7 +196,7 @@ def send_job_message( matrix_sender_access_token = config.matrix_sender_access_token receiver_room_id = tokenHelper.get_token_user_matrix_room_id(decoded_token) - cc_receivers_room_ids = config.matrix_cc_receivers_room_ids + bcc_receivers_room_ids = config.matrix_bcc_receivers_room_ids matrix_message_data = { 'oda_site': { @@ -229,11 +229,11 @@ def send_job_message( message_body_html = template.render(**matrix_message_data) message_text = textify_matrix_message(message_body_html) res_content = { - 'res_content_cc_users': [] + 'res_content_bcc_users': [] } message_data = { - 'message_data_cc_users': [] + 'message_data_bcc_users': [] } if receiver_room_id is not None and receiver_room_id != "": res_data_message_token_user = send_message(url_server=matrix_server_url, @@ -250,18 +250,18 @@ def send_job_message( matrix_helper_logger.warning('a matrix message could not be sent to the token user as no personal room id was ' 'provided within the token') - for cc_receiver_room_id in cc_receivers_room_ids: - if cc_receiver_room_id is not None and cc_receiver_room_id != "": + for bcc_receiver_room_id in bcc_receivers_room_ids: + if bcc_receiver_room_id is not None and bcc_receiver_room_id != "": res_data_message_cc_user = send_message(url_server=matrix_server_url, sender_access_token=matrix_sender_access_token, - room_id=cc_receiver_room_id, + room_id=bcc_receiver_room_id, message_text=message_text, message_body_html=message_body_html ) message_data_cc_user = res_data_message_cc_user['message_data'] - message_data['message_data_cc_users'].append(message_data_cc_user) + message_data['message_data_bcc_users'].append(message_data_cc_user) res_content_cc_user = res_data_message_cc_user['res_content'] - res_content['res_content_cc_users'].append(res_content_cc_user) + res_content['res_content_bcc_users'].append(res_content_cc_user) store_status_matrix_message_info(message_data, status, scratch_dir, sending_time=sending_time, first_submitted_time=time_request) diff --git a/cdci_data_analysis/config_dir/conf_env.yml.example b/cdci_data_analysis/config_dir/conf_env.yml.example index f69fddd93..8664ab7ee 100644 --- a/cdci_data_analysis/config_dir/conf_env.yml.example +++ b/cdci_data_analysis/config_dir/conf_env.yml.example @@ -81,7 +81,7 @@ dispatcher: # access token of the sender account, from which the messages will be sent from matrix_sender_access_token: MATRIX_SENDER_ACCESS_TOKEN # list of additional room ids receivers towards which the message will be sent, besides the room id extracted from the token - matrix_cc_receivers_room_ids: ['room_id'] + matrix_bcc_receivers_room_ids: ['room_id'] # incident report related options, for the messages sent via matrix incident_report_matrix_options: # list of room ids receivers towards which the incident report message will be sent diff --git a/cdci_data_analysis/configurer.py b/cdci_data_analysis/configurer.py index f862b23a4..4ec6e6f1c 100644 --- a/cdci_data_analysis/configurer.py +++ b/cdci_data_analysis/configurer.py @@ -247,7 +247,7 @@ def __init__(self, cfg_dict, origin=None): disp_dict['email_options'].get('incident_report_email_options', {}).get('incident_report_receivers_email_addresses', None), disp_dict.get('matrix_options', {}).get('matrix_server_url', None), disp_dict.get('matrix_options', {}).get('matrix_sender_access_token', None), - disp_dict.get('matrix_options', {}).get('matrix_cc_receivers_room_ids', []), + disp_dict.get('matrix_options', {}).get('matrix_bcc_receivers_room_ids', []), disp_dict.get('matrix_options', {}).get('incident_report_matrix_options', {}).get('matrix_incident_report_receivers_room_ids', []), disp_dict.get('matrix_options', {}).get('incident_report_matrix_options', {}).get('matrix_incident_report_sender_personal_access_token', None), disp_dict.get('matrix_options', {}).get('matrix_message_sending_job_submitted', True), @@ -325,7 +325,7 @@ def set_conf_dispatcher(self, incident_report_receivers_email_addresses, matrix_server_url, matrix_sender_access_token, - matrix_cc_receivers_room_ids, + matrix_bcc_receivers_room_ids, matrix_incident_report_receivers_room_ids, matrix_incident_report_sender_personal_access_token, matrix_message_sending_job_submitted, @@ -375,7 +375,7 @@ def set_conf_dispatcher(self, self.incident_report_receivers_email_addresses = incident_report_receivers_email_addresses self.matrix_server_url = matrix_server_url self.matrix_sender_access_token = matrix_sender_access_token - self.matrix_cc_receivers_room_ids = matrix_cc_receivers_room_ids + self.matrix_bcc_receivers_room_ids = matrix_bcc_receivers_room_ids self.matrix_incident_report_receivers_room_ids = matrix_incident_report_receivers_room_ids self.matrix_incident_report_sender_personal_access_token = matrix_incident_report_sender_personal_access_token self.matrix_message_sending_job_submitted = matrix_message_sending_job_submitted diff --git a/cdci_data_analysis/pytest_fixtures.py b/cdci_data_analysis/pytest_fixtures.py index 9a5d26a90..3f8119714 100644 --- a/cdci_data_analysis/pytest_fixtures.py +++ b/cdci_data_analysis/pytest_fixtures.py @@ -564,7 +564,7 @@ def dispatcher_test_conf_with_matrix_options_fn(dispatcher_test_conf_fn): f.write('\n matrix_options:' '\n matrix_server_url: "https://matrix-client.matrix.org/"' f'\n matrix_sender_access_token: "{os.getenv("MATRIX_SENDER_ACCESS_TOKEN", "matrix_sender_access_token")}"' - f'\n matrix_cc_receivers_room_ids: ["{os.getenv("MATRIX_CC_RECEIVER_ROOM_ID", "")}"]' + f'\n matrix_bcc_receivers_room_ids: ["{os.getenv("MATRIX_CC_RECEIVER_ROOM_ID", "")}"]' '\n incident_report_matrix_options:' f'\n matrix_incident_report_receivers_room_ids: ["{os.getenv("MATRIX_INCIDENT_REPORT_RECEIVER_ROOM_ID", "matrix_incident_report_receivers_room_ids")}"]' f'\n matrix_incident_report_sender_personal_access_token: "{os.getenv("MATRIX_INCIDENT_REPORT_SENDER_PERSONAL_ACCESS_TOKEN", "matrix_incident_report_sender_personal_access_token")}"' @@ -578,7 +578,7 @@ def dispatcher_test_conf_with_matrix_options_fn(dispatcher_test_conf_fn): @pytest.fixture -def dispatcher_no_cc_matrix_room_ids(monkeypatch): +def dispatcher_no_bcc_matrix_room_ids(monkeypatch): monkeypatch.delenv('MATRIX_CC_RECEIVER_ROOM_ID', raising=False) diff --git a/tests/conftest.py b/tests/conftest.py index 846829e46..e8a35efa5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ dispatcher_long_living_fixture, gunicorn_dispatcher_long_living_fixture, dispatcher_long_living_fixture_with_matrix_options, - dispatcher_no_cc_matrix_room_ids, + dispatcher_no_bcc_matrix_room_ids, gunicorn_dispatcher_long_living_fixture_with_matrix_options, dispatcher_test_conf, dispatcher_test_conf_with_gallery, diff --git a/tests/test_matrix_messages.py b/tests/test_matrix_messages.py index 20d64fcdd..7fcf81b61 100644 --- a/tests/test_matrix_messages.py +++ b/tests/test_matrix_messages.py @@ -315,19 +315,19 @@ def test_matrix_message_run_analysis_callback(gunicorn_dispatcher_long_living_fi require_reference_matrix_message=True ) - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 1 - assert 'event_id' in matrix_message_status_details_obj['res_content']['res_content_cc_users'][0] + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 1 + assert 'event_id' in matrix_message_status_details_obj['res_content']['res_content_bcc_users'][0] - matrix_cc_message_event_id_obj = matrix_message_status_details_obj['res_content']['res_content_cc_users'][0]['event_id'] + matrix_bcc_message_event_id_obj = matrix_message_status_details_obj['res_content']['res_content_bcc_users'][0]['event_id'] validate_matrix_message_content( - dispatcher_local_matrix_message_server.get_matrix_message_record(room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_cc_receivers_room_ids'][0], - event_id=matrix_cc_message_event_id_obj), + dispatcher_local_matrix_message_server.get_matrix_message_record(room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_bcc_receivers_room_ids'][0], + event_id=matrix_bcc_message_event_id_obj), 'submitted', - room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_cc_receivers_room_ids'][0], - event_id=matrix_cc_message_event_id_obj, + room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_bcc_receivers_room_ids'][0], + event_id=matrix_bcc_message_event_id_obj, user_id=token_payload['user_id'], dispatcher_job_state=dispatcher_job_state, variation_suffixes=["dummy"], @@ -460,9 +460,9 @@ def test_matrix_message_run_analysis_callback(gunicorn_dispatcher_long_living_fi assert 'matrix_message_status_details' in jdata matrix_message_status_details_obj = json.loads(jdata['matrix_message_status_details']) assert 'res_content' in matrix_message_status_details_obj - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 1 + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 1 if request_cred == 'private-no-room-id': assert 'res_content_token_user' not in matrix_message_status_details_obj['res_content'] @@ -486,7 +486,7 @@ def test_matrix_message_run_analysis_callback(gunicorn_dispatcher_long_living_fi require_reference_matrix_message=True ) - matrix_cc_message_event_id_obj = matrix_message_status_details_obj['res_content']['res_content_cc_users'][0][ + matrix_bcc_message_event_id_obj = matrix_message_status_details_obj['res_content']['res_content_bcc_users'][0][ 'event_id'] # check the matrix message in the matrix message folders, and that the first one was produced @@ -494,11 +494,11 @@ def test_matrix_message_run_analysis_callback(gunicorn_dispatcher_long_living_fi validate_matrix_message_content( dispatcher_local_matrix_message_server.get_matrix_message_record( - room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_cc_receivers_room_ids'][0], - event_id=matrix_cc_message_event_id_obj), + room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_bcc_receivers_room_ids'][0], + event_id=matrix_bcc_message_event_id_obj), 'done', - room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_cc_receivers_room_ids'][0], - event_id=matrix_cc_message_event_id_obj, + room_id=dispatcher_test_conf_with_matrix_options['matrix_options']['matrix_bcc_receivers_room_ids'][0], + event_id=matrix_bcc_message_event_id_obj, user_id=token_payload['user_id'], dispatcher_job_state=dispatcher_job_state, time_request_str=time_request_str, @@ -533,9 +533,9 @@ def test_matrix_message_run_analysis_callback(gunicorn_dispatcher_long_living_fi assert 'matrix_message_status_details' in jdata matrix_message_status_details_obj = json.loads(jdata['matrix_message_status_details']) assert 'res_content' in matrix_message_status_details_obj - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 1 + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 1 if request_cred == 'private-no-room-id': assert 'res_content_token_user' not in matrix_message_status_details_obj['res_content'] else: @@ -612,10 +612,10 @@ def test_matrix_message_submitted_same_job(dispatcher_live_fixture_with_matrix_o assert 'res_content' in matrix_message_status_details_obj assert 'res_content_token_user' in matrix_message_status_details_obj['res_content'] assert 'event_id' in matrix_message_status_details_obj['res_content']['res_content_token_user'] - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 1 - assert 'event_id' in matrix_message_status_details_obj['res_content']['res_content_cc_users'][0] + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 1 + assert 'event_id' in matrix_message_status_details_obj['res_content']['res_content_bcc_users'][0] time_request = jdata['time_request'] time_request_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(float(time_request))) @@ -1206,7 +1206,7 @@ def test_incident_report(dispatcher_live_fixture_with_matrix_options, @pytest.mark.parametrize("default_values", [True, False]) @pytest.mark.parametrize("time_original_request_none", [False]) @pytest.mark.parametrize("request_cred", ['public', 'private', 'private-no-matrix-message', 'private-no-room-id']) -def test_matrix_message_run_analysis_callback_no_room_ids(dispatcher_no_cc_matrix_room_ids, +def test_matrix_message_run_analysis_callback_no_room_ids(dispatcher_no_bcc_matrix_room_ids, gunicorn_dispatcher_long_living_fixture_with_matrix_options, dispatcher_test_conf_with_matrix_options, dispatcher_local_matrix_message_server, @@ -1331,9 +1331,9 @@ def test_matrix_message_run_analysis_callback_no_room_ids(dispatcher_no_cc_matri require_reference_matrix_message=True ) - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 0 + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 0 # for the call_back(s) in case the time of the original request is not provided if time_original_request_none: @@ -1457,9 +1457,9 @@ def test_matrix_message_run_analysis_callback_no_room_ids(dispatcher_no_cc_matri assert 'matrix_message_status_details' in jdata matrix_message_status_details_obj = json.loads(jdata['matrix_message_status_details']) assert 'res_content' in matrix_message_status_details_obj - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 0 + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 0 if request_cred == 'private-no-room-id': assert 'res_content_token_user' not in matrix_message_status_details_obj['res_content'] @@ -1513,9 +1513,9 @@ def test_matrix_message_run_analysis_callback_no_room_ids(dispatcher_no_cc_matri assert 'matrix_message_status_details' in jdata matrix_message_status_details_obj = json.loads(jdata['matrix_message_status_details']) assert 'res_content' in matrix_message_status_details_obj - assert 'res_content_cc_users' in matrix_message_status_details_obj['res_content'] - assert isinstance(matrix_message_status_details_obj['res_content']['res_content_cc_users'], list) - assert len(matrix_message_status_details_obj['res_content']['res_content_cc_users']) == 0 + assert 'res_content_bcc_users' in matrix_message_status_details_obj['res_content'] + assert isinstance(matrix_message_status_details_obj['res_content']['res_content_bcc_users'], list) + assert len(matrix_message_status_details_obj['res_content']['res_content_bcc_users']) == 0 if request_cred == 'private-no-room-id': assert 'res_content_token_user' not in matrix_message_status_details_obj['res_content'] else: