diff --git a/domain/document/endpoint.go b/domain/document/endpoint.go index 37e6b8db..50d165d9 100644 --- a/domain/document/endpoint.go +++ b/domain/document/endpoint.go @@ -732,6 +732,18 @@ func (h *Handler) Export(w http.ResponseWriter, r *http.Request) { method := "document.Export" ctx := domain.GetRequestContext(r) + // Deduce ORG if anon user. + if len(ctx.OrgID) == 0 { + ctx.Subdomain = organization.GetSubdomainFromHost(r) + org, err := h.Store.Organization.GetOrganizationByDomain(ctx.Subdomain) + if err != nil { + response.WriteServerError(w, method, err) + h.Runtime.Log.Error(method, err) + return + } + ctx.OrgID = org.RefID + } + defer streamutil.Close(r.Body) body, err := ioutil.ReadAll(r.Body) if err != nil { @@ -756,6 +768,6 @@ func (h *Handler) Export(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.Write([]byte(export)) w.WriteHeader(http.StatusOK) + w.Write([]byte(export)) } diff --git a/domain/document/export.go b/domain/document/export.go index 92443567..1fb75cfe 100644 --- a/domain/document/export.go +++ b/domain/document/export.go @@ -12,7 +12,11 @@ package document import ( + "database/sql" "fmt" + "github.com/documize/community/domain/permission" + "github.com/documize/community/model/page" + "github.com/documize/community/model/workflow" "strings" "time" @@ -35,6 +39,7 @@ type exportTOC struct { // BuildExport generates self-enclosed HTML for content specified. func BuildExport(ctx domain.RequestContext, s domain.Store, spec exportSpec) (html string, err error) { export := strings.Builder{} + content := strings.Builder{} toc := []exportTOC{} switch spec.FilterType { @@ -75,25 +80,138 @@ func BuildExport(ctx domain.RequestContext, s domain.Store, spec exportSpec) (ht export.WriteString("") export.WriteString("
") - // Generate data header and table of contents. + // Show title and timestamp. generated := time.Now().UTC().Format(time.ANSIC) export.WriteString(fmt.Sprintf("