Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schedules enable_web_overrides option to public API #3062

Merged
merged 2 commits into from
Sep 26, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Unify breadcrumbs behaviour with other Grafana Apps and main core ([#1906](https://github.com/grafana/oncall/issues/1906))
- Add `enable_web_overrides` option to schedules public API ([#3062](https://github.com/grafana/oncall/pull/3062))

### Fixed

1 change: 1 addition & 0 deletions docs/sources/oncall-api-reference/schedules.md
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ The above command returns JSON structured in the following way:
| `time_zone` | No | Optional | Schedule time zone. Is used for manually added on-call shifts in Schedules with type `calendar`. Default time zone is `UTC`. For more information about time zones, see [time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). |
| `ical_url_primary` | No | If type = `ical` | URL of external iCal calendar for schedule with type `ical`. |
| `ical_url_overrides` | No | Optional | URL of external iCal calendar for schedule with any type. Events from this calendar override events from primary calendar or from on-call shifts. |
| `enable_web_overrides` | No | Optional | Whether to enable web overrides or not. Setting specific for API/Terraform based schedules (`calendar` type). |
| `slack` | No | Optional | Dictionary with Slack-specific settings for a schedule. Includes `channel_id` and `user_group_id` fields, that take a channel ID and a user group ID from Slack. |
| `shifts` | No | Optional | List of shifts. Used for manually added on-call shifts in Schedules with type `calendar`. |

4 changes: 4 additions & 0 deletions engine/apps/public_api/serializers/schedules_calendar.py
Original file line number Diff line number Diff line change
@@ -28,9 +28,11 @@ class Meta:
"on_call_now",
"shifts",
"ical_url_overrides",
"enable_web_overrides",
]
extra_kwargs = {
"ical_url_overrides": {"required": False, "allow_null": True},
"enable_web_overrides": {"required": False, "allow_null": True},
}

def validate_shifts(self, shifts):
@@ -61,10 +63,12 @@ class Meta:
"on_call_now",
"shifts",
"ical_url_overrides",
"enable_web_overrides",
]
extra_kwargs = {
"name": {"required": False},
"ical_url_overrides": {"required": False, "allow_null": True},
"enable_web_overrides": {"required": False, "allow_null": True},
}

def update(self, instance, validated_data):
46 changes: 46 additions & 0 deletions engine/apps/public_api/tests/test_schedules.py
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ def test_get_calendar_schedule(
"user_group_id": None,
},
"ical_url_overrides": None,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_200_OK
@@ -130,6 +131,7 @@ def test_create_calendar_schedule(make_organization_and_user_with_token):
"user_group_id": None,
},
"ical_url_overrides": None,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_201_CREATED
@@ -180,6 +182,7 @@ def test_create_calendar_schedule_with_shifts(make_organization_and_user_with_to
"user_group_id": None,
},
"ical_url_overrides": None,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_201_CREATED
@@ -227,6 +230,7 @@ def test_update_calendar_schedule(
"user_group_id": None,
},
"ical_url_overrides": None,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_200_OK
@@ -236,6 +240,45 @@ def test_update_calendar_schedule(
assert response.json() == result


@pytest.mark.django_db
def test_update_calendar_schedule_enable_web_overrides(
make_organization_and_user_with_token,
make_schedule,
):
organization, user, token = make_organization_and_user_with_token()
client = APIClient()

schedule = make_schedule(
organization,
schedule_class=OnCallScheduleCalendar,
)

url = reverse("api-public:schedules-detail", kwargs={"pk": schedule.public_primary_key})

data = {
"enable_web_overrides": True,
}
response = client.put(url, data=data, format="json", HTTP_AUTHORIZATION=f"{token}")

result = {
"id": schedule.public_primary_key,
"team_id": None,
"name": schedule.name,
"type": "calendar",
"time_zone": "UTC",
"on_call_now": [],
"shifts": [],
"slack": {"channel_id": None, "user_group_id": None},
"ical_url_overrides": None,
"enable_web_overrides": True,
}

assert response.status_code == status.HTTP_200_OK
schedule.refresh_from_db()
assert schedule.enable_web_overrides
assert response.json() == result


@pytest.mark.django_db
def test_get_web_schedule(
make_organization_and_user_with_token,
@@ -363,6 +406,7 @@ def test_update_ical_url_overrides_calendar_schedule(
"user_group_id": None,
},
"ical_url_overrides": ICAL_URL,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_200_OK
@@ -418,6 +462,7 @@ def test_update_calendar_schedule_with_custom_event(
"user_group_id": None,
},
"ical_url_overrides": None,
"enable_web_overrides": False,
}

assert response.status_code == status.HTTP_200_OK
@@ -732,6 +777,7 @@ def test_get_schedule_list(
"shifts": [],
"slack": {"channel_id": slack_channel_id, "user_group_id": user_group_id},
"ical_url_overrides": None,
"enable_web_overrides": False,
},
{
"id": schedule_ical.public_primary_key,