From a78e715293733924de2f272900efe80a52e0bb0f Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Fri, 8 May 2026 12:30:31 +0800 Subject: [PATCH] refactor(instance): remove redundant instance ownership checks The ownership validation is now handled at an earlier stage in the request processing, making these checks redundant. This change simplifies the code by removing duplicate validation logic. --- handlers/instance.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/handlers/instance.go b/handlers/instance.go index a351159..1d833ed 100644 --- a/handlers/instance.go +++ b/handlers/instance.go @@ -537,7 +537,7 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - instance, err := database.DBQueryFrpcInstanceByID(instanceID) + // instance, err := database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start a not existed instance: %d", userID, instanceID)) @@ -549,11 +549,11 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") - postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start instance %d that does not belong to them", userID, instanceID)) - return - } + // if instance.UserID != userID { + // utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") + // postLog.Error(fmt.Sprintf("[StartInstanceHandler] User %d tried to start instance %d that does not belong to them", userID, instanceID)) + // return + // } initType := sys.GetInitSystem() sysName, err := database.GetServiceNameByInstanceID(instanceID) @@ -665,7 +665,7 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - instance, err := database.DBQueryFrpcInstanceByID(instanceID) + // instance, err := database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop a not existed instance: %d", userID, instanceID)) @@ -677,11 +677,11 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") - postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop instance %d that does not belong to them", userID, instanceID)) - return - } + // if instance.UserID != userID { + // utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") + // postLog.Error(fmt.Sprintf("[StopInstanceHandler] User %d tried to stop instance %d that does not belong to them", userID, instanceID)) + // return + // } initType := sys.GetInitSystem() serviceName, err := database.GetServiceNameByInstanceID(instanceID) @@ -781,7 +781,7 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - instance, err := database.DBQueryFrpcInstanceByID(instanceID) + // instance, err := database.DBQueryFrpcInstanceByID(instanceID) if err == sql.ErrNoRows { utils.SendErrorResponse(w, http.StatusNotFound, "Instance not found") postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart a not existed instance: %d", userID, instanceID)) @@ -793,11 +793,11 @@ func RestartInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - if instance.UserID != userID { - utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") - postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart instance %d that does not belong to them", userID, instanceID)) - return - } + // if instance.UserID != userID { + // utils.SendErrorResponse(w, http.StatusForbidden, "Instance not found") + // postLog.Error(fmt.Sprintf("[RestartInstanceHandler] User %d tried to restart instance %d that does not belong to them", userID, instanceID)) + // return + // } initType := sys.GetInitSystem() sysName, err := database.GetServiceNameByInstanceID(instanceID)