mirror of
https://github.com/documize/community.git
synced 2025-08-05 05:25:27 +02:00
Allow doc/section/files links to open in tabs
Closes #233 and might help #236
This commit is contained in:
parent
92696c5181
commit
9e3eac19aa
12 changed files with 886 additions and 743 deletions
|
@ -15,13 +15,14 @@ import (
|
|||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/documize/community/domain/auth"
|
||||
"github.com/documize/community/model/space"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/domain/auth"
|
||||
"github.com/documize/community/model/space"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/request"
|
||||
"github.com/documize/community/core/response"
|
||||
|
@ -161,7 +162,7 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) {
|
|||
canDownload = true
|
||||
}
|
||||
|
||||
if len(secureToken) == 0 && len(authToken) == 0 {
|
||||
if !canDownload && len(secureToken) == 0 && len(authToken) == 0 {
|
||||
h.Runtime.Log.Error("get attachment received no access token", err)
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
|
|
|
@ -13,9 +13,12 @@ package link
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/documize/community/core/stringutil"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/request"
|
||||
"github.com/documize/community/core/response"
|
||||
|
@ -160,3 +163,55 @@ func (h *Handler) SearchLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteJSON(w, payload)
|
||||
}
|
||||
|
||||
// GetLink returns link object for given ID.
|
||||
func (h *Handler) GetLink(w http.ResponseWriter, r *http.Request) {
|
||||
method := "link.GetLink"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
// Param check.
|
||||
linkID := request.Param(r, "linkID")
|
||||
if len(linkID) == 0 {
|
||||
response.WriteMissingDataError(w, method, "linkID")
|
||||
return
|
||||
}
|
||||
|
||||
// Load link record.
|
||||
link, err := h.Store.Link.GetLink(ctx, linkID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check document permissions.
|
||||
if !permission.CanViewDocument(ctx, *h.Store, link.SourceDocumentID) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
// Build URL for link
|
||||
url := ""
|
||||
|
||||
// Jump-to-document link type.
|
||||
if link.LinkType == "document" {
|
||||
doc, err := h.Store.Document.Get(ctx, link.TargetDocumentID)
|
||||
if err != nil {
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
url = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
||||
doc.SpaceID, doc.SpaceID, doc.RefID, stringutil.MakeSlug(doc.Name)))
|
||||
}
|
||||
|
||||
// Jump-to-section link type.
|
||||
if link.LinkType == "section" || link.LinkType == "tab" {
|
||||
doc, err := h.Store.Document.Get(ctx, link.TargetDocumentID)
|
||||
if err != nil {
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
url = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s?currentPageId=%s",
|
||||
doc.SpaceID, doc.SpaceID, doc.RefID,
|
||||
stringutil.MakeSlug(doc.Name), link.TargetID))
|
||||
}
|
||||
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
|
|
|
@ -46,6 +46,25 @@ func (s Store) Add(ctx domain.RequestContext, l link.Link) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// GetLink returns specified link.
|
||||
func (s Store) GetLink(ctx domain.RequestContext, linkID string) (l link.Link, err error) {
|
||||
err = s.Runtime.Db.Get(&l, s.Bind(`
|
||||
select c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_userid AS userid,
|
||||
c_sourcedocid AS sourcedocumentid, c_sourcesectionid AS sourcesectionid,
|
||||
c_targetdocid AS targetdocumentid, c_targetid AS targetid, c_externalid AS externalid,
|
||||
c_type as linktype, c_orphan As orphan, c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc_link
|
||||
WHERE c_orgid=? AND c_refid=?`),
|
||||
ctx.OrgID, linkID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "select link %s", linkID)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetDocumentOutboundLinks returns outbound links for specified document.
|
||||
func (s Store) GetDocumentOutboundLinks(ctx domain.RequestContext, documentID string) (links []link.Link, err error) {
|
||||
err = s.Runtime.Db.Select(&links, s.Bind(`
|
||||
|
|
|
@ -215,6 +215,7 @@ type AttachmentStorer interface {
|
|||
type LinkStorer interface {
|
||||
Add(ctx domain.RequestContext, l link.Link) (err error)
|
||||
SearchCandidates(ctx domain.RequestContext, keywords string) (docs []link.Candidate, pages []link.Candidate, attachments []link.Candidate, err error)
|
||||
GetLink(ctx domain.RequestContext, linkID string) (l link.Link, err error)
|
||||
GetDocumentOutboundLinks(ctx domain.RequestContext, documentID string) (links []link.Link, err error)
|
||||
GetPageLinks(ctx domain.RequestContext, documentID, pageID string) (links []link.Link, err error)
|
||||
MarkOrphanDocumentLink(ctx domain.RequestContext, documentID string) (err error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue