mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
Continued MySQL/PostgreSQL store provider refactoring
Refactored, renamed, removed storage related code. Basic smoke test passed for PostgreSQL whilst fully working on MySQL variants as per usual.
This commit is contained in:
parent
b455e5eaf5
commit
97beb3f4d3
81 changed files with 1454 additions and 1497 deletions
|
@ -14,6 +14,7 @@ package document
|
|||
import (
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/category"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/page"
|
||||
|
@ -64,7 +65,7 @@ func FilterCategoryProtected(docs []doc.Document, cats []category.Category, memb
|
|||
}
|
||||
|
||||
// CopyDocument clones an existing document
|
||||
func CopyDocument(ctx domain.RequestContext, s domain.Store, documentID string) (newDocumentID string, err error) {
|
||||
func CopyDocument(ctx domain.RequestContext, s store.Store, documentID string) (newDocumentID string, err error) {
|
||||
doc, err := s.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "unable to fetch existing document")
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/documize/community/domain/organization"
|
||||
"github.com/documize/community/domain/permission"
|
||||
indexer "github.com/documize/community/domain/search"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/activity"
|
||||
"github.com/documize/community/model/audit"
|
||||
"github.com/documize/community/model/doc"
|
||||
|
@ -43,7 +44,7 @@ import (
|
|||
// Handler contains the runtime information such as logging and database.
|
||||
type Handler struct {
|
||||
Runtime *env.Runtime
|
||||
Store *domain.Store
|
||||
Store *store.Store
|
||||
Indexer indexer.Indexer
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/permission"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/page"
|
||||
pm "github.com/documize/community/model/permission"
|
||||
|
@ -39,7 +40,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) {
|
||||
func BuildExport(ctx domain.RequestContext, s store.Store, spec exportSpec) (html string, err error) {
|
||||
export := strings.Builder{}
|
||||
content := strings.Builder{}
|
||||
toc := []exportTOC{}
|
||||
|
@ -114,7 +115,7 @@ func BuildExport(ctx domain.RequestContext, s domain.Store, spec exportSpec) (ht
|
|||
}
|
||||
|
||||
// exportSpace returns documents exported.
|
||||
func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc []exportTOC, export string, err error) {
|
||||
func exportSpace(ctx domain.RequestContext, s store.Store, spaceID string) (toc []exportTOC, export string, err error) {
|
||||
// Permission check.
|
||||
if !permission.CanViewSpace(ctx, s, spaceID) {
|
||||
return toc, "", nil
|
||||
|
@ -164,7 +165,7 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
|||
}
|
||||
|
||||
// exportCategory returns documents exported for selected categories.
|
||||
func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, category []string) (toc []exportTOC, export string, err error) {
|
||||
func exportCategory(ctx domain.RequestContext, s store.Store, spaceID string, category []string) (toc []exportTOC, export string, err error) {
|
||||
// Permission check.
|
||||
if !permission.CanViewSpace(ctx, s, spaceID) {
|
||||
return toc, "", nil
|
||||
|
@ -232,7 +233,7 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
|||
}
|
||||
|
||||
// exportDocument returns documents for export.
|
||||
func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, document []string) (toc []exportTOC, export string, err error) {
|
||||
func exportDocument(ctx domain.RequestContext, s store.Store, spaceID string, document []string) (toc []exportTOC, export string, err error) {
|
||||
// Permission check.
|
||||
if !permission.CanViewSpace(ctx, s, spaceID) {
|
||||
return toc, "", nil
|
||||
|
@ -288,7 +289,7 @@ func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, d
|
|||
}
|
||||
|
||||
// processDocument writes out document as HTML content
|
||||
func processDocument(ctx domain.RequestContext, s domain.Store, documentID string) (export string, err error) {
|
||||
func processDocument(ctx domain.RequestContext, s store.Store, documentID string) (export string, err error) {
|
||||
b := strings.Builder{}
|
||||
|
||||
// Permission check.
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
// Store provides data access to space category information.
|
||||
type Store struct {
|
||||
store.Context
|
||||
domain.DocumentStorer
|
||||
store.DocumentStorer
|
||||
}
|
||||
|
||||
// Add inserts the given document record into the document table and audits that it has been done.
|
||||
|
@ -35,8 +35,9 @@ func (s Store) Add(ctx domain.RequestContext, d doc.Document) (err error) {
|
|||
d.Revised = d.Created // put same time in both fields
|
||||
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`
|
||||
INSERT INTO dmz_doc (c_refid, c_orgid, c_spaceid, c_userid, c_job, c_location, c_name, c_desc, c_slug, c_tags, c_template, c_protection, c_approval, c_lifecycle, c_versioned, c_versionid, c_versionorder, c_groupid, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
INSERT INTO dmz_doc (c_refid, c_orgid, c_spaceid, c_userid, c_job, c_location, c_name, c_desc, c_slug, c_tags,
|
||||
c_template, c_protection, c_approval, c_lifecycle, c_versioned, c_versionid, c_versionorder, c_groupid, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
d.RefID, d.OrgID, d.SpaceID, d.UserID, d.Job, d.Location, d.Name, d.Excerpt, d.Slug, d.Tags,
|
||||
d.Template, d.Protection, d.Approval, d.Lifecycle, d.Versioned, d.VersionID, d.VersionOrder, d.GroupID, d.Created, d.Revised)
|
||||
|
||||
|
@ -83,7 +84,7 @@ func (s Store) GetBySpace(ctx domain.RequestContext, spaceID string) (documents
|
|||
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
||||
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc
|
||||
WHERE c_orgid=? AND c_template=0 AND c_spaceid IN
|
||||
WHERE c_orgid=? AND c_template=false AND c_spaceid IN
|
||||
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid=? AND c_refid IN
|
||||
(SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||
|
@ -115,7 +116,7 @@ func (s Store) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu
|
|||
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
||||
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_doc
|
||||
WHERE c_orgid=? AND c_spaceid=? AND c_template=1 AND c_lifecycle=1
|
||||
WHERE c_orgid=? AND c_spaceid=? AND c_template=true AND c_lifecycle=1
|
||||
AND c_spaceid IN
|
||||
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
||||
|
@ -146,7 +147,7 @@ func (s Store) PublicDocuments(ctx domain.RequestContext, orgID string) (documen
|
|||
SELECT d.c_refid AS documentid, d.c_name AS document, d.c_revised as revised, l.c_refid AS spaceid, l.c_name AS space
|
||||
FROM dmz_doc d
|
||||
LEFT JOIN dmz_space l ON l.c_refid=d.c_spaceid
|
||||
WHERE d.c_orgid=? AND l.c_type=1 AND d.c_lifecycle=1 AND d.c_template=0`),
|
||||
WHERE d.c_orgid=? AND l.c_type=1 AND d.c_lifecycle=1 AND d.c_template=false`),
|
||||
orgID)
|
||||
|
||||
if err == sql.ErrNoRows {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue