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

Method PrivatelyOwned

controllers/BookController.go:333–379  ·  view source on GitHub ↗

设置书籍私有状态.

()

Source from the content-addressed store, hash-verified

331
332// 设置书籍私有状态.
333func (this *BookController) PrivatelyOwned() {
334
335 status := this.GetString("status")
336 if this.forbidGeneralRole() && status == "open" {
337 this.JsonResult(6001, "您的角色非作者和管理员,无法将书籍设置为公开")
338 }
339 if status != "open" && status != "close" {
340 this.JsonResult(6003, "参数错误")
341 }
342
343 state := 0
344 if status == "open" {
345 state = 0
346 } else {
347 state = 1
348 }
349
350 bookResult, err := this.IsPermission()
351 if err != nil {
352 this.JsonResult(6001, err.Error())
353 }
354
355 //只有创始人才能变更私有状态
356 if bookResult.RoleId != conf.BookFounder {
357 this.JsonResult(6002, "权限不足")
358 }
359
360 if _, err = orm.NewOrm().QueryTable("md_books").Filter("book_id", bookResult.BookId).Update(orm.Params{
361 "privately_owned": state,
362 }); err != nil {
363 logs.Error("PrivatelyOwned => ", err)
364 this.JsonResult(6004, "保存失败")
365 }
366 go func() {
367 models.CountCategory()
368
369 public := true
370 if state == 1 {
371 public = false
372 }
373 client := models.NewElasticSearchClient()
374 if errSet := client.SetBookPublic(bookResult.BookId, public); errSet != nil && client.On {
375 beego.Error(errSet.Error())
376 }
377 }()
378 this.JsonResult(0, "ok")
379}
380
381// Transfer 转让书籍.
382func (this *BookController) Transfer() {

Callers

nothing calls this directly

Calls 7

IsPermissionMethod · 0.95
SetBookPublicMethod · 0.95
CountCategoryFunction · 0.92
NewElasticSearchClientFunction · 0.92
forbidGeneralRoleMethod · 0.80
JsonResultMethod · 0.80
UpdateMethod · 0.45

Tested by

no test coverage detected