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

Allow viewers fetch cloud connection status #1181

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add Slack slash command allowing to trigger a direct page via a manually created alert group

### Changed

- Allow users with `viewer` role to fetch cloud connection status using the internal API ([#1181](https://github.com/grafana/oncall/pull/1181))

### Fixed

- Removed duplicate API call, in the UI on plugin initial load, to `GET /api/internal/v1/alert_receive_channels`
Expand Down
Empty file.
41 changes: 41 additions & 0 deletions engine/apps/oss_installation/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient

from apps.api.permissions import LegacyAccessControlRole
from apps.oss_installation.models import CloudConnector


@pytest.mark.django_db
def test_cloud_connection_viewer_can_read(
make_organization_and_user_with_plugin_token,
make_user_auth_headers,
):
organization, user, token = make_organization_and_user_with_plugin_token(role=LegacyAccessControlRole.VIEWER)

# create cloud connection
CloudConnector.objects.create(cloud_url="test")

client = APIClient()
url = reverse("oss_installation:cloud-connection-status")

response = client.get(url, **make_user_auth_headers(user, token))
assert response.status_code == status.HTTP_200_OK


@pytest.mark.django_db
def test_cloud_connection_viewer_cant_delete(
make_organization_and_user_with_plugin_token,
make_user_auth_headers,
):
organization, user, token = make_organization_and_user_with_plugin_token(role=LegacyAccessControlRole.VIEWER)

# create cloud connection
CloudConnector.objects.create(cloud_url="test")

client = APIClient()
url = reverse("oss_installation:cloud-connection-status")
response = client.delete(url, **make_user_auth_headers(user, token))

assert response.status_code == status.HTTP_403_FORBIDDEN
2 changes: 2 additions & 0 deletions engine/apps/oss_installation/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .views import CloudConnectionView, CloudHeartbeatView, CloudUsersView, CloudUserView

app_name = "oss_installation"

router = OptionalSlashRouter()
router.register("cloud_users", CloudUserView, basename="cloud-users")

Expand Down
2 changes: 1 addition & 1 deletion engine/apps/oss_installation/views/cloud_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CloudConnectionView(APIView):
authentication_classes = (PluginAuthentication,)
permission_classes = (IsAuthenticated, RBACPermission)
rbac_permissions = {
"get": [RBACPermission.Permissions.OTHER_SETTINGS_WRITE],
"get": [RBACPermission.Permissions.OTHER_SETTINGS_READ],
"delete": [RBACPermission.Permissions.OTHER_SETTINGS_WRITE],
}

Expand Down
2 changes: 1 addition & 1 deletion engine/engine/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

if settings.OSS_INSTALLATION:
urlpatterns += [
path("api/internal/v1/", include("apps.oss_installation.urls")),
path("api/internal/v1/", include("apps.oss_installation.urls", namespace="oss_installation")),
]

if settings.DEBUG:
Expand Down