Fix inconsistency with API URL returned by plugin status (#3122)

# What this PR does
Change status to return backend URL in the same way (trailing /) that is
used to build URLs throughout by using create_engine_url utility
function.

## Which issue(s) this PR fixes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
This commit is contained in:
Michael Derynck 2023-10-16 11:38:08 -06:00 committed by GitHub
parent ae85ce3d55
commit f40e0463d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View file

@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update plugin OnCaller role permissions ([#3145](https://github.com/grafana/oncall/pull/3145))
### Fixed
- Fix plugin status to always return URL with trailing / @mderynck ([#3122](https://github.com/grafana/oncall/pull/3122))
## v1.3.43 (2023-10-05)
### Added

View file

@ -10,9 +10,11 @@ GRAFANA_TOKEN = "TESTTOKEN"
GRAFANA_URL = "hello.com"
LICENSE = "asdfasdf"
VERSION = "asdfasdfasdf"
BASE_URL = "http://asdasdqweqweqw.com/oncall"
BASE_URL = "http://asdasdqweqweqw.com/oncall/"
BASE_URL_NO_TRAILING_SLASH = "http://asdasdqweqweqw.com/oncall"
GRAFANA_CONTEXT_DATA = {"IsAnonymous": False}
SETTINGS = {"LICENSE": LICENSE, "VERSION": VERSION, "BASE_URL": BASE_URL}
SETTINGS_ALT = SETTINGS | {"BASE_URL": BASE_URL_NO_TRAILING_SLASH}
def _check_status_response(auth_headers, client):
@ -86,3 +88,18 @@ def test_status_mobile_app_auth_token(
auth_headers = {"HTTP_AUTHORIZATION": f"{auth_token}"}
_check_status_response(auth_headers, client)
@pytest.mark.django_db
@override_settings(**SETTINGS_ALT)
def test_status_base_url_trailing_slash(make_organization_and_user_with_plugin_token, make_user_auth_headers):
organization, user, token = make_organization_and_user_with_plugin_token()
organization.grafana_url = GRAFANA_URL
organization.api_token_status = Organization.API_TOKEN_STATUS_OK
organization.save(update_fields=["grafana_url", "api_token_status"])
client = APIClient()
auth_headers = make_user_auth_headers(
user, token, grafana_token=GRAFANA_TOKEN, grafana_context_data=GRAFANA_CONTEXT_DATA
)
_check_status_response(auth_headers, client)

View file

@ -9,6 +9,7 @@ from apps.grafana_plugin.tasks.sync import plugin_sync_organization_async
from apps.mobile_app.auth import MobileAppAuthTokenAuthentication
from apps.user_management.models import Organization
from common.api_helpers.mixins import GrafanaHeadersMixin
from common.api_helpers.utils import create_engine_url
class StatusView(GrafanaHeadersMixin, APIView):
@ -35,14 +36,14 @@ class StatusView(GrafanaHeadersMixin, APIView):
is_installed = False
token_ok = False
allow_signup = True
api_url = settings.BASE_URL
api_url = create_engine_url("")
# Check if organization is in OnCall database
if organization:
is_installed = True
token_ok = organization.api_token_status == Organization.API_TOKEN_STATUS_OK
if organization.is_moved:
api_url = organization.migration_destination.oncall_backend_url
api_url = create_engine_url("", override_base=organization.migration_destination.oncall_backend_url)
else:
allow_signup = DynamicSetting.objects.get_or_create(
name="allow_plugin_organization_signup", defaults={"boolean_value": True}