diff --git a/pkg/api/org.go b/pkg/api/org.go index 364a07e2d84..078e9c20d17 100644 --- a/pkg/api/org.go +++ b/pkg/api/org.go @@ -152,7 +152,13 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgID int64) respons // GET /api/orgs/:orgId func DeleteOrgByID(c *models.ReqContext) response.Response { - if err := bus.Dispatch(&models.DeleteOrgCommand{Id: c.ParamsInt64(":orgId")}); err != nil { + orgID := c.ParamsInt64(":orgId") + // before deleting an org, check if user does not belong to the current org + if c.OrgId == orgID { + return response.Error(400, "Can not delete org for current user", nil) + } + + if err := bus.Dispatch(&models.DeleteOrgCommand{Id: orgID}); err != nil { if errors.Is(err, models.ErrOrgNotFound) { return response.Error(404, "Failed to delete organization. ID not found", nil) }