Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(dashboard): delete dashboard shouldn't break on license check (#9984)

Vikrant Gupta99b9e27bca28
diff --git a/ee/modules/dashboard/impldashboard/module.go b/ee/modules/dashboard/impldashboard/module.go
index 1777ae992f..76697b56c9 100644
--- a/ee/modules/dashboard/impldashboard/module.go
+++ b/ee/modules/dashboard/impldashboard/module.go
@@ -163,7 +163,7 @@ func (module *module) Delete(ctx context.Context, orgID valuer.UUID, id valuer.U
}
err = module.store.RunInTx(ctx, func(ctx context.Context) error {
- err := module.DeletePublic(ctx, orgID, id)
+ err := module.deletePublic(ctx, orgID, id)
if err != nil && !errors.Ast(err, errors.TypeNotFound) {
return err
}
@@ -263,3 +263,35 @@ func (module *module) Update(ctx context.Context, orgID valuer.UUID, id valuer.U
func (module *module) LockUnlock(ctx context.Context, orgID valuer.UUID, id valuer.UUID, updatedBy string, role types.Role, lock bool) error {
return module.pkgDashboardModule.LockUnlock(ctx, orgID, id, updatedBy, role, lock)
}
+
+func (module *module) deletePublic(ctx context.Context, orgID valuer.UUID, dashboardID valuer.UUID) error {
+ publicDashboard, err := module.store.GetPublic(ctx, dashboardID.String())
+ if err != nil {
+ return err
+ }
+
+ role, err := module.role.GetOrCreate(ctx, roletypes.NewRole(roletypes.AnonymousUserRoleName, roletypes.AnonymousUserRoleDescription, roletypes.RoleTypeManaged.StringValue(), orgID))
+ if err != nil {
+ return err
+ }
+
+ deletionObject := authtypes.MustNewObject(
+ authtypes.Resource{
+ Name: dashboardtypes.TypeableMetaResourcePublicDashboard.Name(),
+ Type: authtypes.TypeMetaResource,
+ },
+ authtypes.MustNewSelector(authtypes.TypeMetaResource, publicDashboard.ID.String()),
+ )
+
+ err = module.role.PatchObjects(ctx, orgID, role.ID, authtypes.RelationRead, nil, []*authtypes.Object{deletionObject})
+ if err != nil {
+ return err
+ }
+
+ err = module.store.DeletePublic(ctx, dashboardID.StringValue())
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/tests/integration/src/dashboard/01_dashboard.py b/tests/integration/src/dashboard/01_dashboard.py
new file mode 100644
index 0000000000..4eefe6039b
--- /dev/null
+++ b/tests/integration/src/dashboard/01_dashboard.py
@@ -0,0 +1,80 @@
+from http import HTTPStatus
+from typing import Callable, List
+
+import requests
+from wiremock.resources.mappings import Mapping
+
+from fixtures.auth import USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD, add_license
+from fixtures.types import Operation, SigNoz, TestContainerDocker
+
+
+def test_create_and_delete_dashboard_without_license(
+ signoz: SigNoz,
+ create_user_admin: Operation, # pylint: disable=unused-argument
+ get_token: Callable[[str, str], str],
+):
+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
+
+ response = requests.post(
+ signoz.self.host_configs["8080"].get("/api/v1/dashboards"),
+ json={"title": "Sample Title", "uploadedGrafana": False, "version": "v5"},
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.CREATED
+ assert response.json()["status"] == "success"
+ data = response.json()["data"]
+ dashboard_id = data["id"]
+
+ response = requests.delete(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/dashboards/{dashboard_id}"
+ ),
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.NO_CONTENT
+
+def test_apply_license(
+ signoz: SigNoz,
+ create_user_admin: Operation, # pylint: disable=unused-argument
+ make_http_mocks: Callable[[TestContainerDocker, List[Mapping]], None],
+ get_token: Callable[[str, str], str],
+) -> None:
+ """
+ This applies a license to the signoz instance.
+ """
+ add_license(signoz, make_http_mocks, get_token)
+
+
+
+def test_create_and_delete_dashboard_with_license(
+ signoz: SigNoz,
+ create_user_admin: Operation, # pylint: disable=unused-argument
+ get_token: Callable[[str, str], str],
+):
+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
+
+ response = requests.post(
+ signoz.self.host_configs["8080"].get("/api/v1/dashboards"),
+ json={"title": "Sample Title", "uploadedGrafana": False, "version": "v5"},
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.CREATED
+ assert response.json()["status"] == "success"
+ data = response.json()["data"]
+ dashboard_id = data["id"]
+
+ response = requests.delete(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/dashboards/{dashboard_id}"
+ ),
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.NO_CONTENT
\ No newline at end of file
diff --git a/tests/integration/src/dashboard/01_public_dashboard.py b/tests/integration/src/dashboard/02_public_dashboard.py
similarity index 100%
rename from tests/integration/src/dashboard/01_public_dashboard.py
rename to tests/integration/src/dashboard/02_public_dashboard.py