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:
@@ -42,6 +42,12 @@ const versionFragment = graphql`
|
|||||||
fragment DocumentSignaturePlaceholder_versionFragment on DocumentVersion {
|
fragment DocumentSignaturePlaceholder_versionFragment on DocumentVersion {
|
||||||
id
|
id
|
||||||
status
|
status
|
||||||
|
major
|
||||||
|
minor
|
||||||
|
document {
|
||||||
|
currentPublishedMajor
|
||||||
|
currentPublishedMinor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -81,6 +87,11 @@ export function DocumentSignaturePlaceholder(props: {
|
|||||||
const person = useFragment<DocumentSignaturePlaceholder_personFragment$key>(personFragment, personFragmentRef);
|
const person = useFragment<DocumentSignaturePlaceholder_personFragment$key>(personFragment, personFragmentRef);
|
||||||
const version = useFragment<DocumentSignaturePlaceholder_versionFragment$key>(versionFragment, versionFragmentRef);
|
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(
|
const [requestSignature, isSendingRequest] = useMutationWithToasts(
|
||||||
requestSignatureMutation,
|
requestSignatureMutation,
|
||||||
{
|
{
|
||||||
@@ -99,7 +110,7 @@ export function DocumentSignaturePlaceholder(props: {
|
|||||||
{person.emailAddress}
|
{person.emailAddress}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{version.status === "PUBLISHED" && canRequestSignature && (
|
{isCurrentPublishedVersion && canRequestSignature && (
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
className="ml-auto"
|
className="ml-auto"
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ type (
|
|||||||
ErrDocumentVersionNotPublished struct {
|
ErrDocumentVersionNotPublished struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrDocumentVersionNotCurrent struct {
|
||||||
|
}
|
||||||
|
|
||||||
ErrDocumentVersionPendingApproval struct {
|
ErrDocumentVersionPendingApproval struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,6 +273,10 @@ func (e ErrDocumentVersionNotPublished) Error() string {
|
|||||||
return "document version is not published"
|
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 {
|
func (e ErrDocumentVersionPendingApproval) Error() string {
|
||||||
return "cannot publish a document version that is pending approval"
|
return "cannot publish a document version that is pending approval"
|
||||||
}
|
}
|
||||||
@@ -1104,6 +1111,13 @@ func (s *DocumentService) RequestSignature(
|
|||||||
return &ErrDocumentVersionNotPublished{}
|
return &ErrDocumentVersionNotPublished{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if document.CurrentPublishedMajor == nil ||
|
||||||
|
document.CurrentPublishedMinor == nil ||
|
||||||
|
documentVersion.Major != *document.CurrentPublishedMajor ||
|
||||||
|
documentVersion.Minor != *document.CurrentPublishedMinor {
|
||||||
|
return &ErrDocumentVersionNotCurrent{}
|
||||||
|
}
|
||||||
|
|
||||||
profile := &coredata.MembershipProfile{}
|
profile := &coredata.MembershipProfile{}
|
||||||
if err := profile.LoadByID(ctx, tx, scope, req.Signatory); err != nil {
|
if err := profile.LoadByID(ctx, tx, scope, req.Signatory); err != nil {
|
||||||
return fmt.Errorf("cannot load signatory profile: %w", err)
|
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)
|
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 {
|
if errContractEnded, ok := errors.AsType[*probo.ErrProfileContractEnded](err); ok {
|
||||||
return nil, gqlutils.Conflict(ctx, errContractEnded)
|
return nil, gqlutils.Conflict(ctx, errContractEnded)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2456,6 +2456,10 @@ func (r *Resolver) RequestDocumentVersionSignatureTool(ctx context.Context, req
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
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))
|
panic(fmt.Errorf("cannot request signature: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user