From 75aaeef3f2cff51da4170a035346353bf092701d Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Mon, 2 Jan 2023 09:28:39 -0300 Subject: [PATCH 1/6] Truncate slack alert group title block below max size --- .../renderers/slack_renderer.py | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/engine/apps/alerts/incident_appearance/renderers/slack_renderer.py b/engine/apps/alerts/incident_appearance/renderers/slack_renderer.py index f36fb2bb..0f2e00c0 100644 --- a/engine/apps/alerts/incident_appearance/renderers/slack_renderer.py +++ b/engine/apps/alerts/incident_appearance/renderers/slack_renderer.py @@ -1,6 +1,7 @@ import json from django.apps import apps +from django.utils.text import Truncator from apps.alerts.incident_appearance.renderers.base_renderer import AlertBaseRenderer, AlertGroupBaseRenderer from apps.alerts.incident_appearance.templaters import AlertSlackTemplater @@ -18,26 +19,31 @@ class AlertSlackRenderer(AlertBaseRenderer): return AlertSlackTemplater def render_alert_blocks(self): + BLOCK_SECTION_TEXT_MAX_SIZE = 2800 blocks = [] + title = Truncator(str_or_backup(self.templated_alert.title, "Alert")) blocks.append( { "type": "section", "text": { "type": "mrkdwn", - "text": str_or_backup(self.templated_alert.title, "Alert"), + "text": title.chars(BLOCK_SECTION_TEXT_MAX_SIZE), }, } ) if is_string_with_visible_characters(self.templated_alert.message): - message = self.templated_alert.message - BLOCK_SECTION_TEXT_MAX_SIZE = 2800 - if len(message) > BLOCK_SECTION_TEXT_MAX_SIZE: - message = ( - message[: BLOCK_SECTION_TEXT_MAX_SIZE - 3] + "... Message has been trimmed. " - "Check the whole content in Web" - ) - blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": message}}) + message = Truncator(self.templated_alert.message) + truncate_wording = "... Message has been trimmed. Check the whole content in Web" + blocks.append( + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": message.chars(BLOCK_SECTION_TEXT_MAX_SIZE, truncate=truncate_wording), + }, + } + ) return blocks def render_alert_attachments(self): From 374f32f4890e23a0bc6935e14f4d460be7fae4e6 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Mon, 2 Jan 2023 10:00:19 -0300 Subject: [PATCH 2/6] Handle no start date when calculating by day ical shift events --- engine/apps/api/tests/test_schedules.py | 2 +- .../schedules/models/custom_on_call_shift.py | 8 ++-- .../tests/test_custom_on_call_shift.py | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/engine/apps/api/tests/test_schedules.py b/engine/apps/api/tests/test_schedules.py index e0f73002..b89a0a8b 100644 --- a/engine/apps/api/tests/test_schedules.py +++ b/engine/apps/api/tests/test_schedules.py @@ -1113,7 +1113,7 @@ def test_merging_same_shift_events( data = { "start": start_date + timezone.timedelta(hours=10), - "rotation_start": start_date, + "rotation_start": start_date + timezone.timedelta(hours=10), "duration": timezone.timedelta(hours=2), "priority_level": 1, "frequency": CustomOnCallShift.FREQUENCY_DAILY, diff --git a/engine/apps/schedules/models/custom_on_call_shift.py b/engine/apps/schedules/models/custom_on_call_shift.py index 96cc2db2..5b6b1114 100644 --- a/engine/apps/schedules/models/custom_on_call_shift.py +++ b/engine/apps/schedules/models/custom_on_call_shift.py @@ -322,8 +322,10 @@ class CustomOnCallShift(models.Model): if all_rotations_checked: break - # number of weeks used to cover all combinations - week_interval = ((last_start - orig_start).days // 7) or 1 + week_interval = 1 + if orig_start and last_start: + # number of weeks used to cover all combinations + week_interval = ((last_start - orig_start).days // 7) or 1 counter = 1 for ((user_group_id, day, _), start) in zip(combinations, starting_dates): users = users_queue[user_group_id] @@ -367,7 +369,7 @@ class CustomOnCallShift(models.Model): start = self.get_rotation_date(event_ical) # Make sure we respect the selected days if any when defining start date - if self.frequency is not None and self.by_day: + if self.frequency is not None and self.by_day and start is not None: start_day = CustomOnCallShift.ICAL_WEEKDAY_MAP[start.weekday()] if start_day not in self.by_day: expected_start_day = min(CustomOnCallShift.ICAL_WEEKDAY_REVERSE_MAP[d] for d in self.by_day) diff --git a/engine/apps/schedules/tests/test_custom_on_call_shift.py b/engine/apps/schedules/tests/test_custom_on_call_shift.py index 3da17a66..0a40a879 100644 --- a/engine/apps/schedules/tests/test_custom_on_call_shift.py +++ b/engine/apps/schedules/tests/test_custom_on_call_shift.py @@ -1430,3 +1430,40 @@ def test_rolling_users_shift_convert_to_ical( assert on_call_shift.event_interval == len(rolling_users) * data["interval"] assert expected_rrule in ical_data + + +@pytest.mark.django_db +def test_rolling_users_event_daily_by_day_start_none_convert_to_ical( + make_organization_and_user, make_user_for_organization, make_on_call_shift, make_schedule +): + organization, user_1 = make_organization_and_user() + + schedule = make_schedule(organization, schedule_class=OnCallScheduleWeb) + now = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + today_weekday = now.weekday() + delta_days = (0 - today_weekday) % 7 + (7 if today_weekday == 0 else 0) + next_week_monday = now + timezone.timedelta(days=delta_days) + + # MO + weekdays = [0] + by_day = [CustomOnCallShift.ICAL_WEEKDAY_MAP[day] for day in weekdays] + data = { + "priority_level": 1, + "start": now + timezone.timedelta(hours=12), + "rotation_start": next_week_monday, + "duration": timezone.timedelta(seconds=3600), + "frequency": CustomOnCallShift.FREQUENCY_DAILY, + "interval": 1, + "by_day": by_day, + "schedule": schedule, + "until": now, + } + rolling_users = [[user_1]] + on_call_shift = make_on_call_shift( + organization=organization, shift_type=CustomOnCallShift.TYPE_ROLLING_USERS_EVENT, **data + ) + on_call_shift.add_rolling_users(rolling_users) + + ical_data = on_call_shift.convert_to_ical() + # empty result since there is no event in the defined time range + assert ical_data == "" From 25998103cc9be9189042b3456c578fc8ac7fb847 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Tue, 3 Jan 2023 13:47:03 +0100 Subject: [PATCH 3/6] swap psycopg2-binary to psycopg2 in requirements.txt (#1062) Fixes issue when running OnCall locally, on an M1 Mac, and using PostgreSQL as the database. (ie. `COMPOSE_PROFILES=postgres...`). Currently getting: ```bash django.db.utils.OperationalError: SCRAM authentication requires libpq version 10 or above ``` I also tried simply adding `libpq-dev` to the `Dockerfile` but this change alone does not solve the issue. See [here](https://github.com/MobSF/Mobile-Security-Framework-MobSF/issues/1898) for a similar reported issue on GitHub. **Root Cause** This issue is caused because `psycopg2-binary` 2.9.3 [doesn't provide](https://pypi.org/project/psycopg2-binary/2.9.3/#files) binary wheels for MacOS arm64; binary wheels for MacOS are only provided for Intel x86 64 bits ([reference](https://stackoverflow.com/a/71653850/3902555)). --- engine/Dockerfile | 1 + engine/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/Dockerfile b/engine/Dockerfile index 72046a3c..dcc0c1ea 100644 --- a/engine/Dockerfile +++ b/engine/Dockerfile @@ -3,6 +3,7 @@ RUN apt-get update && apt-get install -y \ python3-dev \ gcc \ libmariadb-dev \ + libpq-dev \ netcat \ curl \ bash diff --git a/engine/requirements.txt b/engine/requirements.txt index b2122269..6daead27 100644 --- a/engine/requirements.txt +++ b/engine/requirements.txt @@ -37,7 +37,7 @@ https://github.com/grafana/fcm-django/archive/refs/tags/v1.0.12r1.tar.gz django-mirage-field==1.3.0 django-mysql==4.6.0 PyMySQL==1.0.2 -psycopg2-binary==2.9.3 +psycopg2==2.9.3 emoji==1.7.0 regex==2021.11.2 psutil==5.9.4 From d77871046932f4558bb42251c6c64bc76515ebe6 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Tue, 3 Jan 2023 21:07:36 +0800 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdb9a7fd..07afd74f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Alert group query optimization - Update RBAC scopes +- Fix error when schedule was not able to load - Minor bug fixes ## v1.1.8 (2022-12-13) From 4a32b21c46128877ed6cfeb8c902c210538367f3 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Tue, 3 Jan 2023 21:09:00 +0800 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07afd74f..91f42855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v1.1.10 (2023-01-03) + +### Fixed + +- Fix error when schedule was not able to load +- Minor fixes + ## v1.1.9 (2023-01-03) ### Fixed From da51edefcc4d2d1cea4b881b610c84bfe92acd93 Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Tue, 3 Jan 2023 21:50:53 +0800 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91f42855..5d433ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v1.1.10 (2023-01-03) +## v1.1.11 (2023-01-03) ### Fixed - Fix error when schedule was not able to load - Minor fixes +## v1.1.10 (2023-01-03) + +### Fixed + +- Minor fixes + ## v1.1.9 (2023-01-03) ### Fixed