1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 12:05:23 +02:00

[WIP] PDF viewer section & per section attachments

This commit is contained in:
Harvey Kandola 2019-04-17 17:13:18 +01:00
parent c0ed3c3d04
commit 166aeba09b
428 changed files with 45874 additions and 802 deletions

View file

@ -217,7 +217,6 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
response.WriteServerError(w, method, err)
return
}
if len(a) == 0 {
a = []attachment.Attachment{}
}
@ -299,6 +298,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
return
}
// File can be associated with a section as well.
sectionID := request.Query(r, "page")
if !permission.CanChangeDocument(ctx, *h.Store, documentID) {
response.WriteForbiddenError(w)
return
@ -336,6 +338,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
a.FileID = random[0:9]
a.Filename = filename.Filename
a.Data = b.Bytes()
a.SectionID = sectionID
ctx.Transaction, err = h.Runtime.Db.Beginx()
if err != nil {

View file

@ -36,8 +36,8 @@ func (s Store) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
bits := strings.Split(a.Filename, ".")
a.Extension = bits[len(bits)-1]
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_doc_attachment (c_refid, c_orgid, c_docid, c_job, c_fileid, c_filename, c_data, c_extension, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
a.RefID, a.OrgID, a.DocumentID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_doc_attachment (c_refid, c_orgid, c_docid, c_sectionid, c_job, c_fileid, c_filename, c_data, c_extension, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
a.RefID, a.OrgID, a.DocumentID, a.SectionID, a.Job, a.FileID, a.Filename, a.Data, a.Extension, a.Created, a.Revised)
if err != nil {
err = errors.Wrap(err, "execute insert attachment")
@ -50,7 +50,7 @@ func (s Store) Add(ctx domain.RequestContext, a attachment.Attachment) (err erro
func (s Store) GetAttachment(ctx domain.RequestContext, orgID, attachmentID string) (a attachment.Attachment, err error) {
err = s.Runtime.Db.Get(&a, s.Bind(`
SELECT id, c_refid AS refid,
c_orgid AS orgid, c_docid AS documentid, c_job AS job, c_fileid AS fileid,
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
@ -68,7 +68,7 @@ func (s Store) GetAttachment(ctx domain.RequestContext, orgID, attachmentID stri
func (s Store) GetAttachments(ctx domain.RequestContext, docID 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_job AS job, c_fileid AS fileid,
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_extension AS extension,
c_created AS created, c_revised AS revised
FROM dmz_doc_attachment
@ -92,7 +92,7 @@ func (s Store) GetAttachments(ctx domain.RequestContext, docID string) (a []atta
func (s Store) GetAttachmentsWithData(ctx domain.RequestContext, docID 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_job AS job, c_fileid AS fileid,
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