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:
@@ -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)
|
||||
|
||||
@@ -1337,6 +1337,10 @@ func (r *mutationResolver) RequestSignature(ctx context.Context, input types.Req
|
||||
return nil, gqlutils.Conflict(ctx, errNotPublished)
|
||||
}
|
||||
|
||||
if errNotCurrent, ok := errors.AsType[*probo.ErrDocumentVersionNotCurrent](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errNotCurrent)
|
||||
}
|
||||
|
||||
if errContractEnded, ok := errors.AsType[*probo.ErrProfileContractEnded](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errContractEnded)
|
||||
}
|
||||
|
||||
@@ -2456,6 +2456,10 @@ func (r *Resolver) RequestDocumentVersionSignatureTool(ctx context.Context, req
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*probo.ErrDocumentVersionNotCurrent](err); ok {
|
||||
return nil, types.RequestDocumentVersionSignatureOutput{}, fmt.Errorf("cannot request signature: %w", err)
|
||||
}
|
||||
|
||||
panic(fmt.Errorf("cannot request signature: %w", err))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user