diff --git a/domain/conversion/conversion.go b/domain/conversion/conversion.go index 5036ba66..571d898e 100644 --- a/domain/conversion/conversion.go +++ b/domain/conversion/conversion.go @@ -19,6 +19,8 @@ import ( "net/http" "strings" + "github.com/documize/community/model/workflow" + "github.com/documize/community/core/env" api "github.com/documize/community/core/convapi" @@ -164,6 +166,7 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St document.UserID = ctx.UserID documentID := uniqueid.Generate() document.RefID = documentID + document.Lifecycle = workflow.LifecycleLive err = store.Document.Add(ctx, document) if err != nil { diff --git a/domain/document/mysql/store.go b/domain/document/mysql/store.go index 428a5d1d..099a08db 100644 --- a/domain/document/mysql/store.go +++ b/domain/document/mysql/store.go @@ -137,7 +137,7 @@ func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu `SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, protection, approval, lifecycle, versioned, versionid, versionorder, groupid, created, revised FROM document - WHERE orgid=? AND labelid=? AND template=1 ANd lifecycle=1 + WHERE orgid=? AND labelid=? AND template=1 AND lifecycle=1 AND labelid IN ( SELECT refid FROM label WHERE orgid=? diff --git a/domain/space/endpoint.go b/domain/space/endpoint.go index 87a4f843..096502c4 100644 --- a/domain/space/endpoint.go +++ b/domain/space/endpoint.go @@ -119,7 +119,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { err = h.Store.Permission.AddPermissions(ctx, perm, permission.SpaceOwner, permission.SpaceManage, permission.SpaceView, permission.DocumentAdd, permission.DocumentCopy, permission.DocumentDelete, permission.DocumentEdit, permission.DocumentMove, - permission.DocumentTemplate, permission.DocumentApprove) + permission.DocumentTemplate, permission.DocumentApprove, permission.DocumentVersion, permission.DocumentVersion) if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) @@ -177,7 +177,6 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { if model.CopyDocument { docs, err := h.Store.Document.GetBySpace(ctx, model.CloneID) - if err != nil { ctx.Transaction.Rollback() response.WriteServerError(w, method, err) @@ -188,6 +187,11 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { toCopy = append(toCopy, docs...) } + // documemt.GroupID groups versioned documents together + // and must be reassigned a new value when being copied + // to avoid conflicts. + groupChange := make(map[string]string) + if len(toCopy) > 0 { for _, t := range toCopy { origID := t.RefID @@ -196,6 +200,16 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) { t.RefID = documentID t.LabelID = sp.RefID + // Reassign group ID + if len(t.GroupID) > 0 { + if len(groupChange[t.GroupID]) > 0 { + t.GroupID = groupChange[t.GroupID] + } else { + groupChange[t.GroupID] = uniqueid.Generate() + t.GroupID = groupChange[t.GroupID] + } + } + err = h.Store.Document.Add(ctx, t) if err != nil { ctx.Transaction.Rollback() diff --git a/domain/template/endpoint.go b/domain/template/endpoint.go index a78a7fde..dc923f9d 100644 --- a/domain/template/endpoint.go +++ b/domain/template/endpoint.go @@ -142,6 +142,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) { doc.RefID = docID doc.ID = 0 doc.Template = true + doc.Lifecycle = workflow.LifecycleLive // Duplicate pages and associated meta pages, err := h.Store.Page.GetPages(ctx, model.DocumentID) @@ -307,6 +308,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) { d.LabelID = folderID d.UserID = ctx.UserID d.Title = docTitle + d.Lifecycle = workflow.LifecycleLive err = h.Store.Document.Add(ctx, d) if err != nil {