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

Method AddMember

controllers/BookMemberController.go:17–59  ·  view source on GitHub ↗

AddMember 参加参与用户.

()

Source from the content-addressed store, hash-verified

15
16// AddMember 参加参与用户.
17func (this *BookMemberController) AddMember() {
18 identify := this.GetString("identify")
19 account := this.GetString("account")
20 roleId, _ := this.GetInt("role_id", 3)
21
22 if identify == "" || account == "" {
23 this.JsonResult(6001, "参数错误")
24 }
25 book, err := this.IsPermission()
26
27 if err != nil {
28 this.JsonResult(6001, err.Error())
29 }
30
31 member := models.NewMember()
32
33 if _, err := member.FindByAccount(account); err != nil {
34 this.JsonResult(404, "用户不存在")
35 }
36 if member.Status == 1 {
37 this.JsonResult(6003, "用户已被禁用")
38 }
39
40 if _, err := models.NewRelationship().FindForRoleId(book.BookId, member.MemberId); err == nil {
41 this.JsonResult(6003, "用户已存在该书籍中")
42 }
43
44 relationship := models.NewRelationship()
45 relationship.BookId = book.BookId
46 relationship.MemberId = member.MemberId
47 relationship.RoleId = roleId
48
49 if err := relationship.Insert(); err != nil {
50 this.JsonResult(500, err.Error())
51 }
52
53 result := models.NewMemberRelationshipResult().FromMember(member)
54 result.RoleId = roleId
55 result.RelationshipId = relationship.RelationshipId
56 result.BookId = book.BookId
57 result.ResolveRoleName()
58 this.JsonResult(0, "ok", result)
59}
60
61// 变更指定用户在指定书籍中的权限
62func (this *BookMemberController) ChangeRole() {

Callers

nothing calls this directly

Calls 10

IsPermissionMethod · 0.95
FindByAccountMethod · 0.95
InsertMethod · 0.95
NewMemberFunction · 0.92
NewRelationshipFunction · 0.92
JsonResultMethod · 0.80
FindForRoleIdMethod · 0.80
FromMemberMethod · 0.80
ResolveRoleNameMethod · 0.45

Tested by

no test coverage detected