Move pending signature requests on minor publish
When a new minor version is published, still-REQUESTED signature requests on the previous version now move onto the newly published version, keeping the same signature row so the notification schedule (count and last-notified time) is preserved. SIGNED signatures are left untouched. Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
@@ -728,6 +728,47 @@ WHERE
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pvss *DocumentVersionSignatures) MoveRequestedToVersionWithinMajor(
|
||||
ctx context.Context,
|
||||
conn pg.Tx,
|
||||
scope Scoper,
|
||||
targetVersionID gid.GID,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE document_version_signatures
|
||||
SET
|
||||
document_version_id = @target_version_id,
|
||||
updated_at = @now
|
||||
WHERE
|
||||
%s
|
||||
AND state = @state
|
||||
AND document_version_id <> @target_version_id
|
||||
AND document_version_id IN (
|
||||
SELECT dv.id
|
||||
FROM document_versions dv
|
||||
INNER JOIN document_versions target
|
||||
ON target.document_id = dv.document_id
|
||||
AND target.major = dv.major
|
||||
WHERE target.id = @target_version_id
|
||||
)
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"target_version_id": targetVersionID,
|
||||
"state": DocumentVersionSignatureStateRequested,
|
||||
"now": time.Now(),
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
if _, err := conn.Exec(ctx, q, args); err != nil {
|
||||
return fmt.Errorf("cannot move requested document version signatures to the newly published version: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pvss *DocumentVersionSignatures) DeleteRequestedByDocumentIDBelowMajor(
|
||||
ctx context.Context,
|
||||
conn pg.Tx,
|
||||
|
||||
@@ -2889,9 +2889,31 @@ func (s *DocumentService) publishMinorVersionInTx(
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err := s.moveRequestedSignaturesToVersionInTx(ctx, scope, tx, documentVersion.ID); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return document, documentVersion, nil
|
||||
}
|
||||
|
||||
// moveRequestedSignaturesToVersionInTx carries every still-pending signature
|
||||
// request from a prior minor of the same major onto the newly published minor
|
||||
// version. The new minor supersedes the previous one while keeping the same
|
||||
// signing obligations, so REQUESTED signatures follow along with their
|
||||
// notification schedule (time and count) intact. SIGNED signatures stay put.
|
||||
func (s *DocumentService) moveRequestedSignaturesToVersionInTx(
|
||||
ctx context.Context, scope coredata.Scoper,
|
||||
tx pg.Tx,
|
||||
documentVersionID gid.GID,
|
||||
) error {
|
||||
signatures := &coredata.DocumentVersionSignatures{}
|
||||
if err := signatures.MoveRequestedToVersionWithinMajor(ctx, tx, scope, documentVersionID); err != nil {
|
||||
return fmt.Errorf("cannot move signature requests to the newly published minor version: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) generateAndUploadPublicationPDF(
|
||||
ctx context.Context, scope coredata.Scoper,
|
||||
documentVersion *coredata.DocumentVersion,
|
||||
|
||||
Reference in New Issue
Block a user