mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
implemented copy page facility
This commit is contained in:
parent
fc9127e165
commit
07ee2248d4
11 changed files with 269 additions and 18 deletions
|
@ -669,9 +669,38 @@ func GetDocumentPageMeta(w http.ResponseWriter, r *http.Request) {
|
|||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
/********************
|
||||
* Page Revisions
|
||||
********************/
|
||||
// GetPageMoveCopyTargets returns available documents for page copy/move axction.
|
||||
func GetPageMoveCopyTargets(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetPageMoveCopyTargets"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
var d []entity.Document
|
||||
var err error
|
||||
|
||||
d, err = p.GetDocumentList()
|
||||
|
||||
if len(d) == 0 {
|
||||
d = []entity.Document{}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(d)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "document", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
//**************************************************
|
||||
// Page Revisions
|
||||
//**************************************************
|
||||
|
||||
// GetDocumentRevisions returns all changes for a document.
|
||||
func GetDocumentRevisions(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -897,3 +926,102 @@ func RollbackDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
writeSuccessBytes(w, payload)
|
||||
}
|
||||
|
||||
//**************************************************
|
||||
// Copy Move Page
|
||||
//**************************************************
|
||||
|
||||
// CopyPage copies page to either same or different document.
|
||||
func CopyPage(w http.ResponseWriter, r *http.Request) {
|
||||
method := "CopyPage"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
documentID := params["documentID"]
|
||||
pageID := params["pageID"]
|
||||
targetID := params["targetID"]
|
||||
|
||||
// data checks
|
||||
if len(documentID) == 0 {
|
||||
writeMissingDataError(w, method, "documentID")
|
||||
return
|
||||
}
|
||||
if len(pageID) == 0 {
|
||||
writeMissingDataError(w, method, "pageID")
|
||||
return
|
||||
}
|
||||
if len(targetID) == 0 {
|
||||
writeMissingDataError(w, method, "targetID")
|
||||
return
|
||||
}
|
||||
|
||||
// permission
|
||||
if !p.CanViewDocument(documentID) {
|
||||
writeForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
// fetch data
|
||||
page, err := p.GetPage(pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
writeNotFoundError(w, method, documentID)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
pageMeta, err := p.GetPageMeta(pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
writeNotFoundError(w, method, documentID)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
newPageID := util.UniqueID()
|
||||
page.RefID = newPageID
|
||||
page.Level = 1
|
||||
page.DocumentID = targetID
|
||||
page.UserID = p.Context.UserID
|
||||
pageMeta.DocumentID = targetID
|
||||
pageMeta.PageID = newPageID
|
||||
pageMeta.UserID = p.Context.UserID
|
||||
|
||||
model := new(models.PageModel)
|
||||
model.Meta = pageMeta
|
||||
model.Page = page
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
p.Context.Transaction = tx
|
||||
|
||||
err = p.AddPage(*model)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(model.Page.BlockID) > 0 {
|
||||
p.IncrementBlockUsage(model.Page.BlockID)
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
newPage, _ := p.GetPage(pageID)
|
||||
json, err := json.Marshal(newPage)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "page", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
|
|
@ -127,8 +127,9 @@ func buildRoutes(prefix string) *mux.Router {
|
|||
}
|
||||
|
||||
func init() {
|
||||
|
||||
// **** add Unsecure Routes
|
||||
//**************************************************
|
||||
// Non-secure routes
|
||||
//**************************************************
|
||||
|
||||
log.IfErr(Add(RoutePrefixPublic, "meta", []string{"GET", "OPTIONS"}, nil, GetMeta))
|
||||
log.IfErr(Add(RoutePrefixPublic, "authenticate", []string{"POST", "OPTIONS"}, nil, Authenticate))
|
||||
|
@ -139,7 +140,9 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPublic, "attachments/{orgID}/{attachmentID}", []string{"GET", "OPTIONS"}, nil, AttachmentDownload))
|
||||
log.IfErr(Add(RoutePrefixPublic, "version", []string{"GET", "OPTIONS"}, nil, version))
|
||||
|
||||
// **** add secure routes
|
||||
//**************************************************
|
||||
// Secure routes
|
||||
//**************************************************
|
||||
|
||||
// Import & Convert Document
|
||||
log.IfErr(Add(RoutePrefixPrivate, "import/folder/{folderID}", []string{"POST", "OPTIONS"}, nil, UploadConvertDocument))
|
||||
|
@ -151,8 +154,6 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}", []string{"GET", "OPTIONS"}, nil, GetDocument))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}", []string{"PUT", "OPTIONS"}, nil, UpdateDocument))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}", []string{"DELETE", "OPTIONS"}, nil, DeleteDocument))
|
||||
|
||||
// Document Meta
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/meta", []string{"GET", "OPTIONS"}, nil, GetDocumentMeta))
|
||||
|
||||
// Document Page
|
||||
|
@ -173,9 +174,8 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/attachments", []string{"GET", "OPTIONS"}, nil, GetAttachments))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/attachments/{attachmentID}", []string{"DELETE", "OPTIONS"}, nil, DeleteAttachment))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/attachments", []string{"POST", "OPTIONS"}, nil, AddAttachments))
|
||||
|
||||
// Document Page Meta
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/meta", []string{"GET", "OPTIONS"}, nil, GetDocumentPageMeta))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/pages/{pageID}/copy/{targetID}", []string{"POST", "OPTIONS"}, nil, CopyPage))
|
||||
|
||||
// Organization
|
||||
log.IfErr(Add(RoutePrefixPrivate, "organizations/{orgID}", []string{"GET", "OPTIONS"}, nil, GetOrganization))
|
||||
|
@ -221,6 +221,7 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"PUT", "OPTIONS"}, nil, UpdateBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"DELETE", "OPTIONS"}, nil, DeleteBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks", []string{"POST", "OPTIONS"}, nil, AddBlock))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "sections/targets", []string{"GET", "OPTIONS"}, nil, GetPageMoveCopyTargets))
|
||||
|
||||
// Links
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links/{folderID}/{documentID}/{pageID}", []string{"GET", "OPTIONS"}, nil, GetLinkCandidates))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue