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

Method Copy

controllers/BookController.go:671–709  ·  view source on GitHub ↗

Create 创建书籍.

()

Source from the content-addressed store, hash-verified

669
670// Create 创建书籍.
671func (this *BookController) Copy() {
672 if opt, err := models.NewOption().FindByKey("ALL_CAN_WRITE_BOOK"); err == nil {
673 if opt.OptionValue == "false" && this.Member.Role == conf.MemberGeneralRole { // 读者无权限创建书籍
674 this.JsonResult(1, "普通读者无法创建书籍,如需创建书籍,请向管理员申请成为作者")
675 }
676 }
677 identify := strings.TrimSpace(this.GetString("identify", ""))
678 sourceIdentify := strings.TrimSpace(this.GetString("source_identify", ""))
679 sourceBook, err := models.NewBook().FindByIdentify(sourceIdentify)
680 if err != nil {
681 this.JsonResult(1, err.Error())
682 }
683 existBook, _ := models.NewBook().FindByIdentify(identify, "book_id")
684 if existBook != nil && existBook.BookId > 0 {
685 this.JsonResult(1, "请更换新的书籍标识")
686 }
687
688 // 如果是私有书籍,且不是团队的人,不允许拷贝该项目
689 if sourceBook.PrivatelyOwned == 1 {
690 rel, err := models.NewRelationship().FindByBookIdAndMemberId(sourceBook.BookId, this.Member.MemberId)
691 if err != nil || rel == nil || rel.RelationshipId == 0 {
692 this.JsonResult(1, "无拷贝书籍权限")
693 }
694 }
695 sourceBook.BookId = 0
696 sourceBook.BookName = strings.TrimSpace(this.GetString("book_name", ""))
697 sourceBook.Identify = identify
698 sourceBook.Description = strings.TrimSpace(this.GetString("description", ""))
699 sourceBook.Author = strings.TrimSpace(this.GetString("author", ""))
700 sourceBook.AuthorURL = strings.TrimSpace(this.GetString("author_url", ""))
701 sourceBook.PrivatelyOwned, _ = strconv.Atoi(this.GetString("privately_owned"))
702 sourceBook.MemberId = this.Member.MemberId
703 err = sourceBook.Copy(sourceIdentify)
704 if err != nil {
705 this.JsonResult(1, "拷贝书籍失败:"+err.Error())
706 }
707
708 this.JsonResult(0, "拷贝书籍成功")
709}
710
711// CreateToken 创建访问来令牌.
712func (this *BookController) CreateToken() {

Callers

nothing calls this directly

Calls 7

NewOptionFunction · 0.92
NewBookFunction · 0.92
NewRelationshipFunction · 0.92
FindByKeyMethod · 0.80
JsonResultMethod · 0.80
FindByIdentifyMethod · 0.45

Tested by

no test coverage detected