mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
Handle draft documents during export process
This commit is contained in:
parent
4949043df9
commit
9d80c5fc8c
1 changed files with 59 additions and 25 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/documize/community/domain/permission"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/page"
|
||||
pm "github.com/documize/community/model/permission"
|
||||
"github.com/documize/community/model/workflow"
|
||||
)
|
||||
|
||||
|
@ -119,16 +120,30 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
|||
return toc, "", nil
|
||||
}
|
||||
|
||||
// Get space.
|
||||
space, err := s.Space.Get(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Get all documents for space.
|
||||
docs, err := s.Document.GetBySpace(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Can user view drafts?
|
||||
// If space defaults to draft documents, then this means
|
||||
// user can view drafts as long as they have edit rights.
|
||||
viewDrafts := permission.CanViewDrafts(ctx, s, spaceID)
|
||||
if space.Lifecycle == workflow.LifecycleDraft && permission.HasPermission(ctx, s, spaceID, pm.DocumentEdit) {
|
||||
viewDrafts = true
|
||||
}
|
||||
|
||||
// Remove documents that cannot be seen due to lack of category view/access permission.
|
||||
cats, err := s.Category.GetBySpace(ctx, spaceID)
|
||||
members, err := s.Category.GetSpaceCategoryMembership(ctx, spaceID)
|
||||
docs = FilterCategoryProtected(docs, cats, members, false)
|
||||
docs = FilterCategoryProtected(docs, cats, members, viewDrafts)
|
||||
|
||||
// Keep the latest version when faced with multiple versions.
|
||||
docs = FilterLastVersion(docs)
|
||||
|
@ -136,7 +151,6 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
|||
// Turn each document into TOC entry and HTML content export
|
||||
b := strings.Builder{}
|
||||
for _, d := range docs {
|
||||
if d.Lifecycle == workflow.LifecycleLive {
|
||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||
if e == nil && len(docHTML) > 0 {
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
||||
|
@ -145,7 +159,6 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
|||
return toc, b.String(), err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toc, b.String(), nil
|
||||
}
|
||||
|
@ -157,16 +170,30 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
|||
return toc, "", nil
|
||||
}
|
||||
|
||||
// Get space.
|
||||
space, err := s.Space.Get(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Get all documents for space.
|
||||
docs, err := s.Document.GetBySpace(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Can user view drafts?
|
||||
// If space defaults to draft documents, then this means
|
||||
// user can view drafts as long as they have edit rights.
|
||||
viewDrafts := permission.CanViewDrafts(ctx, s, spaceID)
|
||||
if space.Lifecycle == workflow.LifecycleDraft && permission.HasPermission(ctx, s, spaceID, pm.DocumentEdit) {
|
||||
viewDrafts = true
|
||||
}
|
||||
|
||||
// Remove documents that cannot be seen due to lack of category view/access permission.
|
||||
cats, err := s.Category.GetBySpace(ctx, spaceID)
|
||||
members, err := s.Category.GetSpaceCategoryMembership(ctx, spaceID)
|
||||
docs = FilterCategoryProtected(docs, cats, members, false)
|
||||
docs = FilterCategoryProtected(docs, cats, members, viewDrafts)
|
||||
|
||||
// Keep the latest version when faced with multiple versions.
|
||||
docs = FilterLastVersion(docs)
|
||||
|
@ -192,7 +219,6 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
|||
// Turn each document into TOC entry and HTML content export
|
||||
b := strings.Builder{}
|
||||
for _, d := range exportDocs {
|
||||
if d.Lifecycle == workflow.LifecycleLive {
|
||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||
if e == nil && len(docHTML) > 0 {
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
||||
|
@ -201,7 +227,6 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
|||
return toc, b.String(), err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return toc, b.String(), nil
|
||||
}
|
||||
|
@ -213,16 +238,30 @@ func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, d
|
|||
return toc, "", nil
|
||||
}
|
||||
|
||||
// Get space.
|
||||
space, err := s.Space.Get(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Get all documents for space.
|
||||
docs, err := s.Document.GetBySpace(ctx, spaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return toc, export, err
|
||||
}
|
||||
|
||||
// Can user view drafts?
|
||||
// If space defaults to draft documents, then this means
|
||||
// user can view drafts as long as they have edit rights.
|
||||
viewDrafts := permission.CanViewDrafts(ctx, s, spaceID)
|
||||
if space.Lifecycle == workflow.LifecycleDraft && permission.HasPermission(ctx, s, spaceID, pm.DocumentEdit) {
|
||||
viewDrafts = true
|
||||
}
|
||||
|
||||
// Remove documents that cannot be seen due to lack of category view/access permission.
|
||||
cats, err := s.Category.GetBySpace(ctx, spaceID)
|
||||
members, err := s.Category.GetSpaceCategoryMembership(ctx, spaceID)
|
||||
docs = FilterCategoryProtected(docs, cats, members, false)
|
||||
docs = FilterCategoryProtected(docs, cats, members, viewDrafts)
|
||||
|
||||
// Keep the latest version when faced with multiple versions.
|
||||
docs = FilterLastVersion(docs)
|
||||
|
@ -263,11 +302,6 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
|||
return export, err
|
||||
}
|
||||
|
||||
// Skip any document that is not live and published.
|
||||
if doc.Lifecycle != workflow.LifecycleLive {
|
||||
return export, nil
|
||||
}
|
||||
|
||||
// Get published pages and new pages awaiting approval.
|
||||
pages, err := s.Page.GetPages(ctx, documentID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
|
@ -310,7 +344,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
|||
|
||||
// Process seciton content before writing out as HTML.
|
||||
section := page.Body
|
||||
if page.ContentType == "plantuml" {
|
||||
if page.ContentType == "plantuml" || page.ContentType == "flowchart" {
|
||||
section = fmt.Sprintf(`<img src="%s" />`, page.Body)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue