mirror of
https://github.com/documize/community.git
synced 2025-08-09 15:35:27 +02:00
removed page revisions code references!
This commit is contained in:
parent
bb9ac592d9
commit
f9a9b659c9
3 changed files with 0 additions and 303 deletions
|
@ -584,246 +584,6 @@ func ChangeDocumentPageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
writeSuccessEmptyJSON(w)
|
||||
}
|
||||
|
||||
// // GetDocumentPageRevisions returns all changes for a given page.
|
||||
// func GetDocumentPageRevisions(w http.ResponseWriter, r *http.Request) {
|
||||
// method := "GetDocumentPageRevisions"
|
||||
// p := request.GetPersister(r)
|
||||
|
||||
// params := mux.Vars(r)
|
||||
// documentID := params["documentID"]
|
||||
|
||||
// if len(documentID) == 0 {
|
||||
// writeMissingDataError(w, method, "documentID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// if !p.CanViewDocument(documentID) {
|
||||
// writeForbiddenError(w)
|
||||
// return
|
||||
// }
|
||||
|
||||
// pageID := params["pageID"]
|
||||
|
||||
// if len(pageID) == 0 {
|
||||
// writeMissingDataError(w, method, "pageID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// revisions, err := p.GetPageRevisions(pageID)
|
||||
|
||||
// payload, err := json.Marshal(revisions)
|
||||
|
||||
// if err != nil {
|
||||
// writeJSONMarshalError(w, method, "revision", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// writeSuccessBytes(w, payload)
|
||||
// }
|
||||
|
||||
// // GetDocumentPageDiff returns HTML diff between two revisions of a given page.
|
||||
// func GetDocumentPageDiff(w http.ResponseWriter, r *http.Request) {
|
||||
// method := "GetDocumentPageDiff"
|
||||
// p := request.GetPersister(r)
|
||||
|
||||
// params := mux.Vars(r)
|
||||
// documentID := params["documentID"]
|
||||
|
||||
// if len(documentID) == 0 {
|
||||
// writeMissingDataError(w, method, "documentID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// if !p.CanViewDocument(documentID) {
|
||||
// writeForbiddenError(w)
|
||||
// return
|
||||
// }
|
||||
|
||||
// pageID := params["pageID"]
|
||||
|
||||
// if len(pageID) == 0 {
|
||||
// writeMissingDataError(w, method, "pageID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// revisionID := params["revisionID"]
|
||||
|
||||
// if len(revisionID) == 0 {
|
||||
// writeMissingDataError(w, method, "revisionID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// page, err := p.GetPage(pageID)
|
||||
|
||||
// if err == sql.ErrNoRows {
|
||||
// writeNotFoundError(w, method, revisionID)
|
||||
// return
|
||||
// }
|
||||
|
||||
// revision, err := p.GetPageRevision(revisionID)
|
||||
|
||||
// latestHTML := page.Body
|
||||
// previousHTML := revision.Body
|
||||
// var result []byte
|
||||
// if false { // use daisydiff ?
|
||||
|
||||
// // generate folder name
|
||||
// guid, err := uuid.NewV4()
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// var folder = "_diffs" + string(os.PathSeparator) + guid.String() + string(os.PathSeparator)
|
||||
|
||||
// err = os.MkdirAll(folder, os.ModePerm)
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Save latest version of page as html
|
||||
// err = ioutil.WriteFile(folder+"latest.html", []byte(latestHTML), 0666)
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Save other version of page as html
|
||||
// err = ioutil.WriteFile(folder+"previous.html", []byte(previousHTML), 0666)
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Now run DaisyDiff
|
||||
// command := exec.Command("java", "-jar", "daisydiff-documize.jar", folder+"latest.html", folder+"previous.html", "--file="+folder+"diff.html")
|
||||
|
||||
// _, err = utility.CommandWithTimeout(command, 90*time.Second)
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // Read in diff result
|
||||
// result, err = ioutil.ReadFile(folder + "diff.html")
|
||||
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// } else { // use html-diff
|
||||
|
||||
// //fmt.Printf("previousHTML=`%s`\nlatestHTML=`%s`\n", previousHTML, latestHTML)
|
||||
|
||||
// var cfg = &htmldiff.Config{
|
||||
// Granularity: 5,
|
||||
// InsertedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: palegreen;"}},
|
||||
// DeletedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightpink; text-decoration: line-through;"}},
|
||||
// ReplacedSpan: []htmldiff.Attribute{{Key: "style", Val: "background-color: lightskyblue;"}},
|
||||
// CleanTags: []string{"documize"},
|
||||
// }
|
||||
// res, err := cfg.HTMLdiff([]string{latestHTML, previousHTML})
|
||||
// if err != nil {
|
||||
// writeServerError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
// result = []byte(res[0])
|
||||
|
||||
// }
|
||||
|
||||
// _, err = w.Write(result)
|
||||
// log.IfErr(err)
|
||||
// }
|
||||
|
||||
// // RollbackDocumentPage rolls-back to a specific page revision.
|
||||
// func RollbackDocumentPage(w http.ResponseWriter, r *http.Request) {
|
||||
// method := "RollbackDocumentPage"
|
||||
// p := request.GetPersister(r)
|
||||
|
||||
// params := mux.Vars(r)
|
||||
// documentID := params["documentID"]
|
||||
|
||||
// if len(documentID) == 0 {
|
||||
// writeMissingDataError(w, method, "documentID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// pageID := params["pageID"]
|
||||
|
||||
// if len(pageID) == 0 {
|
||||
// writeMissingDataError(w, method, "pageID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// revisionID := params["revisionID"]
|
||||
|
||||
// if len(revisionID) == 0 {
|
||||
// writeMissingDataError(w, method, "revisionID")
|
||||
// return
|
||||
// }
|
||||
|
||||
// if !p.CanChangeDocument(documentID) {
|
||||
// writeForbiddenError(w)
|
||||
// return
|
||||
// }
|
||||
|
||||
// tx, err := request.Db.Beginx()
|
||||
|
||||
// if err != nil {
|
||||
// writeTransactionError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// p.Context.Transaction = tx
|
||||
|
||||
// // fetch page
|
||||
// page, err := p.GetPage(pageID)
|
||||
|
||||
// if err != nil {
|
||||
// writeGeneralSQLError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // fetch revision
|
||||
// revision, err := p.GetPageRevision(revisionID)
|
||||
|
||||
// if err != nil {
|
||||
// log.IfErr(tx.Rollback())
|
||||
// writeGeneralSQLError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // roll back
|
||||
// page.Body = revision.Body
|
||||
|
||||
// refID := util.UniqueID()
|
||||
// err = p.UpdatePage(page, refID, p.Context.UserID, false)
|
||||
|
||||
// if err != nil {
|
||||
// log.IfErr(tx.Rollback())
|
||||
// writeGeneralSQLError(w, method, err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// log.IfErr(tx.Commit())
|
||||
|
||||
// payload, err := json.Marshal(page)
|
||||
|
||||
// if err != nil {
|
||||
// writeJSONMarshalError(w, method, "revision", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// writeSuccessBytes(w, payload)
|
||||
// }
|
||||
|
||||
// GetDocumentPageMeta gets page meta data for specified document page.
|
||||
func GetDocumentPageMeta(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetDocumentPageMeta"
|
||||
|
|
|
@ -218,22 +218,6 @@ func (p *PageMeta) SetDefaults() {
|
|||
}
|
||||
}
|
||||
|
||||
// Revision holds the previous version of a Page.
|
||||
type Revision struct {
|
||||
BaseEntity
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
PageID string `json:"pageId"`
|
||||
UserID string `json:"userId"`
|
||||
ContentType string `json:"contentType"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Email string `json:"email"`
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
Initials string `json:"initials"`
|
||||
}
|
||||
|
||||
// DocumentMeta details who viewed the document.
|
||||
type DocumentMeta struct {
|
||||
Viewers []DocumentMetaViewer `json:"viewers"`
|
||||
|
|
|
@ -372,7 +372,6 @@ func (p *Persister) DeletePage(documentID, pageID string) (rows int64, err error
|
|||
if err == nil {
|
||||
_, err = p.Base.DeleteWhere(p.Context.Transaction, fmt.Sprintf("DELETE FROM pagemeta WHERE orgid='%s' AND pageid='%s'", p.Context.OrgID, pageID))
|
||||
_, err = searches.Delete(&databaseRequest{OrgID: p.Context.OrgID}, documentID, pageID)
|
||||
_, err = p.DeletePageRevisions(pageID)
|
||||
|
||||
p.Base.Audit(p.Context, "remove-page", documentID, pageID)
|
||||
}
|
||||
|
@ -419,49 +418,3 @@ func (p *Persister) GetDocumentPageMeta(documentID string, externalSourceOnly bo
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
/********************
|
||||
* Page Revisions
|
||||
********************/
|
||||
|
||||
// GetPageRevision returns the revisionID page revision record.
|
||||
func (p *Persister) GetPageRevision(revisionID string) (revision entity.Revision, err error) {
|
||||
stmt, err := Db.Preparex("SELECT id, refid, orgid, documentid, pageid, userid, contenttype, title, body, created, revised FROM revision WHERE orgid=? and refid=?")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to prepare select for revision %s", revisionID), err)
|
||||
return
|
||||
}
|
||||
|
||||
err = stmt.Get(&revision, p.Context.OrgID, revisionID)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to execute select for revision %s", revisionID), err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 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 (p *Persister) GetPageRevisions(pageID string) (revisions []entity.Revision, err error) {
|
||||
err = Db.Select(&revisions, "SELECT a.id,a.refid,a.orgid,a.documentid,a.pageid,a.userid,a.contenttype,a.body,a.created,a.revised,coalesce(b.email,'') as email,coalesce(b.firstname,'') as firstname, coalesce(b.lastname,'') as lastname, coalesce(b.initials,'') as initials FROM revision a LEFT JOIN user b ON a.userid=b.refid WHERE a.orgid=? AND a.pageid=? ORDER BY a.id DESC", p.Context.OrgID, pageID)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to execute select revisions for org %s and page %s", p.Context.OrgID, pageID), err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Base.Audit(p.Context, "get-page-revisions", "", pageID)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeletePageRevisions deletes all of the page revision records for a given pageID.
|
||||
func (p *Persister) DeletePageRevisions(pageID string) (rows int64, err error) {
|
||||
rows, err = p.Base.DeleteWhere(p.Context.Transaction, fmt.Sprintf("DELETE FROM revision WHERE orgid='%s' AND pageid='%s'", p.Context.OrgID, pageID))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue