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

Method ChangeRole

controllers/BookMemberController.go:62–113  ·  view source on GitHub ↗

变更指定用户在指定书籍中的权限

()

Source from the content-addressed store, hash-verified

60
61// 变更指定用户在指定书籍中的权限
62func (this *BookMemberController) ChangeRole() {
63 identify := this.GetString("identify")
64 memberId, _ := this.GetInt("member_id", 0)
65 role, _ := this.GetInt("role_id", 0)
66
67 if identify == "" || memberId <= 0 {
68 this.JsonResult(6001, "参数错误")
69 }
70 if memberId == this.Member.MemberId {
71 this.JsonResult(6006, "不能变更自己的权限")
72 }
73
74 book, err := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId)
75 if err != nil {
76 if err == models.ErrPermissionDenied {
77 this.JsonResult(403, "权限不足")
78 }
79 if err == orm.ErrNoRows {
80 this.JsonResult(404, "书籍不存在")
81 }
82 this.JsonResult(6002, err.Error())
83 }
84
85 if book.RoleId != 0 && book.RoleId != 1 {
86 this.JsonResult(403, "权限不足")
87 }
88
89 member := models.NewMember()
90
91 if _, err := member.Find(memberId); err != nil {
92 this.JsonResult(6003, "用户不存在")
93 }
94
95 if member.Status == 1 {
96 this.JsonResult(6004, "用户已被禁用")
97 }
98
99 relationship, err := models.NewRelationship().UpdateRoleId(book.BookId, memberId, role)
100
101 if err != nil {
102 logs.Error("变更用户在书籍中的权限 => ", err)
103 this.JsonResult(6005, err.Error())
104 }
105
106 result := models.NewMemberRelationshipResult().FromMember(member)
107 result.RoleId = relationship.RoleId
108 result.RelationshipId = relationship.RelationshipId
109 result.BookId = book.BookId
110 result.ResolveRoleName()
111
112 this.JsonResult(0, "ok", result)
113}
114
115// 删除参与者.
116func (this *BookMemberController) RemoveMember() {

Callers

nothing calls this directly

Calls 10

FindMethod · 0.95
NewBookResultFunction · 0.92
NewMemberFunction · 0.92
NewRelationshipFunction · 0.92
JsonResultMethod · 0.80
UpdateRoleIdMethod · 0.80
FromMemberMethod · 0.80
FindByIdentifyMethod · 0.45
ResolveRoleNameMethod · 0.45

Tested by

no test coverage detected