ljw 1 год назад
Родитель
Сommit
d5cf3544f1
1 измененных файлов с 19 добавлено и 21 удалено
  1. 19 21
      http/controller/api/group.go

+ 19 - 21
http/controller/api/group.go

@@ -28,23 +28,23 @@ type Group struct {
28
 // @Router /users [get]
28
 // @Router /users [get]
29
 // @Security BearerAuth
29
 // @Security BearerAuth
30
 func (g *Group) Users(c *gin.Context) {
30
 func (g *Group) Users(c *gin.Context) {
31
-	u := service.AllService.UserService.CurUser(c)
32
-
33
-	if !*u.IsAdmin {
34
-		gr := service.AllService.GroupService.InfoById(u.GroupId)
35
-		if gr.Type != model.GroupTypeShare {
36
-			response.Error(c, response.TranslateMsg(c, "NoAccess"))
37
-			return
38
-		}
39
-	}
40
-
41
 	q := &apiReq.UserListQuery{}
31
 	q := &apiReq.UserListQuery{}
42
 	err := c.ShouldBindQuery(&q)
32
 	err := c.ShouldBindQuery(&q)
43
 	if err != nil {
33
 	if err != nil {
44
 		response.Error(c, err.Error())
34
 		response.Error(c, err.Error())
45
 		return
35
 		return
46
 	}
36
 	}
47
-	userList := service.AllService.UserService.ListByGroupId(u.GroupId, q.Page, q.PageSize)
37
+	u := service.AllService.UserService.CurUser(c)
38
+	gr := service.AllService.GroupService.InfoById(u.GroupId)
39
+	userList := &model.UserList{}
40
+	if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
41
+		//仅能获取到自己
42
+		userList.Users = append(userList.Users, u)
43
+		userList.Total = 1
44
+	} else {
45
+		userList = service.AllService.UserService.ListByGroupId(u.GroupId, q.Page, q.PageSize)
46
+	}
47
+
48
 	var data []*apiResp.UserPayload
48
 	var data []*apiResp.UserPayload
49
 	for _, user := range userList.Users {
49
 	for _, user := range userList.Users {
50
 		up := &apiResp.UserPayload{}
50
 		up := &apiResp.UserPayload{}
@@ -73,23 +73,21 @@ func (g *Group) Users(c *gin.Context) {
73
 // @Security BearerAuth
73
 // @Security BearerAuth
74
 func (g *Group) Peers(c *gin.Context) {
74
 func (g *Group) Peers(c *gin.Context) {
75
 	u := service.AllService.UserService.CurUser(c)
75
 	u := service.AllService.UserService.CurUser(c)
76
-
77
-	if !*u.IsAdmin {
78
-		gr := service.AllService.GroupService.InfoById(u.GroupId)
79
-		if gr.Type != model.GroupTypeShare {
80
-			response.Error(c, response.TranslateMsg(c, "NoAccess"))
81
-			return
82
-		}
83
-	}
84
-
85
 	q := &apiReq.PeerListQuery{}
76
 	q := &apiReq.PeerListQuery{}
86
 	err := c.ShouldBindQuery(&q)
77
 	err := c.ShouldBindQuery(&q)
87
 	if err != nil {
78
 	if err != nil {
88
 		response.Error(c, err.Error())
79
 		response.Error(c, err.Error())
89
 		return
80
 		return
90
 	}
81
 	}
82
+	gr := service.AllService.GroupService.InfoById(u.GroupId)
83
+	users := make([]*model.User, 0, 1)
84
+	if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
85
+		//仅能获取到自己
86
+		users = append(users, u)
87
+	} else {
88
+		users = service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
89
+	}
91
 
90
 
92
-	users := service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
93
 	namesById := make(map[uint]string)
91
 	namesById := make(map[uint]string)
94
 	userIds := make([]uint, 0)
92
 	userIds := make([]uint, 0)
95
 	for _, user := range users {
93
 	for _, user := range users {