Skip to content

Commit

Permalink
Add schedules enable_web_overrides option to public API (#3062)
Browse files Browse the repository at this point in the history
Related updates (to be merged afterwards):
- grafana/amixr-api-go-client#14
- grafana/terraform-provider-grafana#1056
  • Loading branch information
matiasb authored Sep 26, 2023
1 parent cc337d1 commit 9ead70a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions docs/sources/oncall-api-reference/schedules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |

Expand Down
4 changes: 4 additions & 0 deletions engine/apps/public_api/serializers/schedules_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
46 changes: 46 additions & 0 deletions engine/apps/public_api/tests/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9ead70a

Please sign in to comment.