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

@@ -42,6 +42,12 @@ const versionFragment = graphql`
fragment DocumentSignaturePlaceholder_versionFragment on DocumentVersion {
id
status
major
minor
document {
currentPublishedMajor
currentPublishedMinor
}
}
`;
@@ -81,6 +87,11 @@ export function DocumentSignaturePlaceholder(props: {
const person = useFragment<DocumentSignaturePlaceholder_personFragment$key>(personFragment, personFragmentRef);
const version = useFragment<DocumentSignaturePlaceholder_versionFragment$key>(versionFragment, versionFragmentRef);
const isCurrentPublishedVersion
= version.status === "PUBLISHED"
&& version.document.currentPublishedMajor === version.major
&& version.document.currentPublishedMinor === version.minor;
const [requestSignature, isSendingRequest] = useMutationWithToasts(
requestSignatureMutation,
{
@@ -99,7 +110,7 @@ export function DocumentSignaturePlaceholder(props: {
{person.emailAddress}
</div>
</div>
{version.status === "PUBLISHED" && canRequestSignature && (
{isCurrentPublishedVersion && canRequestSignature && (
<Button
variant="secondary"
className="ml-auto"

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)

View File

@@ -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)
}

View File

@@ -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))
}