diff --git a/internal/api/v2/approvals.go b/internal/api/v2/approvals.go index 1bf6f0693..953fb0462 100644 --- a/internal/api/v2/approvals.go +++ b/internal/api/v2/approvals.go @@ -27,24 +27,6 @@ func ApprovalsHandler(srv server.Server) http.Handler { return } - // Check if document is locked. - locked, err := hcd.IsLocked(docID, srv.DB, srv.GWService, srv.Logger) - if err != nil { - srv.Logger.Error("error checking document locked status", - "error", err, - "path", r.URL.Path, - "method", r.Method, - "doc_id", docID, - ) - http.Error(w, "Error getting document status", http.StatusNotFound) - return - } - // Don't continue if document is locked. - if locked { - http.Error(w, "Document is locked", http.StatusLocked) - return - } - // Get document from database. model := models.Document{ GoogleFileID: docID, @@ -130,6 +112,24 @@ func ApprovalsHandler(srv server.Server) http.Handler { return } + // Check if document is locked. + locked, err := hcd.IsLocked(docID, srv.DB, srv.GWService, srv.Logger) + if err != nil { + srv.Logger.Error("error checking document locked status", + "error", err, + "path", r.URL.Path, + "method", r.Method, + "doc_id", docID, + ) + http.Error(w, "Error getting document status", http.StatusNotFound) + return + } + // Don't continue if document is locked. + if locked { + http.Error(w, "Document is locked", http.StatusLocked) + return + } + // Add email to slice of users who have requested changes of the document. doc.ChangesRequestedBy = append(doc.ChangesRequestedBy, userEmail) @@ -398,6 +398,24 @@ func ApprovalsHandler(srv server.Server) http.Handler { return } + // Check if document is locked. + locked, err := hcd.IsLocked(docID, srv.DB, srv.GWService, srv.Logger) + if err != nil { + srv.Logger.Error("error checking document locked status", + "error", err, + "path", r.URL.Path, + "method", r.Method, + "doc_id", docID, + ) + http.Error(w, "Error getting document status", http.StatusNotFound) + return + } + // Don't continue if document is locked. + if locked { + http.Error(w, "Document is locked", http.StatusLocked) + return + } + // If the user is a group approver, they won't be in the approvers list. if !contains(doc.Approvers, userEmail) { doc.Approvers = append(doc.Approvers, userEmail)