mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
Make API work with new schema
This commit is contained in:
parent
28342fcf5e
commit
4f0cc2f616
48 changed files with 1218 additions and 1097 deletions
|
@ -125,7 +125,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
pageID := uniqueid.Generate()
|
||||
model.Page.RefID = pageID
|
||||
model.Meta.PageID = pageID
|
||||
model.Meta.SectionID = pageID
|
||||
model.Meta.OrgID = ctx.OrgID // required for Render call below
|
||||
model.Meta.UserID = ctx.UserID // required for Render call below
|
||||
model.Page.SetDefaults()
|
||||
|
@ -160,16 +160,16 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(model.Page.BlockID) > 0 {
|
||||
h.Store.Block.IncrementUsage(ctx, model.Page.BlockID)
|
||||
if len(model.Page.TemplateID) > 0 {
|
||||
h.Store.Block.IncrementUsage(ctx, model.Page.TemplateID)
|
||||
}
|
||||
|
||||
// Draft actions are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: model.Page.DocumentID,
|
||||
PageID: model.Page.RefID,
|
||||
SectionID: model.Page.RefID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeCreated})
|
||||
}
|
||||
|
@ -438,9 +438,9 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
// Draft edits are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: model.Page.DocumentID,
|
||||
PageID: model.Page.RefID,
|
||||
SectionID: model.Page.RefID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeEdited})
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
link.OrgID = ctx.OrgID
|
||||
link.UserID = ctx.UserID
|
||||
link.SourceDocumentID = model.Page.DocumentID
|
||||
link.SourcePageID = model.Page.RefID
|
||||
link.SourceSectionID = model.Page.RefID
|
||||
|
||||
if link.LinkType == "document" || link.LinkType == "network" {
|
||||
link.TargetID = ""
|
||||
|
@ -562,8 +562,8 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(p.BlockID) > 0 {
|
||||
h.Store.Block.DecrementUsage(ctx, p.BlockID)
|
||||
if len(p.TemplateID) > 0 {
|
||||
h.Store.Block.DecrementUsage(ctx, p.TemplateID)
|
||||
}
|
||||
|
||||
_, err = h.Store.Page.Delete(ctx, documentID, pageID)
|
||||
|
@ -577,9 +577,9 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
// Draft actions are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: documentID,
|
||||
PageID: pageID,
|
||||
SectionID: pageID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeDeleted})
|
||||
}
|
||||
|
@ -647,7 +647,7 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
for _, page := range *model {
|
||||
pageData, err := h.Store.Page.Get(ctx, page.PageID)
|
||||
pageData, err := h.Store.Page.Get(ctx, page.SectionID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -670,11 +670,11 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
}
|
||||
if len(pageData.BlockID) > 0 {
|
||||
h.Store.Block.DecrementUsage(ctx, pageData.BlockID)
|
||||
if len(pageData.TemplateID) > 0 {
|
||||
h.Store.Block.DecrementUsage(ctx, pageData.TemplateID)
|
||||
}
|
||||
|
||||
_, err = h.Store.Page.Delete(ctx, documentID, page.PageID)
|
||||
_, err = h.Store.Page.Delete(ctx, documentID, page.SectionID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -682,20 +682,20 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
go h.Indexer.DeleteContent(ctx, page.PageID)
|
||||
go h.Indexer.DeleteContent(ctx, page.SectionID)
|
||||
|
||||
h.Store.Link.DeleteSourcePageLinks(ctx, page.PageID)
|
||||
h.Store.Link.DeleteSourcePageLinks(ctx, page.SectionID)
|
||||
|
||||
h.Store.Link.MarkOrphanPageLink(ctx, page.PageID)
|
||||
h.Store.Link.MarkOrphanPageLink(ctx, page.SectionID)
|
||||
|
||||
h.Store.Page.DeletePageRevisions(ctx, page.PageID)
|
||||
h.Store.Page.DeletePageRevisions(ctx, page.SectionID)
|
||||
|
||||
// Draft actions are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: documentID,
|
||||
PageID: page.PageID,
|
||||
SectionID: page.SectionID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeDeleted})
|
||||
}
|
||||
|
@ -769,7 +769,7 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
for _, p := range *model {
|
||||
err = h.Store.Page.UpdateSequence(ctx, documentID, p.PageID, p.Sequence)
|
||||
err = h.Store.Page.UpdateSequence(ctx, documentID, p.SectionID, p.Sequence)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -838,7 +838,7 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
for _, p := range *model {
|
||||
err = h.Store.Page.UpdateLevel(ctx, documentID, p.PageID, p.Level)
|
||||
err = h.Store.Page.UpdateLevel(ctx, documentID, p.SectionID, p.Level)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -932,7 +932,7 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
|||
p.DocumentID = targetID
|
||||
p.UserID = ctx.UserID
|
||||
pageMeta.DocumentID = targetID
|
||||
pageMeta.PageID = newPageID
|
||||
pageMeta.SectionID = newPageID
|
||||
pageMeta.UserID = ctx.UserID
|
||||
|
||||
model := new(page.NewPage)
|
||||
|
@ -954,16 +954,16 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if len(model.Page.BlockID) > 0 {
|
||||
h.Store.Block.IncrementUsage(ctx, model.Page.BlockID)
|
||||
if len(model.Page.TemplateID) > 0 {
|
||||
h.Store.Block.IncrementUsage(ctx, model.Page.TemplateID)
|
||||
}
|
||||
|
||||
// Log t actions are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: targetID,
|
||||
PageID: newPageID,
|
||||
SectionID: newPageID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeCreated})
|
||||
}
|
||||
|
@ -1215,9 +1215,9 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
|||
// Draft actions are not logged
|
||||
if doc.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: p.DocumentID,
|
||||
PageID: p.RefID,
|
||||
SectionID: p.RefID,
|
||||
SourceType: activity.SourceTypePage,
|
||||
ActivityType: activity.TypeReverted})
|
||||
}
|
||||
|
@ -1290,7 +1290,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// permissions
|
||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, doc.LabelID)
|
||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, doc.SpaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
|
@ -1344,7 +1344,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
d.Page = p
|
||||
|
||||
for _, m := range meta {
|
||||
if p.RefID == m.PageID {
|
||||
if p.RefID == m.SectionID {
|
||||
d.Meta = m
|
||||
break
|
||||
}
|
||||
|
@ -1359,7 +1359,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
ud.Page = up
|
||||
|
||||
for _, m := range meta {
|
||||
if up.RefID == m.PageID {
|
||||
if up.RefID == m.SectionID {
|
||||
ud.Meta = m
|
||||
break
|
||||
}
|
||||
|
@ -1413,7 +1413,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
|||
h.Runtime.Log.Error(method, err)
|
||||
} else {
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SpaceID: doc.SpaceID,
|
||||
DocumentID: doc.RefID,
|
||||
Metadata: source, // deliberate
|
||||
SourceType: activity.SourceTypeSearch, // deliberate
|
||||
|
@ -1450,7 +1450,7 @@ func (h *Handler) workflowPermitsChange(doc dm.Document, ctx domain.RequestConte
|
|||
|
||||
// If approval workflow then only approvers can delete page
|
||||
if doc.Protection == workflow.ProtectionReview {
|
||||
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.LabelID, doc.RefID, pm.DocumentApprove)
|
||||
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.SpaceID, doc.RefID, pm.DocumentApprove)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("workflowAllowsChange", err)
|
||||
return false, err
|
||||
|
|
|
@ -58,10 +58,10 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
|||
}
|
||||
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section (c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_name, c_body, c_revisions, c_sequence, c_templateid, c_status, c_relativeid, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.PageType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.BlockID, model.Page.Status, model.Page.RelativeID, model.Page.Created, model.Page.Revised)
|
||||
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.Type, model.Page.Level, model.Page.Name, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.TemplateID, model.Page.Status, model.Page.RelativeID, model.Page.Created, model.Page.Revised)
|
||||
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section_meta (c_sectionid, c_orgid, c_userid, c_docid, c_rawbody, c_config, c_external, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
model.Meta.PageID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
||||
model.Meta.SectionID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute page meta insert")
|
||||
|
@ -73,7 +73,9 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
|||
// Get returns the pageID page record from the page table.
|
||||
func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err error) {
|
||||
err = s.Runtime.Db.Get(&p, `
|
||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section
|
||||
WHERE c_orgid=? AND c_refid=?`,
|
||||
ctx.OrgID, pageID)
|
||||
|
@ -88,7 +90,9 @@ func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err e
|
|||
// GetPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||
func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||
err = s.Runtime.Db.Select(&p, `
|
||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section
|
||||
WHERE c_orgid=? AND c_docid=? AND (c_status=0 OR ((c_status=4 OR c_status=2) AND c_relativeid=''))
|
||||
ORDER BY c_sequence`,
|
||||
|
@ -104,7 +108,9 @@ func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.
|
|||
// GetUnpublishedPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||
func (s Scope) GetUnpublishedPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||
err = s.Runtime.Db.Select(&p, `
|
||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section
|
||||
WHERE c_orgid=? AND c_docid=? AND c_status!=0 AND c_relativeid!=''
|
||||
ORDER BY c_sequence`,
|
||||
|
@ -121,7 +127,9 @@ func (s Scope) GetUnpublishedPages(ctx domain.RequestContext, documentID string)
|
|||
// but without the body field (which holds the HTML content).
|
||||
func (s Scope) GetPagesWithoutContent(ctx domain.RequestContext, documentID string) (pages []page.Page, err error) {
|
||||
err = s.Runtime.Db.Select(&pages, `
|
||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||
c_level AS level, c_sequence AS sequence, c_name AS name, c_revisions AS revisions, c_templateid AS templateid,
|
||||
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||
FROM dmz_section
|
||||
WHERE c_orgid=? AND c_docid=? AND c_status=0
|
||||
ORDER BY c_sequence`,
|
||||
|
@ -145,9 +153,9 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
|||
INSERT INTO dmz_section_revision
|
||||
(c_refid, c_orgid, c_docid, c_ownerid, c_sectionid, c_userid, c_contenttype, c_type,
|
||||
c_name, c_body, c_rawbody, c_config, c_created, c_revised)
|
||||
SELECT ? as refid, a.c_orgid, a.c_docid, a.c_userid as ownerid, a.c_refid as sectionid,
|
||||
? as userid, a.c_contenttype, a.c_type, a.c_name, a.c_body,
|
||||
b.c_rawbody, b.c_config, ? as c_created, ? as c_revised
|
||||
SELECT ? AS refid, a.c_orgid, a.c_docid, a.c_userid AS ownerid, a.c_refid AS sectionid,
|
||||
? AS userid, a.c_contenttype, a.c_type, a.c_name, a.c_body,
|
||||
b.c_rawbody, b.c_config, ? AS c_created, ? As c_revised
|
||||
FROM dmz_section a, dmz_section_meta b
|
||||
WHERE a.c_refid=? AND a.c_refid=b.c_sectionid`,
|
||||
refID, userID, time.Now().UTC(), time.Now().UTC(), page.RefID)
|
||||
|
@ -160,10 +168,10 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
|||
|
||||
// Update page
|
||||
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_section SET
|
||||
docid=:documentid, level=:level, c_name=:name, body=:body,
|
||||
c_docid=:documentid, c_level=:level, c_name=:name, c_body=:body,
|
||||
c_revisions=:revisions, c_sequence=:sequence, c_status=:status,
|
||||
c_relativeid=:relativeid, c_revised=:revised
|
||||
WHERE orgid=:orgid AND refid=:refid`,
|
||||
WHERE c_orgid=:orgid AND c_refid=:refid`,
|
||||
&page)
|
||||
|
||||
if err != nil {
|
||||
|
@ -347,7 +355,7 @@ func (s Scope) GetPageRevision(ctx domain.RequestContext, revisionID string) (re
|
|||
// GetPageRevisions returns a slice of page revision records for a given pageID, in the order they were created.
|
||||
// Then audits that the get-page-revisions action has occurred.
|
||||
func (s Scope) GetPageRevisions(ctx domain.RequestContext, pageID string) (revisions []page.Revision, err error) {
|
||||
err = s.Runtime.Db.Select(&revisions, `SELECT a.c_id, a.c_refid AS refid,
|
||||
err = s.Runtime.Db.Select(&revisions, `SELECT a.id, a.c_refid AS refid,
|
||||
a.c_orgid AS orgid, a.c_docid AS documentid, a.c_ownerid AS ownerid, a.c_sectionid AS sectionid, a.c_userid AS userid,
|
||||
a.c_contenttype AS contenttype, a.c_type AS type, a.c_name AS name,
|
||||
a.c_created AS created, a.c_revised AS revised,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue