mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
Specify default categories for new documents
Closes #339 All new documents will be assigned default categories. Documents created from templates that already have categories take precedence.
This commit is contained in:
parent
5c1ad25dc9
commit
f117e91bcb
18 changed files with 1284 additions and 1134 deletions
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/attachment"
|
||||
"github.com/documize/community/model/audit"
|
||||
cm "github.com/documize/community/model/category"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/page"
|
||||
pm "github.com/documize/community/model/permission"
|
||||
|
@ -427,6 +428,30 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// If document has no categories then we use
|
||||
// default categories for the space.
|
||||
if len(cats) == 0 {
|
||||
cats, err = h.Store.Category.GetBySpace(ctx, d.SpaceID)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("fetch default categories for new document", err)
|
||||
}
|
||||
for ic := range cats {
|
||||
if cats[ic].IsDefault {
|
||||
c := cm.Member{}
|
||||
c.OrgID = ctx.OrgID
|
||||
c.SpaceID = d.SpaceID
|
||||
c.RefID = uniqueid.Generate()
|
||||
c.DocumentID = d.RefID
|
||||
c.CategoryID = cats[ic].RefID
|
||||
|
||||
err = h.Store.Category.AssociateDocument(ctx, c)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("apply default category to new document", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Space.SetStats(ctx, d.SpaceID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue