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
|
@ -100,7 +100,7 @@ func CopyDocument(ctx domain.RequestContext, s domain.Store, documentID string)
|
|||
|
||||
pageID := uniqueid.Generate()
|
||||
p.RefID = pageID
|
||||
meta.PageID = pageID
|
||||
meta.SectionID = pageID
|
||||
meta.DocumentID = newDocumentID
|
||||
|
||||
m := page.NewPage{}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) {
|
||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: document.LabelID,
|
||||
SpaceID: document.SpaceID,
|
||||
DocumentID: document.RefID,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypeRead})
|
||||
|
@ -166,7 +166,7 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Sort by title.
|
||||
sort.Sort(doc.ByTitle(documents))
|
||||
sort.Sort(doc.ByName(documents))
|
||||
|
||||
// Remove documents that cannot be seen due to lack of
|
||||
// category view/access permission.
|
||||
|
@ -231,9 +231,9 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if oldDoc.LabelID != d.LabelID {
|
||||
if oldDoc.SpaceID != d.SpaceID {
|
||||
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
|
||||
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.LabelID, d.LabelID)
|
||||
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.SpaceID, d.SpaceID)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
|
@ -268,7 +268,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
// Record document being marked as archived.
|
||||
if d.Lifecycle == workflow.LifecycleArchived {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: d.LabelID,
|
||||
SpaceID: d.SpaceID,
|
||||
DocumentID: documentID,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypeArchived})
|
||||
|
@ -277,7 +277,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
// Record document being marked as draft.
|
||||
if d.Lifecycle == workflow.LifecycleDraft {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: d.LabelID,
|
||||
SpaceID: d.SpaceID,
|
||||
DocumentID: documentID,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypeDraft})
|
||||
|
@ -286,7 +286,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
// Record document being marked as live.
|
||||
if d.Lifecycle == workflow.LifecycleLive {
|
||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: d.LabelID,
|
||||
SpaceID: d.SpaceID,
|
||||
DocumentID: documentID,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypePublished})
|
||||
|
@ -340,7 +340,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// 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 {
|
||||
response.WriteForbiddenError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
|
@ -389,7 +389,7 @@ 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,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypeDeleted})
|
||||
|
@ -458,7 +458,7 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: "",
|
||||
SpaceID: "",
|
||||
DocumentID: "",
|
||||
Metadata: options.Keywords,
|
||||
SourceType: activity.SourceTypeSearch,
|
||||
|
@ -504,7 +504,7 @@ func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.Que
|
|||
|
||||
if _, isExisting := prev[q[i].DocumentID]; !isExisting {
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: q[i].SpaceID,
|
||||
SpaceID: q[i].SpaceID,
|
||||
DocumentID: q[i].DocumentID,
|
||||
Metadata: keywords,
|
||||
SourceType: activity.SourceTypeSearch,
|
||||
|
@ -545,7 +545,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) {
|
||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
@ -557,9 +557,10 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// permissions
|
||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.LabelID)
|
||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if len(perms) == 0 {
|
||||
|
@ -570,6 +571,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
roles, err := h.Store.Permission.GetUserDocumentPermissions(ctx, document.RefID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if len(roles) == 0 {
|
||||
|
@ -629,7 +631,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if document.Lifecycle == workflow.LifecycleLive {
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
LabelID: document.LabelID,
|
||||
SpaceID: document.SpaceID,
|
||||
DocumentID: document.RefID,
|
||||
SourceType: activity.SourceTypeDocument,
|
||||
ActivityType: activity.TypeRead})
|
||||
|
|
|
@ -153,7 +153,7 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
|||
for _, d := range docs {
|
||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||
if e == nil && len(docHTML) > 0 {
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||
b.WriteString(docHTML)
|
||||
} else {
|
||||
return toc, b.String(), err
|
||||
|
@ -221,7 +221,7 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
|||
for _, d := range exportDocs {
|
||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||
if e == nil && len(docHTML) > 0 {
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||
b.WriteString(docHTML)
|
||||
} else {
|
||||
return toc, b.String(), err
|
||||
|
@ -274,7 +274,7 @@ func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, d
|
|||
if permission.CanViewDocument(ctx, s, d.RefID) {
|
||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||
if e == nil && len(docHTML) > 0 {
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||
b.WriteString(docHTML)
|
||||
} else {
|
||||
return toc, b.String(), err
|
||||
|
@ -325,7 +325,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
|||
// Put out document name.
|
||||
b.WriteString(fmt.Sprintf("<div class='export-doc-header' id='%s'>", doc.RefID))
|
||||
b.WriteString("<div class='export-doc-title'>")
|
||||
b.WriteString(doc.Title)
|
||||
b.WriteString(doc.Name)
|
||||
b.WriteString("</div>")
|
||||
b.WriteString("<div class='export-doc-excerpt'>")
|
||||
b.WriteString(doc.Excerpt)
|
||||
|
@ -338,7 +338,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
|||
b.WriteString(`<div class="document-structure">`)
|
||||
b.WriteString(`<div class="page-header">`)
|
||||
b.WriteString(fmt.Sprintf("<span class='page-number'>%s</span>", page.Numbering))
|
||||
b.WriteString(fmt.Sprintf("<span class='page-title'>%s</span>", page.Title))
|
||||
b.WriteString(fmt.Sprintf("<span class='page-title'>%s</span>", page.Name))
|
||||
b.WriteString("</div>")
|
||||
b.WriteString("</div>")
|
||||
|
||||
|
|
|
@ -119,15 +119,16 @@ func (s Scope) 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=0 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'
|
||||
UNION ALL
|
||||
SELECT p.c_refid from permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=?
|
||||
AND p.c_who='role' AND p.c_location='space' AND p.c_refid=? AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
||||
SELECT p.c_refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=?
|
||||
AND p.c_who='role' AND p.c_location='space' AND p.c_refid=? AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0')
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
ORDER BY c_name, c_versionorder`,
|
||||
ctx.OrgID, ctx.OrgID, ctx.OrgID, spaceID, ctx.OrgID, ctx.UserID, ctx.OrgID, spaceID, ctx.UserID)
|
||||
|
||||
|
@ -154,9 +155,9 @@ func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu
|
|||
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
|
||||
(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'
|
||||
(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'
|
||||
UNION ALL
|
||||
SELECT p.refid from permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
||||
SELECT p.c_refid FROM dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
||||
)
|
||||
)
|
||||
ORDER BY c_name`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
||||
|
@ -311,23 +312,23 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64,
|
|||
// Remove document pages, revisions, attachments, updates the search subsystem.
|
||||
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section WHERE _cdocid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section_revision WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section_revision WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_attachment WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_attachment WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_vote WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_vote WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -346,7 +347,7 @@ func (s Scope) GetVersions(ctx domain.RequestContext, groupID string) (v []doc.V
|
|||
v = []doc.Version{}
|
||||
|
||||
err = s.Runtime.Db.Select(&v, `
|
||||
SELECT versionid, refid as documentid
|
||||
SELECT c_versionid AS versionid, c_refid as documentid
|
||||
FROM dmz_doc
|
||||
WHERE c_orgid=? AND c_groupid=?
|
||||
ORDER BY c_versionorder`, ctx.OrgID, groupID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue