MCPcopy Index your code
hub / github.com/TruthHun/BookStack / SaveSort

Method SaveSort

controllers/BookController.go:864–915  ·  view source on GitHub ↗

文档排序.

()

Source from the content-addressed store, hash-verified

862
863// 文档排序.
864func (this *BookController) SaveSort() {
865
866 identify := this.Ctx.Input.Param(":key")
867 if identify == "" {
868 this.Abort("404")
869 }
870
871 bookId := 0
872 if this.Member.IsAdministrator() {
873 book, err := models.NewBook().FindByFieldFirst("identify", identify)
874 if err != nil {
875 beego.Error(err)
876 }
877 bookId = book.BookId
878 } else {
879 bookResult, err := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId)
880 if err != nil {
881 beego.Error("DocumentController.Edit => ", err)
882 this.Abort("404")
883 }
884
885 if bookResult.RoleId == conf.BookObserver {
886 this.JsonResult(6002, "书籍不存在或权限不足")
887 }
888 bookId = bookResult.BookId
889 }
890
891 content := this.Ctx.Input.RequestBody
892
893 var docs []struct {
894 Id int `json:"id"`
895 Sort int `json:"sort"`
896 Parent int `json:"parent"`
897 }
898
899 err := json.Unmarshal(content, &docs)
900 if err != nil {
901 beego.Error(err)
902 this.JsonResult(6003, "数据错误")
903 }
904
905 qs := orm.NewOrm().QueryTable("md_documents").Filter("book_id", bookId)
906 now := time.Now()
907 for _, item := range docs {
908 qs.Filter("document_id", item.Id).Update(orm.Params{
909 "parent_id": item.Parent,
910 "order_sort": item.Sort,
911 "modify_time": now,
912 })
913 }
914 this.JsonResult(0, "ok")
915}
916
917// 判断是否具有管理员或管理员以上权限
918func (this *BookController) IsPermission() (*models.BookResult, error) {

Callers

nothing calls this directly

Calls 7

NewBookFunction · 0.92
NewBookResultFunction · 0.92
IsAdministratorMethod · 0.80
JsonResultMethod · 0.80
FindByFieldFirstMethod · 0.45
FindByIdentifyMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected