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 28
 // @Router /users [get]
29 29
 // @Security BearerAuth
30 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 31
 	q := &apiReq.UserListQuery{}
42 32
 	err := c.ShouldBindQuery(&q)
43 33
 	if err != nil {
44 34
 		response.Error(c, err.Error())
45 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 48
 	var data []*apiResp.UserPayload
49 49
 	for _, user := range userList.Users {
50 50
 		up := &apiResp.UserPayload{}
@@ -73,23 +73,21 @@ func (g *Group) Users(c *gin.Context) {
73 73
 // @Security BearerAuth
74 74
 func (g *Group) Peers(c *gin.Context) {
75 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 76
 	q := &apiReq.PeerListQuery{}
86 77
 	err := c.ShouldBindQuery(&q)
87 78
 	if err != nil {
88 79
 		response.Error(c, err.Error())
89 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 91
 	namesById := make(map[uint]string)
94 92
 	userIds := make([]uint, 0)
95 93
 	for _, user := range users {