Consolidate document draft management into updateDocument
Replace the three separate draft mutations (createDraftDocumentVersion, updateDocumentVersion, deleteDraftDocumentVersion) with automatic draft lifecycle management inside updateDocument. The backend now auto-creates a draft when a published document is edited, updates the existing draft on subsequent edits, and auto-deletes the draft when content reverts to match the published version. A new deleteDocumentDraft mutation provides explicit draft deletion. Backend: - Merge version-level fields (content, title, classification, documentType) into UpdateDocumentRequest - Convert CreateDraft, UpdateVersion, DeleteDraft into private transaction helpers called from Update - Update returns (*Document, *DocumentVersion, error) with the version present only when a draft exists Frontend: - Remove all create/update/delete draft mutations from components - Auto-save via updateDocument with layout refetch on draft status transitions while preserving editor cursor (data-generation key) - Title, type, and classification editable on published versions (backend auto-creates draft) - Forms use react-hook-form values option to stay synced with Relay fragment data across draft/publish transitions API surface (GraphQL, MCP, CLI, n8n) updated consistently: - Removed: createDraftDocumentVersion, updateDocumentVersion, deleteDraftDocumentVersion - Added: deleteDocumentDraft (document-level) - Updated: updateDocument accepts content, classification, documentType Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package createdraft
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.probo.inc/probo/pkg/cli/api"
|
||||
"go.probo.inc/probo/pkg/cmd/cmdutil"
|
||||
)
|
||||
|
||||
const createDraftMutation = `
|
||||
mutation($input: CreateDraftDocumentVersionInput!) {
|
||||
createDraftDocumentVersion(input: $input) {
|
||||
documentVersionEdge {
|
||||
node {
|
||||
id
|
||||
title
|
||||
major
|
||||
minor
|
||||
status
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
type createDraftResponse struct {
|
||||
CreateDraftDocumentVersion struct {
|
||||
DocumentVersionEdge struct {
|
||||
Node struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Major int `json:"major"`
|
||||
Minor int `json:"minor"`
|
||||
Status string `json:"status"`
|
||||
} `json:"node"`
|
||||
} `json:"documentVersionEdge"`
|
||||
} `json:"createDraftDocumentVersion"`
|
||||
}
|
||||
|
||||
func NewCmdCreateDraft(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-draft <document-id>",
|
||||
Short: "Create a new draft version of a document",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := f.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host, hc, err := cfg.DefaultHost()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := api.NewClient(
|
||||
host,
|
||||
hc.Token,
|
||||
"/api/console/v1/graphql",
|
||||
cfg.HTTPTimeoutDuration(),
|
||||
)
|
||||
|
||||
data, err := client.Do(
|
||||
createDraftMutation,
|
||||
map[string]any{
|
||||
"input": map[string]any{
|
||||
"documentID": args[0],
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp createDraftResponse
|
||||
if err := json.Unmarshal(data, &resp); err != nil {
|
||||
return fmt.Errorf("cannot parse response: %w", err)
|
||||
}
|
||||
|
||||
v := resp.CreateDraftDocumentVersion.DocumentVersionEdge.Node
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Created draft version %s (%s v%d.%d)\n",
|
||||
v.ID,
|
||||
v.Title,
|
||||
v.Major,
|
||||
v.Minor,
|
||||
)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -24,9 +24,11 @@ import (
|
||||
)
|
||||
|
||||
const deleteDraftMutation = `
|
||||
mutation($input: DeleteDraftDocumentVersionInput!) {
|
||||
deleteDraftDocumentVersion(input: $input) {
|
||||
deletedDocumentVersionId
|
||||
mutation($input: DeleteDocumentDraftInput!) {
|
||||
deleteDocumentDraft(input: $input) {
|
||||
document {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -35,8 +37,8 @@ func NewCmdDeleteDraft(f *cmdutil.Factory) *cobra.Command {
|
||||
var flagYes bool
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "delete-draft <document-version-id>",
|
||||
Short: "Delete a draft document version",
|
||||
Use: "delete-draft <document-id>",
|
||||
Short: "Delete the draft version of a document",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !flagYes {
|
||||
@@ -46,7 +48,7 @@ func NewCmdDeleteDraft(f *cmdutil.Factory) *cobra.Command {
|
||||
|
||||
var confirmed bool
|
||||
err := huh.NewConfirm().
|
||||
Title(fmt.Sprintf("Delete draft version %s?", args[0])).
|
||||
Title(fmt.Sprintf("Delete draft for document %s?", args[0])).
|
||||
Value(&confirmed).
|
||||
Run()
|
||||
if err != nil {
|
||||
@@ -78,7 +80,7 @@ func NewCmdDeleteDraft(f *cmdutil.Factory) *cobra.Command {
|
||||
deleteDraftMutation,
|
||||
map[string]any{
|
||||
"input": map[string]any{
|
||||
"documentVersionId": args[0],
|
||||
"documentId": args[0],
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -88,7 +90,7 @@ func NewCmdDeleteDraft(f *cmdutil.Factory) *cobra.Command {
|
||||
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Deleted draft version %s\n",
|
||||
"Deleted draft for document %s\n",
|
||||
args[0],
|
||||
)
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"go.probo.inc/probo/pkg/cmd/cmdutil"
|
||||
"go.probo.inc/probo/pkg/cmd/document/archive"
|
||||
"go.probo.inc/probo/pkg/cmd/document/create"
|
||||
createdraft "go.probo.inc/probo/pkg/cmd/document/create-draft"
|
||||
"go.probo.inc/probo/pkg/cmd/document/delete"
|
||||
deletedraft "go.probo.inc/probo/pkg/cmd/document/delete-draft"
|
||||
"go.probo.inc/probo/pkg/cmd/document/list"
|
||||
@@ -28,7 +27,6 @@ import (
|
||||
publishminor "go.probo.inc/probo/pkg/cmd/document/publish-minor"
|
||||
"go.probo.inc/probo/pkg/cmd/document/unarchive"
|
||||
"go.probo.inc/probo/pkg/cmd/document/update"
|
||||
updateversion "go.probo.inc/probo/pkg/cmd/document/update-version"
|
||||
"go.probo.inc/probo/pkg/cmd/document/view"
|
||||
viewversion "go.probo.inc/probo/pkg/cmd/document/view-version"
|
||||
)
|
||||
@@ -48,9 +46,7 @@ func NewCmdDocument(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd.AddCommand(unarchive.NewCmdUnarchive(f))
|
||||
cmd.AddCommand(listversions.NewCmdListVersions(f))
|
||||
cmd.AddCommand(viewversion.NewCmdViewVersion(f))
|
||||
cmd.AddCommand(createdraft.NewCmdCreateDraft(f))
|
||||
cmd.AddCommand(deletedraft.NewCmdDeleteDraft(f))
|
||||
cmd.AddCommand(updateversion.NewCmdUpdateVersion(f))
|
||||
cmd.AddCommand(publishmajor.NewCmdPublishMajor(f))
|
||||
cmd.AddCommand(publishminor.NewCmdPublishMinor(f))
|
||||
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package updateversion
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.probo.inc/probo/pkg/cli/api"
|
||||
"go.probo.inc/probo/pkg/cmd/cmdutil"
|
||||
)
|
||||
|
||||
const updateMutation = `
|
||||
mutation($input: UpdateDocumentVersionInput!) {
|
||||
updateDocumentVersion(input: $input) {
|
||||
documentVersion {
|
||||
id
|
||||
title
|
||||
major
|
||||
minor
|
||||
status
|
||||
documentType
|
||||
classification
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
type updateResponse struct {
|
||||
UpdateDocumentVersion struct {
|
||||
DocumentVersion struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Major int `json:"major"`
|
||||
Minor int `json:"minor"`
|
||||
Status string `json:"status"`
|
||||
DocumentType string `json:"documentType"`
|
||||
Classification string `json:"classification"`
|
||||
} `json:"documentVersion"`
|
||||
} `json:"updateDocumentVersion"`
|
||||
}
|
||||
|
||||
func NewCmdUpdateVersion(f *cmdutil.Factory) *cobra.Command {
|
||||
var (
|
||||
flagTitle string
|
||||
flagContent string
|
||||
flagDocumentType string
|
||||
flagClassification string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "update-version <document-version-id>",
|
||||
Short: "Update a document version",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := f.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
host, hc, err := cfg.DefaultHost()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := api.NewClient(
|
||||
host,
|
||||
hc.Token,
|
||||
"/api/console/v1/graphql",
|
||||
cfg.HTTPTimeoutDuration(),
|
||||
)
|
||||
|
||||
input := map[string]any{
|
||||
"documentVersionId": args[0],
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("title") {
|
||||
input["title"] = flagTitle
|
||||
}
|
||||
if cmd.Flags().Changed("content") {
|
||||
input["content"] = flagContent
|
||||
}
|
||||
if cmd.Flags().Changed("document-type") {
|
||||
if err := cmdutil.ValidateEnum(
|
||||
"document-type",
|
||||
flagDocumentType,
|
||||
[]string{"OTHER", "GOVERNANCE", "POLICY", "PROCEDURE", "PLAN", "REGISTER", "RECORD", "REPORT", "TEMPLATE"},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
input["documentType"] = flagDocumentType
|
||||
}
|
||||
if cmd.Flags().Changed("classification") {
|
||||
if err := cmdutil.ValidateEnum(
|
||||
"classification",
|
||||
flagClassification,
|
||||
[]string{"PUBLIC", "INTERNAL", "CONFIDENTIAL", "SECRET"},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
input["classification"] = flagClassification
|
||||
}
|
||||
|
||||
if len(input) == 1 {
|
||||
return fmt.Errorf("at least one field must be specified for update")
|
||||
}
|
||||
|
||||
data, err := client.Do(
|
||||
updateMutation,
|
||||
map[string]any{"input": input},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var resp updateResponse
|
||||
if err := json.Unmarshal(data, &resp); err != nil {
|
||||
return fmt.Errorf("cannot parse response: %w", err)
|
||||
}
|
||||
|
||||
v := resp.UpdateDocumentVersion.DocumentVersion
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Updated version %s (%s v%d.%d)\n",
|
||||
v.ID,
|
||||
v.Title,
|
||||
v.Major,
|
||||
v.Minor,
|
||||
)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&flagTitle, "title", "", "Version title")
|
||||
cmd.Flags().StringVar(&flagContent, "content", "", "Version content")
|
||||
cmd.Flags().StringVar(&flagDocumentType, "document-type", "", "Document type: OTHER, GOVERNANCE, POLICY, PROCEDURE, PLAN, REGISTER, RECORD, REPORT, TEMPLATE")
|
||||
cmd.Flags().StringVar(&flagClassification, "classification", "", "Classification: PUBLIC, INTERNAL, CONFIDENTIAL, SECRET")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -29,13 +29,15 @@ mutation($input: UpdateDocumentInput!) {
|
||||
document {
|
||||
id
|
||||
trustCenterVisibility
|
||||
versions(first: 1) {
|
||||
edges {
|
||||
node {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
documentVersion {
|
||||
id
|
||||
title
|
||||
major
|
||||
minor
|
||||
status
|
||||
documentType
|
||||
classification
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,19 +48,27 @@ type updateResponse struct {
|
||||
Document struct {
|
||||
ID string `json:"id"`
|
||||
TrustCenterVisibility string `json:"trustCenterVisibility"`
|
||||
Versions struct {
|
||||
Edges []struct {
|
||||
Node struct {
|
||||
Title string `json:"title"`
|
||||
} `json:"node"`
|
||||
} `json:"edges"`
|
||||
} `json:"versions"`
|
||||
} `json:"document"`
|
||||
DocumentVersion *struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Major int `json:"major"`
|
||||
Minor int `json:"minor"`
|
||||
Status string `json:"status"`
|
||||
DocumentType string `json:"documentType"`
|
||||
Classification string `json:"classification"`
|
||||
} `json:"documentVersion"`
|
||||
} `json:"updateDocument"`
|
||||
}
|
||||
|
||||
func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
var flagTrustCenterVisibility string
|
||||
var (
|
||||
flagTitle string
|
||||
flagContent string
|
||||
flagDocumentType string
|
||||
flagClassification string
|
||||
flagTrustCenterVisibility string
|
||||
)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "update <id>",
|
||||
@@ -86,6 +96,32 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
"id": args[0],
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("title") {
|
||||
input["title"] = flagTitle
|
||||
}
|
||||
if cmd.Flags().Changed("content") {
|
||||
input["content"] = flagContent
|
||||
}
|
||||
if cmd.Flags().Changed("document-type") {
|
||||
if err := cmdutil.ValidateEnum(
|
||||
"document-type",
|
||||
flagDocumentType,
|
||||
[]string{"OTHER", "GOVERNANCE", "POLICY", "PROCEDURE", "PLAN", "REGISTER", "RECORD", "REPORT", "TEMPLATE"},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
input["documentType"] = flagDocumentType
|
||||
}
|
||||
if cmd.Flags().Changed("classification") {
|
||||
if err := cmdutil.ValidateEnum(
|
||||
"classification",
|
||||
flagClassification,
|
||||
[]string{"PUBLIC", "INTERNAL", "CONFIDENTIAL", "SECRET"},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
input["classification"] = flagClassification
|
||||
}
|
||||
if cmd.Flags().Changed("trust-center-visibility") {
|
||||
if err := cmdutil.ValidateEnum(
|
||||
"trust-center-visibility",
|
||||
@@ -115,21 +151,31 @@ func NewCmdUpdate(f *cmdutil.Factory) *cobra.Command {
|
||||
}
|
||||
|
||||
doc := resp.UpdateDocument.Document
|
||||
title := doc.ID
|
||||
if len(doc.Versions.Edges) > 0 {
|
||||
title = doc.Versions.Edges[0].Node.Title
|
||||
if v := resp.UpdateDocument.DocumentVersion; v != nil {
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Updated document %s (%s v%d.%d)\n",
|
||||
doc.ID,
|
||||
v.Title,
|
||||
v.Major,
|
||||
v.Minor,
|
||||
)
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Updated document %s\n",
|
||||
doc.ID,
|
||||
)
|
||||
}
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Updated document %s (%s)\n",
|
||||
doc.ID,
|
||||
title,
|
||||
)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&flagTitle, "title", "", "Document title")
|
||||
cmd.Flags().StringVar(&flagContent, "content", "", "Document content")
|
||||
cmd.Flags().StringVar(&flagDocumentType, "document-type", "", "Document type: OTHER, GOVERNANCE, POLICY, PROCEDURE, PLAN, REGISTER, RECORD, REPORT, TEMPLATE")
|
||||
cmd.Flags().StringVar(&flagClassification, "classification", "", "Classification: PUBLIC, INTERNAL, CONFIDENTIAL, SECRET")
|
||||
cmd.Flags().StringVar(&flagTrustCenterVisibility, "trust-center-visibility", "", "Trust center visibility: NONE, PRIVATE, PUBLIC")
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -186,7 +186,7 @@ const (
|
||||
ActionDocumentChangelogGenerate = "core:document:generate-changelog"
|
||||
ActionDocumentArchive = "core:document:archive"
|
||||
ActionDocumentUnarchive = "core:document:unarchive"
|
||||
ActionDocumentDraftVersionCreate = "core:document:create-draft-version"
|
||||
ActionDocumentDeleteDraft = "core:document:delete-draft"
|
||||
ActionDocumentSendSigningNotifications = "core:document:send-signing-notifications"
|
||||
|
||||
// DocumentVersion actions
|
||||
@@ -194,8 +194,6 @@ const (
|
||||
ActionDocumentVersionList = "core:document-version:list"
|
||||
ActionDocumentVersionExportPDF = "core:document-version:export-pdf"
|
||||
ActionDocumentVersionSign = "core:document-version:sign"
|
||||
ActionDocumentVersionUpdate = "core:document-version:update"
|
||||
ActionDocumentVersionDeleteDraft = "core:document-version:delete-draft"
|
||||
ActionDocumentVersionRequestApproval = "core:document-version:request-approval"
|
||||
ActionDocumentVersionVoidApproval = "core:document-version:void-approval"
|
||||
ActionDocumentVersionApprove = "core:document-version:approve"
|
||||
|
||||
@@ -71,6 +71,9 @@ type (
|
||||
ErrDocumentArchived struct {
|
||||
}
|
||||
|
||||
ErrDocumentDraftNotDeletable struct {
|
||||
}
|
||||
|
||||
ErrDocumentNotArchived struct {
|
||||
}
|
||||
|
||||
@@ -89,18 +92,14 @@ type (
|
||||
|
||||
UpdateDocumentRequest struct {
|
||||
DocumentID gid.GID
|
||||
Title *string
|
||||
Content *string
|
||||
Classification *coredata.DocumentClassification
|
||||
DocumentType *coredata.DocumentType
|
||||
TrustCenterVisibility *coredata.TrustCenterVisibility
|
||||
DefaultApproverIDs *[]gid.GID
|
||||
}
|
||||
|
||||
UpdateDocumentVersionRequest struct {
|
||||
ID gid.GID
|
||||
Title *string
|
||||
Content *string
|
||||
Classification *coredata.DocumentClassification
|
||||
DocumentType *coredata.DocumentType
|
||||
}
|
||||
|
||||
RequestSignatureRequest struct {
|
||||
DocumentVersionID gid.GID
|
||||
Signatory gid.GID
|
||||
@@ -158,24 +157,16 @@ func (udr *UpdateDocumentRequest) Validate() error {
|
||||
v.Check(item, "default_approver_ids", validator.GID(coredata.MembershipProfileEntityType))
|
||||
})
|
||||
}
|
||||
|
||||
return v.Error()
|
||||
}
|
||||
|
||||
func (udvr *UpdateDocumentVersionRequest) Validate() error {
|
||||
v := validator.New()
|
||||
|
||||
v.Check(udvr.ID, "id", validator.Required(), validator.GID(coredata.DocumentVersionEntityType))
|
||||
v.Check(udvr.Title, "title", validator.SafeTextNoNewLine(TitleMaxLength))
|
||||
v.Check(udvr.Classification, "classification", validator.OneOfSlice(coredata.DocumentClassifications()))
|
||||
v.Check(udr.Title, "title", validator.SafeTextNoNewLine(TitleMaxLength))
|
||||
v.Check(udr.Classification, "classification", validator.OneOfSlice(coredata.DocumentClassifications()))
|
||||
v.Check(
|
||||
udvr.Content,
|
||||
udr.Content,
|
||||
"content",
|
||||
validator.MaxLen(documentContentMaxJSONBytes),
|
||||
validator.ProseMirrorDocumentContent(),
|
||||
validator.ProseMirrorDocumentMaxTextLength(documentContentMaxTextLength),
|
||||
)
|
||||
v.Check(udvr.DocumentType, "document_type", validator.OneOfSlice(coredata.DocumentTypes()))
|
||||
v.Check(udr.DocumentType, "document_type", validator.OneOfSlice(coredata.DocumentTypes()))
|
||||
|
||||
return v.Error()
|
||||
}
|
||||
@@ -214,6 +205,10 @@ func (e ErrDocumentArchived) Error() string {
|
||||
return "cannot modify an archived document"
|
||||
}
|
||||
|
||||
func (e ErrDocumentDraftNotDeletable) Error() string {
|
||||
return "latest version is not a deletable draft"
|
||||
}
|
||||
|
||||
func (e ErrDocumentNotArchived) Error() string {
|
||||
return "cannot unarchive a document that is not archived"
|
||||
}
|
||||
@@ -824,68 +819,39 @@ func (s *DocumentService) signDocumentVersionInTx(
|
||||
return documentVersionSignature, nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) UpdateVersion(
|
||||
func (s *DocumentService) updateVersionInTx(
|
||||
ctx context.Context,
|
||||
req UpdateDocumentVersionRequest,
|
||||
) (*coredata.DocumentVersion, error) {
|
||||
documentVersion := &coredata.DocumentVersion{}
|
||||
document := &coredata.Document{}
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
tx pg.Tx,
|
||||
draftVersion *coredata.DocumentVersion,
|
||||
content *string,
|
||||
classification *coredata.DocumentClassification,
|
||||
documentType *coredata.DocumentType,
|
||||
title *string,
|
||||
) error {
|
||||
if content != nil {
|
||||
sanitized, err := prosemirror.SanitizeDocumentJSON(*content)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot sanitize document content: %w", err)
|
||||
}
|
||||
draftVersion.Content = sanitized
|
||||
}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Tx) error {
|
||||
if err := documentVersion.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
||||
return fmt.Errorf("cannot load document version %q: %w", req.ID, err)
|
||||
}
|
||||
if title != nil {
|
||||
draftVersion.Title = *title
|
||||
}
|
||||
if classification != nil {
|
||||
draftVersion.Classification = *classification
|
||||
}
|
||||
if documentType != nil {
|
||||
draftVersion.DocumentType = *documentType
|
||||
}
|
||||
draftVersion.UpdatedAt = time.Now()
|
||||
|
||||
if err := document.LoadByID(ctx, conn, s.svc.scope, documentVersion.DocumentID); err != nil {
|
||||
return fmt.Errorf("cannot load document %q: %w", documentVersion.DocumentID, err)
|
||||
}
|
||||
|
||||
if document.ArchivedAt != nil {
|
||||
return &ErrDocumentArchived{}
|
||||
}
|
||||
|
||||
if documentVersion.Status != coredata.DocumentVersionStatusDraft {
|
||||
return &ErrDocumentVersionNotDraft{}
|
||||
}
|
||||
|
||||
if req.Content != nil {
|
||||
content, err := prosemirror.SanitizeDocumentJSON(*req.Content)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot sanitize document content: %w", err)
|
||||
}
|
||||
documentVersion.Content = content
|
||||
}
|
||||
|
||||
if req.Title != nil {
|
||||
documentVersion.Title = *req.Title
|
||||
}
|
||||
if req.Classification != nil {
|
||||
documentVersion.Classification = *req.Classification
|
||||
}
|
||||
if req.DocumentType != nil {
|
||||
documentVersion.DocumentType = *req.DocumentType
|
||||
}
|
||||
documentVersion.UpdatedAt = time.Now()
|
||||
|
||||
if err := documentVersion.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update document version: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err := draftVersion.Update(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot update document version: %w", err)
|
||||
}
|
||||
|
||||
return documentVersion, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) GetVersionSignature(
|
||||
@@ -1087,101 +1053,46 @@ func (s *DocumentService) IsVersionSignedByUserEmail(
|
||||
return signed, nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) CreateDraft(
|
||||
func (s *DocumentService) createDraftInTx(
|
||||
ctx context.Context,
|
||||
documentID gid.GID,
|
||||
tx pg.Tx,
|
||||
document *coredata.Document,
|
||||
latestVersion *coredata.DocumentVersion,
|
||||
) (*coredata.DocumentVersion, error) {
|
||||
draftVersionID := gid.New(s.svc.scope.GetTenantID(), coredata.DocumentVersionEntityType)
|
||||
|
||||
latestVersion := &coredata.DocumentVersion{}
|
||||
document := &coredata.Document{}
|
||||
draftVersion := &coredata.DocumentVersion{}
|
||||
now := time.Now()
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Tx) error {
|
||||
if err := document.LoadByID(ctx, conn, s.svc.scope, documentID); err != nil {
|
||||
return fmt.Errorf("cannot load document: %w", err)
|
||||
}
|
||||
draftVersion := &coredata.DocumentVersion{
|
||||
ID: gid.New(s.svc.scope.GetTenantID(), coredata.DocumentVersionEntityType),
|
||||
OrganizationID: document.OrganizationID,
|
||||
DocumentID: document.ID,
|
||||
Title: latestVersion.Title,
|
||||
Major: latestVersion.Major,
|
||||
Minor: latestVersion.Minor + 1,
|
||||
Classification: latestVersion.Classification,
|
||||
DocumentType: latestVersion.DocumentType,
|
||||
Content: latestVersion.Content,
|
||||
Status: coredata.DocumentVersionStatusDraft,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
|
||||
if document.ArchivedAt != nil {
|
||||
return &ErrDocumentArchived{}
|
||||
}
|
||||
|
||||
if err := latestVersion.LoadLatestVersion(ctx, conn, s.svc.scope, documentID); err != nil {
|
||||
return fmt.Errorf("cannot load latest version: %w", err)
|
||||
}
|
||||
|
||||
if latestVersion.Status != coredata.DocumentVersionStatusPublished {
|
||||
return &ErrDocumentVersionNotPublished{}
|
||||
}
|
||||
|
||||
draftVersion.ID = draftVersionID
|
||||
draftVersion.OrganizationID = document.OrganizationID
|
||||
draftVersion.DocumentID = documentID
|
||||
draftVersion.Title = latestVersion.Title
|
||||
draftVersion.Major = latestVersion.Major
|
||||
draftVersion.Minor = latestVersion.Minor + 1
|
||||
draftVersion.Classification = latestVersion.Classification
|
||||
draftVersion.DocumentType = latestVersion.DocumentType
|
||||
draftVersion.Content = latestVersion.Content
|
||||
draftVersion.Status = coredata.DocumentVersionStatusDraft
|
||||
draftVersion.CreatedAt = now
|
||||
draftVersion.UpdatedAt = now
|
||||
|
||||
if err := draftVersion.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot create draft: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err := draftVersion.Insert(ctx, tx, s.svc.scope); err != nil {
|
||||
return nil, fmt.Errorf("cannot create draft: %w", err)
|
||||
}
|
||||
|
||||
return draftVersion, nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) DeleteDraft(
|
||||
func (s *DocumentService) deleteDraftInTx(
|
||||
ctx context.Context,
|
||||
documentVersionID gid.GID,
|
||||
tx pg.Tx,
|
||||
draftVersion *coredata.DocumentVersion,
|
||||
) error {
|
||||
documentVersion := &coredata.DocumentVersion{}
|
||||
if err := draftVersion.Delete(ctx, tx, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete document version: %w", err)
|
||||
}
|
||||
|
||||
return s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(ctx context.Context, conn pg.Tx) error {
|
||||
if err := documentVersion.LoadByID(ctx, conn, s.svc.scope, documentVersionID); err != nil {
|
||||
return fmt.Errorf("cannot load document version: %w", err)
|
||||
}
|
||||
|
||||
document := &coredata.Document{}
|
||||
if err := document.LoadByID(ctx, conn, s.svc.scope, documentVersion.DocumentID); err != nil {
|
||||
return fmt.Errorf("cannot load document: %w", err)
|
||||
}
|
||||
|
||||
if document.ArchivedAt != nil {
|
||||
return &ErrDocumentArchived{}
|
||||
}
|
||||
|
||||
if documentVersion.Status != coredata.DocumentVersionStatusDraft {
|
||||
return fmt.Errorf("cannot delete published document version")
|
||||
}
|
||||
|
||||
if documentVersion.Major == 0 && documentVersion.Minor == 1 {
|
||||
return fmt.Errorf("cannot delete the first version of a document")
|
||||
}
|
||||
|
||||
if err := documentVersion.Delete(ctx, conn, s.svc.scope); err != nil {
|
||||
return fmt.Errorf("cannot delete document version: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) SoftDelete(
|
||||
@@ -1698,12 +1609,14 @@ func (s *DocumentService) ListForMeasureID(
|
||||
func (s *DocumentService) Update(
|
||||
ctx context.Context,
|
||||
req UpdateDocumentRequest,
|
||||
) (*coredata.Document, error) {
|
||||
) (*coredata.Document, *coredata.DocumentVersion, bool, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, false, err
|
||||
}
|
||||
|
||||
document := &coredata.Document{}
|
||||
var resultVersion *coredata.DocumentVersion
|
||||
var draftCreated bool
|
||||
now := time.Now()
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
@@ -1727,6 +1640,73 @@ func (s *DocumentService) Update(
|
||||
return fmt.Errorf("cannot update document: %w", err)
|
||||
}
|
||||
|
||||
// Handle draft version logic for title/content/classification/type changes.
|
||||
latestVersion := &coredata.DocumentVersion{}
|
||||
if err := latestVersion.LoadLatestVersion(ctx, tx, s.svc.scope, req.DocumentID); err != nil {
|
||||
return fmt.Errorf("cannot load latest version: %w", err)
|
||||
}
|
||||
|
||||
hasVersionChanges := req.Title != nil || req.Content != nil || req.Classification != nil || req.DocumentType != nil
|
||||
|
||||
if !hasVersionChanges {
|
||||
if req.DefaultApproverIDs != nil {
|
||||
defaultApprovers := &coredata.DocumentDefaultApprovers{}
|
||||
if err := defaultApprovers.MergeByDocumentID(ctx, tx, s.svc.scope, req.DocumentID, document.OrganizationID, *req.DefaultApproverIDs); err != nil {
|
||||
return fmt.Errorf("cannot update default approvers: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if latestVersion.Status == coredata.DocumentVersionStatusDraft {
|
||||
// Draft exists: update it with any new values.
|
||||
if err := s.updateVersionInTx(ctx, tx, latestVersion, req.Content, req.Classification, req.DocumentType, req.Title); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If there is a published version and the draft matches it, delete the draft.
|
||||
// Never delete the initial draft (v0.1) since there's nothing to fall back to.
|
||||
if document.CurrentPublishedMajor != nil && (latestVersion.Major != 0 || latestVersion.Minor != 1) {
|
||||
publishedVersion := &coredata.DocumentVersion{}
|
||||
if err := publishedVersion.LoadByDocumentIDAndVersion(
|
||||
ctx,
|
||||
tx,
|
||||
s.svc.scope,
|
||||
req.DocumentID,
|
||||
*document.CurrentPublishedMajor,
|
||||
*document.CurrentPublishedMinor,
|
||||
); err != nil {
|
||||
return fmt.Errorf("cannot load published version: %w", err)
|
||||
}
|
||||
|
||||
if latestVersion.Title == publishedVersion.Title &&
|
||||
latestVersion.Content == publishedVersion.Content &&
|
||||
latestVersion.Classification == publishedVersion.Classification &&
|
||||
latestVersion.DocumentType == publishedVersion.DocumentType {
|
||||
if err := s.deleteDraftInTx(ctx, tx, latestVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
resultVersion = nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
resultVersion = latestVersion
|
||||
} else {
|
||||
// No draft exists: create one.
|
||||
draftVersion, err := s.createDraftInTx(ctx, tx, document, latestVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.updateVersionInTx(ctx, tx, draftVersion, req.Content, req.Classification, req.DocumentType, req.Title); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resultVersion = draftVersion
|
||||
draftCreated = true
|
||||
}
|
||||
|
||||
if req.DefaultApproverIDs != nil {
|
||||
defaultApprovers := &coredata.DocumentDefaultApprovers{}
|
||||
if err := defaultApprovers.MergeByDocumentID(ctx, tx, s.svc.scope, req.DocumentID, document.OrganizationID, *req.DefaultApproverIDs); err != nil {
|
||||
@@ -1738,6 +1718,47 @@ func (s *DocumentService) Update(
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, false, err
|
||||
}
|
||||
|
||||
return document, resultVersion, draftCreated, nil
|
||||
}
|
||||
|
||||
func (s *DocumentService) DeleteDraft(
|
||||
ctx context.Context,
|
||||
documentID gid.GID,
|
||||
) (*coredata.Document, error) {
|
||||
document := &coredata.Document{}
|
||||
|
||||
err := s.svc.pg.WithTx(
|
||||
ctx,
|
||||
func(ctx context.Context, tx pg.Tx) error {
|
||||
if err := document.LoadByID(ctx, tx, s.svc.scope, documentID); err != nil {
|
||||
return fmt.Errorf("cannot load document %q: %w", documentID, err)
|
||||
}
|
||||
|
||||
if document.ArchivedAt != nil {
|
||||
return &ErrDocumentArchived{}
|
||||
}
|
||||
|
||||
latestVersion := &coredata.DocumentVersion{}
|
||||
if err := latestVersion.LoadLatestVersion(ctx, tx, s.svc.scope, documentID); err != nil {
|
||||
return fmt.Errorf("cannot load latest version: %w", err)
|
||||
}
|
||||
|
||||
if latestVersion.Status != coredata.DocumentVersionStatusDraft {
|
||||
return &ErrDocumentDraftNotDeletable{}
|
||||
}
|
||||
|
||||
if latestVersion.Major == 0 && latestVersion.Minor == 1 {
|
||||
return &ErrDocumentDraftNotDeletable{}
|
||||
}
|
||||
|
||||
return s.deleteDraftInTx(ctx, tx, latestVersion)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3892,6 +3892,7 @@ type Mutation {
|
||||
# Document mutations
|
||||
createDocument(input: CreateDocumentInput!): CreateDocumentPayload!
|
||||
updateDocument(input: UpdateDocumentInput!): UpdateDocumentPayload!
|
||||
deleteDocumentDraft(input: DeleteDocumentDraftInput!): DeleteDocumentDraftPayload!
|
||||
archiveDocument(input: ArchiveDocumentInput!): ArchiveDocumentPayload!
|
||||
unarchiveDocument(input: UnarchiveDocumentInput!): UnarchiveDocumentPayload!
|
||||
deleteDocument(input: DeleteDocumentInput!): DeleteDocumentPayload!
|
||||
@@ -3955,15 +3956,6 @@ type Mutation {
|
||||
generateDocumentChangelog(
|
||||
input: GenerateDocumentChangelogInput!
|
||||
): GenerateDocumentChangelogPayload!
|
||||
createDraftDocumentVersion(
|
||||
input: CreateDraftDocumentVersionInput!
|
||||
): CreateDraftDocumentVersionPayload!
|
||||
deleteDraftDocumentVersion(
|
||||
input: DeleteDraftDocumentVersionInput!
|
||||
): DeleteDraftDocumentVersionPayload!
|
||||
updateDocumentVersion(
|
||||
input: UpdateDocumentVersionInput!
|
||||
): UpdateDocumentVersionPayload!
|
||||
requestSignature(input: RequestSignatureInput!): RequestSignaturePayload!
|
||||
bulkRequestSignatures(
|
||||
input: BulkRequestSignaturesInput!
|
||||
@@ -4673,6 +4665,10 @@ input CreateDocumentInput {
|
||||
|
||||
input UpdateDocumentInput {
|
||||
id: ID!
|
||||
title: String
|
||||
content: String
|
||||
classification: DocumentClassification
|
||||
documentType: DocumentType
|
||||
trustCenterVisibility: TrustCenterVisibility
|
||||
defaultApproverIds: [ID!]
|
||||
}
|
||||
@@ -4703,6 +4699,10 @@ input ExportTransferImpactAssessmentsPDFInput {
|
||||
filter: TransferImpactAssessmentFilter
|
||||
}
|
||||
|
||||
input DeleteDocumentDraftInput {
|
||||
documentId: ID!
|
||||
}
|
||||
|
||||
input ArchiveDocumentInput {
|
||||
documentId: ID!
|
||||
}
|
||||
@@ -5442,6 +5442,12 @@ type ExportTransferImpactAssessmentsPDFPayload {
|
||||
|
||||
type UpdateDocumentPayload {
|
||||
document: Document!
|
||||
documentVersion: DocumentVersion
|
||||
documentVersionEdge: DocumentVersionEdge
|
||||
}
|
||||
|
||||
type DeleteDocumentDraftPayload {
|
||||
document: Document!
|
||||
}
|
||||
|
||||
type ArchiveDocumentPayload {
|
||||
@@ -5922,38 +5928,10 @@ type BulkPublishDocumentVersionsPayload {
|
||||
documents: [Document!]!
|
||||
}
|
||||
|
||||
type CreateDraftDocumentVersionPayload {
|
||||
documentVersionEdge: DocumentVersionEdge!
|
||||
}
|
||||
|
||||
type DeleteDraftDocumentVersionPayload {
|
||||
deletedDocumentVersionId: ID!
|
||||
}
|
||||
|
||||
input CreateDraftDocumentVersionInput {
|
||||
documentID: ID!
|
||||
}
|
||||
|
||||
input DeleteDraftDocumentVersionInput {
|
||||
documentVersionId: ID!
|
||||
}
|
||||
|
||||
input UpdateDocumentVersionInput {
|
||||
documentVersionId: ID!
|
||||
title: String
|
||||
content: String
|
||||
classification: DocumentClassification
|
||||
documentType: DocumentType
|
||||
}
|
||||
|
||||
input CancelSignatureRequestInput {
|
||||
documentVersionSignatureId: ID!
|
||||
}
|
||||
|
||||
type UpdateDocumentVersionPayload {
|
||||
documentVersion: DocumentVersion!
|
||||
}
|
||||
|
||||
input SendSigningNotificationsInput {
|
||||
organizationId: ID!
|
||||
}
|
||||
|
||||
@@ -5303,16 +5303,23 @@ func (r *mutationResolver) UpdateDocument(ctx context.Context, input types.Updat
|
||||
defaultApproverIDs = &input.DefaultApproverIds
|
||||
}
|
||||
|
||||
document, err := prb.Documents.Update(
|
||||
document, documentVersion, draftCreated, err := prb.Documents.Update(
|
||||
ctx,
|
||||
probo.UpdateDocumentRequest{
|
||||
DocumentID: input.ID,
|
||||
Title: input.Title,
|
||||
Content: input.Content,
|
||||
Classification: input.Classification,
|
||||
DocumentType: input.DocumentType,
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
DefaultApproverIDs: defaultApproverIDs,
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
}
|
||||
if errArchived, ok := errors.AsType[*probo.ErrDocumentArchived](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errArchived)
|
||||
}
|
||||
@@ -5323,7 +5330,48 @@ func (r *mutationResolver) UpdateDocument(ctx context.Context, input types.Updat
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.UpdateDocumentPayload{
|
||||
payload := &types.UpdateDocumentPayload{
|
||||
Document: types.NewDocument(document),
|
||||
}
|
||||
|
||||
if documentVersion != nil {
|
||||
payload.DocumentVersion = types.NewDocumentVersion(documentVersion)
|
||||
}
|
||||
|
||||
if draftCreated {
|
||||
payload.DocumentVersionEdge = types.NewDocumentVersionEdge(
|
||||
documentVersion,
|
||||
coredata.DocumentVersionOrderFieldCreatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
// DeleteDocumentDraft is the resolver for the deleteDocumentDraft field.
|
||||
func (r *mutationResolver) DeleteDocumentDraft(ctx context.Context, input types.DeleteDocumentDraftInput) (*types.DeleteDocumentDraftPayload, error) {
|
||||
if err := r.authorize(ctx, input.DocumentID, probo.ActionDocumentDeleteDraft); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.DocumentID.TenantID())
|
||||
|
||||
document, err := prb.Documents.DeleteDraft(ctx, input.DocumentID)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
}
|
||||
if errNotDeletable, ok := errors.AsType[*probo.ErrDocumentDraftNotDeletable](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errNotDeletable)
|
||||
}
|
||||
if errArchived, ok := errors.AsType[*probo.ErrDocumentArchived](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errArchived)
|
||||
}
|
||||
r.logger.ErrorCtx(ctx, "cannot delete document draft", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.DeleteDocumentDraftPayload{
|
||||
Document: types.NewDocument(document),
|
||||
}, nil
|
||||
}
|
||||
@@ -6038,98 +6086,6 @@ func (r *mutationResolver) GenerateDocumentChangelog(ctx context.Context, input
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CreateDraftDocumentVersion is the resolver for the createDraftDocumentVersion field.
|
||||
func (r *mutationResolver) CreateDraftDocumentVersion(ctx context.Context, input types.CreateDraftDocumentVersionInput) (*types.CreateDraftDocumentVersionPayload, error) {
|
||||
if err := r.authorize(ctx, input.DocumentID, probo.ActionDocumentDraftVersionCreate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.DocumentID.TenantID())
|
||||
|
||||
documentVersion, err := prb.Documents.CreateDraft(ctx, input.DocumentID)
|
||||
if err != nil {
|
||||
if errArchived, ok := errors.AsType[*probo.ErrDocumentArchived](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errArchived)
|
||||
}
|
||||
|
||||
if errNotPublished, ok := errors.AsType[*probo.ErrDocumentVersionNotPublished](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errNotPublished)
|
||||
}
|
||||
|
||||
r.logger.ErrorCtx(ctx, "cannot create draft document version", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.CreateDraftDocumentVersionPayload{
|
||||
DocumentVersionEdge: types.NewDocumentVersionEdge(documentVersion, coredata.DocumentVersionOrderFieldCreatedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DeleteDraftDocumentVersion is the resolver for the deleteDraftDocumentVersion field.
|
||||
func (r *mutationResolver) DeleteDraftDocumentVersion(ctx context.Context, input types.DeleteDraftDocumentVersionInput) (*types.DeleteDraftDocumentVersionPayload, error) {
|
||||
if err := r.authorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionDeleteDraft); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.DocumentVersionID.TenantID())
|
||||
|
||||
err := prb.Documents.DeleteDraft(ctx, input.DocumentVersionID)
|
||||
if err != nil {
|
||||
if errArchived, ok := errors.AsType[*probo.ErrDocumentArchived](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errArchived)
|
||||
}
|
||||
|
||||
r.logger.ErrorCtx(ctx, "cannot delete draft document version", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.DeleteDraftDocumentVersionPayload{
|
||||
DeletedDocumentVersionID: input.DocumentVersionID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateDocumentVersion is the resolver for the updateDocumentVersion field.
|
||||
func (r *mutationResolver) UpdateDocumentVersion(ctx context.Context, input types.UpdateDocumentVersionInput) (*types.UpdateDocumentVersionPayload, error) {
|
||||
if err := r.authorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionUpdate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prb := r.ProboService(ctx, input.DocumentVersionID.TenantID())
|
||||
|
||||
documentVersion, err := prb.Documents.UpdateVersion(
|
||||
ctx,
|
||||
probo.UpdateDocumentVersionRequest{
|
||||
ID: input.DocumentVersionID,
|
||||
Title: input.Title,
|
||||
Content: input.Content,
|
||||
Classification: input.Classification,
|
||||
DocumentType: input.DocumentType,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
}
|
||||
|
||||
if errNotDraft, ok := errors.AsType[*probo.ErrDocumentVersionNotDraft](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errNotDraft)
|
||||
}
|
||||
|
||||
if errArchived, ok := errors.AsType[*probo.ErrDocumentArchived](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errArchived)
|
||||
}
|
||||
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
||||
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
||||
}
|
||||
r.logger.ErrorCtx(ctx, "cannot update document version", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.UpdateDocumentVersionPayload{
|
||||
DocumentVersion: types.NewDocumentVersion(documentVersion),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RequestSignature is the resolver for the requestSignature field.
|
||||
func (r *mutationResolver) RequestSignature(ctx context.Context, input types.RequestSignatureInput) (*types.RequestSignaturePayload, error) {
|
||||
if err := r.authorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionSignatureRequest); err != nil {
|
||||
|
||||
@@ -2115,10 +2115,23 @@ func (r *Resolver) UpdateDocumentTool(ctx context.Context, req *mcp.CallToolRequ
|
||||
defaultApproverIDs = &input.DefaultApproverIds
|
||||
}
|
||||
|
||||
document, err := svc.Documents.Update(
|
||||
var content *string
|
||||
if input.Content != nil {
|
||||
c, err := markdownToProseMirrorJSON(*input.Content)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||
}
|
||||
content = &c
|
||||
}
|
||||
|
||||
document, documentVersion, _, err := svc.Documents.Update(
|
||||
ctx,
|
||||
probo.UpdateDocumentRequest{
|
||||
DocumentID: input.ID,
|
||||
Title: input.Title,
|
||||
Content: content,
|
||||
Classification: input.Classification,
|
||||
DocumentType: input.DocumentType,
|
||||
TrustCenterVisibility: input.TrustCenterVisibility,
|
||||
DefaultApproverIDs: defaultApproverIDs,
|
||||
},
|
||||
@@ -2127,9 +2140,15 @@ func (r *Resolver) UpdateDocumentTool(ctx context.Context, req *mcp.CallToolRequ
|
||||
panic(fmt.Errorf("cannot update document: %w", err))
|
||||
}
|
||||
|
||||
return nil, types.UpdateDocumentOutput{
|
||||
output := types.UpdateDocumentOutput{
|
||||
Document: types.NewDocument(document),
|
||||
}, nil
|
||||
}
|
||||
|
||||
if documentVersion != nil {
|
||||
output.DocumentVersion = types.NewDocumentVersion(documentVersion)
|
||||
}
|
||||
|
||||
return nil, output, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) ListDocumentVersionsTool(ctx context.Context, req *mcp.CallToolRequest, input *types.ListDocumentVersionsInput) (*mcp.CallToolResult, types.ListDocumentVersionsOutput, error) {
|
||||
@@ -2172,72 +2191,6 @@ func (r *Resolver) GetDocumentVersionTool(ctx context.Context, req *mcp.CallTool
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) CreateDraftDocumentVersionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.CreateDraftDocumentVersionInput) (*mcp.CallToolResult, types.CreateDraftDocumentVersionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.DocumentID, probo.ActionDocumentDraftVersionCreate)
|
||||
|
||||
svc := r.ProboService(ctx, input.DocumentID)
|
||||
|
||||
draftVersion, err := svc.Documents.CreateDraft(ctx, input.DocumentID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot create draft document version: %w", err))
|
||||
}
|
||||
|
||||
if input.Content != nil {
|
||||
content, err := markdownToProseMirrorJSON(*input.Content)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||
}
|
||||
|
||||
draftVersion, err = svc.Documents.UpdateVersion(
|
||||
ctx,
|
||||
probo.UpdateDocumentVersionRequest{
|
||||
ID: draftVersion.ID,
|
||||
Content: &content,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update draft document version content: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
return nil, types.CreateDraftDocumentVersionOutput{
|
||||
DocumentVersion: types.NewDocumentVersion(draftVersion),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) UpdateDocumentVersionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.UpdateDocumentVersionInput) (*mcp.CallToolResult, types.UpdateDocumentVersionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionUpdate)
|
||||
|
||||
svc := r.ProboService(ctx, input.DocumentVersionID)
|
||||
|
||||
var content *string
|
||||
if input.Content != nil {
|
||||
c, err := markdownToProseMirrorJSON(*input.Content)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot convert markdown to prosemirror: %w", err))
|
||||
}
|
||||
content = &c
|
||||
}
|
||||
|
||||
documentVersion, err := svc.Documents.UpdateVersion(
|
||||
ctx,
|
||||
probo.UpdateDocumentVersionRequest{
|
||||
ID: input.DocumentVersionID,
|
||||
Title: input.Title,
|
||||
Content: content,
|
||||
Classification: input.Classification,
|
||||
DocumentType: input.DocumentType,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot update document version: %w", err))
|
||||
}
|
||||
|
||||
return nil, types.UpdateDocumentVersionOutput{
|
||||
DocumentVersion: types.NewDocumentVersion(documentVersion),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) ListDocumentVersionSignaturesTool(ctx context.Context, req *mcp.CallToolRequest, input *types.ListDocumentVersionSignaturesInput) (*mcp.CallToolResult, types.ListDocumentVersionSignaturesOutput, error) {
|
||||
r.MustAuthorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionSignatureList)
|
||||
|
||||
@@ -2312,21 +2265,6 @@ func (r *Resolver) RequestDocumentVersionSignatureTool(ctx context.Context, req
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) DeleteDraftDocumentVersionTool(ctx context.Context, req *mcp.CallToolRequest, input *types.DeleteDraftDocumentVersionInput) (*mcp.CallToolResult, types.DeleteDraftDocumentVersionOutput, error) {
|
||||
r.MustAuthorize(ctx, input.DocumentVersionID, probo.ActionDocumentVersionDeleteDraft)
|
||||
|
||||
svc := r.ProboService(ctx, input.DocumentVersionID)
|
||||
|
||||
err := svc.Documents.DeleteDraft(ctx, input.DocumentVersionID)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot delete draft document version: %w", err))
|
||||
}
|
||||
|
||||
return nil, types.DeleteDraftDocumentVersionOutput{
|
||||
DeletedDocumentVersionID: input.DocumentVersionID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) DeleteDocumentTool(ctx context.Context, req *mcp.CallToolRequest, input *types.DeleteDocumentInput) (*mcp.CallToolResult, types.DeleteDocumentOutput, error) {
|
||||
r.MustAuthorize(ctx, input.DocumentID, probo.ActionDocumentDelete)
|
||||
|
||||
@@ -3971,3 +3909,18 @@ func (r *Resolver) SendSigningNotificationsTool(ctx context.Context, req *mcp.Ca
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Resolver) DeleteDocumentDraftTool(ctx context.Context, req *mcp.CallToolRequest, input *types.DeleteDocumentDraftInput) (*mcp.CallToolResult, types.DeleteDocumentDraftOutput, error) {
|
||||
r.MustAuthorize(ctx, input.ID, probo.ActionDocumentDeleteDraft)
|
||||
|
||||
svc := r.ProboService(ctx, input.ID)
|
||||
|
||||
document, err := svc.Documents.DeleteDraft(ctx, input.ID)
|
||||
if err != nil {
|
||||
return nil, types.DeleteDocumentDraftOutput{}, fmt.Errorf("cannot delete document draft: %w", err)
|
||||
}
|
||||
|
||||
return nil, types.DeleteDocumentDraftOutput{
|
||||
Document: types.NewDocument(document),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -5517,6 +5517,18 @@ components:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document ID
|
||||
title:
|
||||
type: string
|
||||
description: Document title
|
||||
content:
|
||||
type: string
|
||||
description: Document content in markdown format
|
||||
classification:
|
||||
$ref: "#/components/schemas/DocumentClassification"
|
||||
description: Document classification
|
||||
document_type:
|
||||
$ref: "#/components/schemas/DocumentType"
|
||||
description: Document type
|
||||
trust_center_visibility:
|
||||
$ref: "#/components/schemas/TrustCenterVisibility"
|
||||
description: Trust center visibility
|
||||
@@ -5527,6 +5539,25 @@ components:
|
||||
description: Default approver profile IDs
|
||||
|
||||
UpdateDocumentOutput:
|
||||
type: object
|
||||
required:
|
||||
- document
|
||||
properties:
|
||||
document:
|
||||
$ref: "#/components/schemas/Document"
|
||||
document_version:
|
||||
$ref: "#/components/schemas/DocumentVersion"
|
||||
|
||||
DeleteDocumentDraftInput:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document ID
|
||||
|
||||
DeleteDocumentDraftOutput:
|
||||
type: object
|
||||
required:
|
||||
- document
|
||||
@@ -5618,75 +5649,6 @@ components:
|
||||
document_version:
|
||||
$ref: "#/components/schemas/DocumentVersion"
|
||||
|
||||
CreateDraftDocumentVersionInput:
|
||||
type: object
|
||||
required:
|
||||
- document_id
|
||||
properties:
|
||||
document_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document ID
|
||||
content:
|
||||
type: string
|
||||
description: Document content in markdown format
|
||||
|
||||
CreateDraftDocumentVersionOutput:
|
||||
type: object
|
||||
description: Created draft; document_version.content is markdown
|
||||
required:
|
||||
- document_version
|
||||
properties:
|
||||
document_version:
|
||||
$ref: "#/components/schemas/DocumentVersion"
|
||||
|
||||
UpdateDocumentVersionInput:
|
||||
type: object
|
||||
required:
|
||||
- document_version_id
|
||||
properties:
|
||||
document_version_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document version ID
|
||||
title:
|
||||
type: string
|
||||
description: Document version title
|
||||
content:
|
||||
type: string
|
||||
description: Document content in markdown format
|
||||
classification:
|
||||
$ref: "#/components/schemas/DocumentClassification"
|
||||
description: Document classification
|
||||
document_type:
|
||||
$ref: "#/components/schemas/DocumentType"
|
||||
description: Document type
|
||||
|
||||
UpdateDocumentVersionOutput:
|
||||
type: object
|
||||
description: Updated draft; document_version.content is markdown
|
||||
required:
|
||||
- document_version
|
||||
properties:
|
||||
document_version:
|
||||
$ref: "#/components/schemas/DocumentVersion"
|
||||
|
||||
DeleteDraftDocumentVersionInput:
|
||||
type: object
|
||||
required:
|
||||
- document_version_id
|
||||
properties:
|
||||
document_version_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Document version ID
|
||||
|
||||
DeleteDraftDocumentVersionOutput:
|
||||
type: object
|
||||
required:
|
||||
- deleted_document_version_id
|
||||
properties:
|
||||
deleted_document_version_id:
|
||||
$ref: "#/components/schemas/GID"
|
||||
description: Deleted document version ID
|
||||
|
||||
PublishMajorDocumentVersionInput:
|
||||
type: object
|
||||
required:
|
||||
@@ -8398,6 +8360,15 @@ tools:
|
||||
$ref: "#/components/schemas/UpdateDocumentInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/UpdateDocumentOutput"
|
||||
- name: deleteDocumentDraft
|
||||
description: Delete the latest draft version of a document, reverting to the last published version. Cannot delete the initial v0.1 draft.
|
||||
hints:
|
||||
readonly: false
|
||||
destructive: true
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/DeleteDocumentDraftInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/DeleteDocumentDraftOutput"
|
||||
- name: archiveDocument
|
||||
description: Archive a document to prevent further modifications
|
||||
hints:
|
||||
@@ -8432,30 +8403,6 @@ tools:
|
||||
$ref: "#/components/schemas/GetDocumentVersionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/GetDocumentVersionOutput"
|
||||
- name: createDraftDocumentVersion
|
||||
description: Create a new draft version from the latest published version
|
||||
hints:
|
||||
readonly: false
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/CreateDraftDocumentVersionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/CreateDraftDocumentVersionOutput"
|
||||
- name: updateDocumentVersion
|
||||
description: Update an existing draft document version content
|
||||
hints:
|
||||
readonly: false
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/UpdateDocumentVersionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/UpdateDocumentVersionOutput"
|
||||
- name: deleteDraftDocumentVersion
|
||||
description: Delete a draft document version
|
||||
hints:
|
||||
readonly: false
|
||||
inputSchema:
|
||||
$ref: "#/components/schemas/DeleteDraftDocumentVersionInput"
|
||||
outputSchema:
|
||||
$ref: "#/components/schemas/DeleteDraftDocumentVersionOutput"
|
||||
- name: publishMajorDocumentVersion
|
||||
description: Publish a draft document version as a new major version
|
||||
hints:
|
||||
|
||||
Reference in New Issue
Block a user