mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
Set document lifecycle defaults
This commit is contained in:
parent
d9a2b16c2a
commit
297ce94546
4 changed files with 22 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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=?
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue