Skip to content

Commit

Permalink
Move locked doc check in approvals API
Browse files Browse the repository at this point in the history
  • Loading branch information
jfreda committed Jun 4, 2024
1 parent e44e932 commit 6c9aa06
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions internal/api/v2/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6c9aa06

Please sign in to comment.