Skip to content

Commit

Permalink
Add members of approver groups as individual approvers in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
jfreda committed Mar 27, 2024
1 parent 740581f commit 96b23e0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion internal/api/v2/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,28 @@ func ApprovalsHandler(srv server.Server) http.Handler {
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)

// Add approver in database.
model.Approvers = append(model.Approvers, &models.User{
EmailAddress: userEmail,
})
if err := model.Upsert(srv.DB); err != nil {
srv.Logger.Error(
"error updating document in the database to add approver",
"error", err,
"method", r.Method,
"path", r.URL.Path,
"doc_id", docID,
)
http.Error(w, "Error approving document",
http.StatusInternalServerError)
return
}
}

// Add email to slice of users who have approved the document.
doc.ApprovedBy = append(doc.ApprovedBy, userEmail)

Expand Down Expand Up @@ -433,7 +455,7 @@ func ApprovalsHandler(srv server.Server) http.Handler {
"path", r.URL.Path,
"doc_id", docID,
"rev_id", latestRev.Id)
http.Error(w, "Error creating review",
http.Error(w, "Error approving document",
http.StatusInternalServerError)
return
}
Expand Down

0 comments on commit 96b23e0

Please sign in to comment.