Commit 5a0fc434 by Carl Bergquist Committed by GitHub

Merge pull request #6722 from dpavlos/fix_6679

[6679] Check if org exists before delete it
parents b00e9390 0064331b
...@@ -152,6 +152,9 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons ...@@ -152,6 +152,9 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons
// GET /api/orgs/:orgId // GET /api/orgs/:orgId
func DeleteOrgById(c *middleware.Context) Response { func DeleteOrgById(c *middleware.Context) Response {
if err := bus.Dispatch(&m.DeleteOrgCommand{Id: c.ParamsInt64(":orgId")}); err != nil { if err := bus.Dispatch(&m.DeleteOrgCommand{Id: c.ParamsInt64(":orgId")}); err != nil {
if err == m.ErrOrgNotFound {
return ApiError(404, "Failed to delete organization. ID not found", nil)
}
return ApiError(500, "Failed to update organization", err) return ApiError(500, "Failed to update organization", err)
} }
return ApiSuccess("Organization deleted") return ApiSuccess("Organization deleted")
......
...@@ -176,6 +176,12 @@ func UpdateOrgAddress(cmd *m.UpdateOrgAddressCommand) error { ...@@ -176,6 +176,12 @@ func UpdateOrgAddress(cmd *m.UpdateOrgAddressCommand) error {
func DeleteOrg(cmd *m.DeleteOrgCommand) error { func DeleteOrg(cmd *m.DeleteOrgCommand) error {
return inTransaction2(func(sess *session) error { return inTransaction2(func(sess *session) error {
//Check if organization exists
if res, err := sess.Query("SELECT 1 from org WHERE id=?", cmd.Id); err != nil {
return err
} else if len(res) != 1 {
return m.ErrOrgNotFound
}
deletes := []string{ deletes := []string{
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ? AND star.dashboard_id = dashboard.id)", "DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE org_id = ? AND star.dashboard_id = dashboard.id)",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment