Allow signature requests only on current published version

Requesting a signature only validated that the version was PUBLISHED, so a
signature could be requested on a superseded (older) published version. Reject
versions that are not the document's current published major/minor, and hide
the request button in the console for non-current versions.

Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
Sacha Al Himdani
2026-06-22 18:30:26 +02:00
parent 9093be79f4
commit a8e8e3e0e7
4 changed files with 34 additions and 1 deletions

View File

@@ -68,6 +68,9 @@ type (
ErrDocumentVersionNotPublished struct {
}
ErrDocumentVersionNotCurrent struct {
}
ErrDocumentVersionPendingApproval struct {
}
@@ -270,6 +273,10 @@ func (e ErrDocumentVersionNotPublished) Error() string {
return "document version is not published"
}
func (e ErrDocumentVersionNotCurrent) Error() string {
return "document version is not the current published version"
}
func (e ErrDocumentVersionPendingApproval) Error() string {
return "cannot publish a document version that is pending approval"
}
@@ -1104,6 +1111,13 @@ func (s *DocumentService) RequestSignature(
return &ErrDocumentVersionNotPublished{}
}
if document.CurrentPublishedMajor == nil ||
document.CurrentPublishedMinor == nil ||
documentVersion.Major != *document.CurrentPublishedMajor ||
documentVersion.Minor != *document.CurrentPublishedMinor {
return &ErrDocumentVersionNotCurrent{}
}
profile := &coredata.MembershipProfile{}
if err := profile.LoadByID(ctx, tx, scope, req.Signatory); err != nil {
return fmt.Errorf("cannot load signatory profile: %w", err)