You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2018/05/17 02:25:50 UTC

[incubator-trafficcontrol] 04/17: verify role is not in use before deletion

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit 3d867a55052913407ea8cd46519b98427e683594
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Wed Apr 11 15:55:18 2018 -0600

    verify role is not in use before deletion
---
 traffic_ops/traffic_ops_golang/role/roles.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/traffic_ops/traffic_ops_golang/role/roles.go b/traffic_ops/traffic_ops_golang/role/roles.go
index 82a3e8b..4466711 100644
--- a/traffic_ops/traffic_ops_golang/role/roles.go
+++ b/traffic_ops/traffic_ops_golang/role/roles.go
@@ -269,6 +269,16 @@ func (role *TORole) Delete(db *sqlx.DB, user auth.CurrentUser) (error, tc.ApiErr
 		log.Error.Printf("could not begin transaction: %v", err)
 		return tc.DBError, tc.SystemError
 	}
+	assignedUsers := 0
+	err = tx.Select(&assignedUsers, "SELECT COUNT(id) FROM tm_user WHERE role=$1", role.ID)
+	if err != nil {
+		log.Errorf("received error: %++v from assigned users check", err)
+		return tc.DBError, tc.SystemError
+	}
+	if assignedUsers != 0 {
+		return fmt.Errorf("can not delete a role with %d assigned users", assignedUsers), tc.DataConflictError
+	}
+
 	log.Debugf("about to run exec query: %s with role: %++v", deleteQuery(), role)
 	result, err := tx.NamedExec(deleteQuery(), role)
 	if err != nil {

-- 
To stop receiving notification emails like this one, please contact
mitchell852@apache.org.