1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 20:15:26 +02:00

Complete PDF section type

This commit is contained in:
Harvey Kandola 2019-04-19 11:30:40 +01:00
parent 7fde947a52
commit b5cd378302
8 changed files with 98 additions and 4 deletions

View file

@ -13,6 +13,7 @@ package attachment
import (
"database/sql"
"fmt"
"strings"
"time"
@ -88,6 +89,31 @@ func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
return
}
// GetSectionAttachments returns a slice containing the attachment records
// with file data for specified document section.
func (s Store) GetSectionAttachments(ctx domain.RequestContext, sectionID string) (a []attachment.Attachment, err error) {
err = s.Runtime.Db.Select(&a, s.Bind(`
SELECT id, c_refid AS refid,
c_orgid AS orgid, c_docid AS documentid, c_sectionid AS sectionid, c_job AS job, c_fileid AS fileid,
c_filename AS filename, c_data AS data, c_extension AS extension,
c_created AS created, c_revised AS revised
FROM dmz_doc_attachment
WHERE c_orgid=? AND c_sectionid=?
ORDER BY c_filename`),
ctx.OrgID, sectionID)
if err == sql.ErrNoRows {
err = nil
a = []attachment.Attachment{}
}
if err != nil {
err = errors.Wrap(err, "execute select section attachments")
return
}
return
}
// GetAttachmentsWithData returns a slice containing the attachment records (including their data) for document docID, ordered by filename.
func (s Store) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error) {
err = s.Runtime.Db.Select(&a, s.Bind(`
@ -116,3 +142,11 @@ func (s Store) GetAttachmentsWithData(ctx domain.RequestContext, docID string) (
func (s Store) Delete(ctx domain.RequestContext, id string) (rows int64, err error) {
return s.DeleteConstrained(ctx.Transaction, "dmz_doc_attachment", ctx.OrgID, id)
}
// DeleteSection removes all attachments agasinst a section.
func (s Store) DeleteSection(ctx domain.RequestContext, sectionID string) (rows int64, err error) {
rows, err = s.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_attachment WHERE c_orgid='%s' AND c_sectionid='%s'",
ctx.OrgID, sectionID))
return
}

View file

@ -22,6 +22,7 @@ import (
"github.com/documize/community/core/env"
"github.com/documize/community/core/request"
"github.com/documize/community/core/response"
"github.com/documize/community/core/secrets"
"github.com/documize/community/core/streamutil"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain"
@ -599,6 +600,8 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
h.Store.Page.DeletePageRevisions(ctx, pageID)
h.Store.Attachment.DeleteSection(ctx, pageID)
// Update doc revised.
h.Store.Document.UpdateRevised(ctx, doc.RefID)
@ -700,6 +703,8 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
h.Store.Page.DeletePageRevisions(ctx, page.SectionID)
h.Store.Attachment.DeleteSection(ctx, page.SectionID)
// Draft actions are not logged
if doc.Lifecycle == workflow.LifecycleLive {
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
@ -977,7 +982,27 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
h.Store.Block.IncrementUsage(ctx, model.Page.TemplateID)
}
// Log t actions are not logged
// Copy section attachments.
at, err := h.Store.Attachment.GetSectionAttachments(ctx, pageID)
if err != nil {
h.Runtime.Log.Error(method, err)
}
for i := range at {
at[i].DocumentID = targetID
at[i].SectionID = newPageID
at[i].RefID = uniqueid.Generate()
random := secrets.GenerateSalt()
at[i].FileID = random[0:9]
err1 := h.Store.Attachment.Add(ctx, at[i])
if err1 != nil {
ctx.Transaction.Rollback()
response.WriteServerError(w, method, err1)
h.Runtime.Log.Error(method, err1)
return
}
}
if doc.Lifecycle == workflow.LifecycleLive {
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
SpaceID: doc.SpaceID,

View file

@ -207,8 +207,10 @@ type AttachmentStorer interface {
Add(ctx domain.RequestContext, a attachment.Attachment) (err error)
GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error)
GetAttachments(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error)
GetSectionAttachments(ctx domain.RequestContext, sectionID string) (a []attachment.Attachment, err error)
GetAttachmentsWithData(ctx domain.RequestContext, docID string) (a []attachment.Attachment, err error)
Delete(ctx domain.RequestContext, id string) (rows int64, err error)
DeleteSection(ctx domain.RequestContext, id string) (rows int64, err error)
}
// LinkStorer defines required methods for persisting content links