mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
wip
This commit is contained in:
parent
33a66c87cf
commit
7c34053e3d
25 changed files with 4884 additions and 3729 deletions
|
@ -62,19 +62,15 @@ func uploadDocument(w http.ResponseWriter, r *http.Request) (string, string, str
|
|||
}
|
||||
|
||||
// generate job id
|
||||
var job = "some-uuid"
|
||||
|
||||
newUUID, err := uuid.NewV4()
|
||||
|
||||
if err != nil {
|
||||
writeServerError(w, method, err)
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
job = newUUID.String()
|
||||
job := newUUID.String()
|
||||
|
||||
err = storageProvider.Upload(job, filename.Filename, b.Bytes())
|
||||
|
||||
if err != nil {
|
||||
writeServerError(w, method, err)
|
||||
return "", "", ""
|
||||
|
@ -229,10 +225,7 @@ func processDocument(p request.Persister, filename, job, folderID string, fileRe
|
|||
return
|
||||
}
|
||||
|
||||
// New code from normal conversion code
|
||||
|
||||
tx, err = request.Db.Beginx()
|
||||
|
||||
if err != nil {
|
||||
log.Error("Cannot begin a transatcion", err)
|
||||
return
|
||||
|
@ -248,9 +241,13 @@ func processDocument(p request.Persister, filename, job, folderID string, fileRe
|
|||
return
|
||||
}
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: newDocument.LabelID,
|
||||
SourceID: newDocument.RefID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeCreated})
|
||||
|
||||
// End new code
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -98,12 +98,31 @@ func GetDocument(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
json, err := json.Marshal(document)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "document", err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction, err = request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: document.LabelID,
|
||||
SourceID: document.RefID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeRead})
|
||||
|
||||
if err != nil {
|
||||
log.IfErr(p.Context.Transaction.Rollback())
|
||||
log.Error("Cannot record user activity", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.IfErr(p.Context.Transaction.Commit())
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
|
@ -259,8 +278,13 @@ func DeleteDocument(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
|
@ -284,6 +308,12 @@ func DeleteDocument(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: documentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeDeleted})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
|
@ -404,7 +434,6 @@ func UpdateDocument(w http.ResponseWriter, r *http.Request) {
|
|||
d.RefID = documentID
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
|
@ -413,7 +442,6 @@ func UpdateDocument(w http.ResponseWriter, r *http.Request) {
|
|||
p.Context.Transaction = tx
|
||||
|
||||
err = p.UpdateDocument(d)
|
||||
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
|
|
|
@ -68,8 +68,8 @@ func AddFolder(w http.ResponseWriter, r *http.Request) {
|
|||
id := util.UniqueID()
|
||||
folder.RefID = id
|
||||
folder.OrgID = p.Context.OrgID
|
||||
err = addFolder(p, &folder)
|
||||
|
||||
err = addFolder(p, &folder)
|
||||
if err != nil {
|
||||
log.IfErr(tx.Rollback())
|
||||
writeGeneralSQLError(w, method, err)
|
||||
|
@ -78,10 +78,9 @@ func AddFolder(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
folder, err = p.GetLabel(id)
|
||||
folder, _ = p.GetLabel(id)
|
||||
|
||||
json, err := json.Marshal(folder)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "folder", err)
|
||||
return
|
||||
|
|
|
@ -84,6 +84,12 @@ func AddDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
model.Meta.SetDefaults()
|
||||
// page.Title = template.HTMLEscapeString(page.Title)
|
||||
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
|
@ -110,12 +116,17 @@ func AddDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
p.IncrementBlockUsage(model.Page.BlockID)
|
||||
}
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: model.Page.DocumentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeCreated})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
newPage, _ := p.GetPage(pageID)
|
||||
|
||||
json, err := json.Marshal(newPage)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "page", err)
|
||||
return
|
||||
|
@ -265,7 +276,6 @@ func GetDocumentPagesBatch(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
json, err := json.Marshal(pages)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "document", err)
|
||||
return
|
||||
|
@ -299,13 +309,17 @@ func DeleteDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
page, err := p.GetPage(pageID)
|
||||
|
@ -327,6 +341,12 @@ func DeleteDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: documentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeDeleted})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
|
@ -352,7 +372,6 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
defer utility.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
writeBadRequestError(w, method, "Bad body")
|
||||
return
|
||||
|
@ -366,13 +385,17 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
for _, page := range *model {
|
||||
|
@ -395,6 +418,12 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: documentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeDeleted})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
writeSuccessEmptyJSON(w)
|
||||
|
@ -406,22 +435,20 @@ func DeleteDocumentPages(w http.ResponseWriter, r *http.Request) {
|
|||
func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
||||
method := "UpdateDocumentPage"
|
||||
p := request.GetPersister(r)
|
||||
params := mux.Vars(r)
|
||||
|
||||
if !p.Context.Editor {
|
||||
writeForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -429,7 +456,6 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
defer utility.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
|
||||
if err != nil {
|
||||
writeBadRequestError(w, method, "Bad request body")
|
||||
return
|
||||
|
@ -437,7 +463,6 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
model := new(models.PageModel)
|
||||
err = json.Unmarshal(body, &model)
|
||||
|
||||
if err != nil {
|
||||
writePayloadError(w, method, err)
|
||||
return
|
||||
|
@ -448,8 +473,13 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
writeTransactionError(w, method, err)
|
||||
return
|
||||
|
@ -488,6 +518,12 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
err = p.UpdatePageMeta(model.Meta, true) // change the UserID to the current one
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: model.Page.DocumentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeEdited})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
updatedPage, err := p.GetPage(pageID)
|
||||
|
@ -894,6 +930,13 @@ func RollbackDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// fetch doc
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// roll back page
|
||||
page.Body = revision.Body
|
||||
refID := util.UniqueID()
|
||||
|
@ -916,6 +959,12 @@ func RollbackDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: page.DocumentID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeReverted})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
payload, err := json.Marshal(page)
|
||||
|
@ -962,6 +1011,12 @@ func CopyPage(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// fetch data
|
||||
doc, err := p.GetDocument(documentID)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
page, err := p.GetPage(pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
writeNotFoundError(w, method, documentID)
|
||||
|
@ -1013,6 +1068,13 @@ func CopyPage(w http.ResponseWriter, r *http.Request) {
|
|||
p.IncrementBlockUsage(model.Page.BlockID)
|
||||
}
|
||||
|
||||
// Log action against target document
|
||||
_ = p.RecordUserActivity(entity.UserActivity{
|
||||
LabelID: doc.LabelID,
|
||||
SourceID: targetID,
|
||||
SourceType: entity.ActivitySourceTypeDocument,
|
||||
ActivityType: entity.ActivityTypeEdited})
|
||||
|
||||
log.IfErr(tx.Commit())
|
||||
|
||||
newPage, _ := p.GetPage(pageID)
|
||||
|
|
|
@ -126,8 +126,7 @@ func SaveAsTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Duplicate attachments
|
||||
attachments, err := p.GetAttachments(model.DocumentID)
|
||||
|
||||
attachments, _ := p.GetAttachments(model.DocumentID)
|
||||
for i, a := range attachments {
|
||||
a.DocumentID = docID
|
||||
a.RefID = util.UniqueID()
|
||||
|
@ -358,8 +357,8 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
pages, err = p.GetPages(templateID)
|
||||
attachments, err = p.GetAttachmentsWithData(templateID)
|
||||
pages, _ = p.GetPages(templateID)
|
||||
attachments, _ = p.GetAttachmentsWithData(templateID)
|
||||
}
|
||||
|
||||
// create new document
|
||||
|
|
|
@ -189,7 +189,6 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
userModel, err = getSecuredUser(p, p.Context.OrgID, userID)
|
||||
|
||||
json, err := json.Marshal(userModel)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "user", err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue