klesh commented on code in PR #5506:
URL: 
https://github.com/apache/incubator-devlake/pull/5506#discussion_r1231991361


##########
backend/helpers/pluginhelper/api/connection_helper.go:
##########
@@ -101,8 +104,16 @@ func (c *ConnectionApiHelper) List(connections 
interface{}) errors.Error {
 }
 
 // Delete connection
-func (c *ConnectionApiHelper) Delete(connection interface{}) errors.Error {
-       return CallDB(c.db.Delete, connection)
+func (c *ConnectionApiHelper) Delete(plugin string, connection interface{}) 
(*services.BlueprintProjectPairs, errors.Error) {
+       connectionId := reflectField(connection, "ID").Uint()
+       referencingBps, err := c.bpManager.GetBlueprintsByConnection(plugin, 
connectionId)
+       if err != nil {
+               return nil, err
+       }
+       if len(referencingBps) > 0 {
+               return services.NewBlueprintProjectPairs(referencingBps), 
errors.Conflict.New("Found one or more references to this connection")
+       }
+       return nil, CallDB(c.db.Delete, connection)

Review Comment:
   also need to check if there are scopes referencing the connection



##########
backend/helpers/pluginhelper/api/scope_generic_helper.go:
##########
@@ -288,43 +290,49 @@ func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
GetScope(input *plugin.ApiReso
        return scopeRes, nil
 }
 
-func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) DeleteScope(input 
*plugin.ApiResourceInput) errors.Error {
+func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) DeleteScope(input 
*plugin.ApiResourceInput) (*serviceHelper.BlueprintProjectPairs, errors.Error) {
        params, err := gs.extractFromDeleteReqParam(input)
        if err != nil {
-               return err
+               return nil, err
        }
        err = gs.dbHelper.VerifyConnection(params.connectionId)
        if err != nil {
-               return errors.Default.Wrap(err, fmt.Sprintf("error verifying 
connection for connection ID %d", params.connectionId))
+               return nil, errors.Default.Wrap(err, fmt.Sprintf("error 
verifying connection for connection ID %d", params.connectionId))
+       }
+       if refs, err := gs.getScopeReferences(input.GetPlugin(), 
params.connectionId, params.scopeId); err != nil || refs != nil {

Review Comment:
   We should allow users to clean the scope even if it is referenced 



##########
backend/helpers/pluginhelper/api/connection_helper.go:
##########
@@ -101,8 +104,16 @@ func (c *ConnectionApiHelper) List(connections 
interface{}) errors.Error {
 }
 
 // Delete connection
-func (c *ConnectionApiHelper) Delete(connection interface{}) errors.Error {
-       return CallDB(c.db.Delete, connection)
+func (c *ConnectionApiHelper) Delete(plugin string, connection interface{}) 
(*services.BlueprintProjectPairs, errors.Error) {

Review Comment:
   Let us move the `plugin` to the `ConnectionHelper` as a field. We should 
refactor it as a Generic type in the future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to