lejianwen 1 год назад
Родитель
Сommit
a3012cfa18

+ 13 - 60
http/controller/admin/addressBook.go

@@ -31,11 +31,6 @@ func (ct *AddressBook) Detail(c *gin.Context) {
31 31
 	id := c.Param("id")
32 32
 	iid, _ := strconv.Atoi(id)
33 33
 	t := service.AllService.AddressBookService.InfoByRowId(uint(iid))
34
-	u := service.AllService.UserService.CurUser(c)
35
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
36
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
37
-		return
38
-	}
39 34
 	if t.RowId > 0 {
40 35
 		response.Success(c, t)
41 36
 		return
@@ -67,9 +62,9 @@ func (ct *AddressBook) Create(c *gin.Context) {
67 62
 		return
68 63
 	}
69 64
 	t := f.ToAddressBook()
70
-	u := service.AllService.UserService.CurUser(c)
71
-	if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
72
-		t.UserId = u.Id
65
+	if t.UserId == 0 {
66
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
67
+		return
73 68
 	}
74 69
 	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
75 70
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
@@ -99,7 +94,7 @@ func (ct *AddressBook) Create(c *gin.Context) {
99 94
 // @Param body body admin.AddressBookForm true "地址簿信息"
100 95
 // @Success 200 {object} response.Response{data=model.AddressBook}
101 96
 // @Failure 500 {object} response.Response
102
-// @Router /admin/address_book/create [post]
97
+// @Router /admin/address_book/batchCreate [post]
103 98
 // @Security token
104 99
 func (ct *AddressBook) BatchCreate(c *gin.Context) {
105 100
 	f := &admin.AddressBookForm{}
@@ -162,10 +157,6 @@ func (ct *AddressBook) List(c *gin.Context) {
162 157
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
163 158
 		return
164 159
 	}
165
-	u := service.AllService.UserService.CurUser(c)
166
-	if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
167
-		query.UserId = int(u.Id)
168
-	}
169 160
 	res := service.AllService.AddressBookService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
170 161
 		tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
171 162
 			return txc.Select("id,name")
@@ -191,11 +182,6 @@ func (ct *AddressBook) List(c *gin.Context) {
191 182
 	for _, ab := range res.AddressBooks {
192 183
 		abCIds = append(abCIds, ab.CollectionId)
193 184
 	}
194
-	//获取地址簿名称
195
-	//cRes := service.AllService.AddressBookService.ListCollection(1, 999, func(tx *gorm.DB) {
196
-	//		tx.Where("id in ?", abCIds)
197
-	//})
198
-	//
199 185
 	response.Success(c, res)
200 186
 }
201 187
 
@@ -222,15 +208,15 @@ func (ct *AddressBook) Update(c *gin.Context) {
222 208
 		return
223 209
 	}
224 210
 	if f.RowId == 0 {
225
-		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
211
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
226 212
 		return
227 213
 	}
228
-	t := f.ToAddressBook()
229
-	u := service.AllService.UserService.CurUser(c)
230
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
231
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
214
+	ex := service.AllService.AddressBookService.InfoByRowId(f.RowId)
215
+	if ex.RowId == 0 {
216
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
232 217
 		return
233 218
 	}
219
+	t := f.ToAddressBook()
234 220
 	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
235 221
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
236 222
 		return
@@ -271,21 +257,12 @@ func (ct *AddressBook) Delete(c *gin.Context) {
271 257
 		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
272 258
 		return
273 259
 	}
274
-	u := service.AllService.UserService.CurUser(c)
275
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
276
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
260
+	err := service.AllService.AddressBookService.Delete(t)
261
+	if err == nil {
262
+		response.Success(c, nil)
277 263
 		return
278 264
 	}
279
-	if u.Id > 0 {
280
-		err := service.AllService.AddressBookService.Delete(t)
281
-		if err == nil {
282
-			response.Success(c, nil)
283
-			return
284
-		}
285
-		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
286
-		return
287
-	}
288
-	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
265
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
289 266
 }
290 267
 
291 268
 // ShareByWebClient
@@ -372,27 +349,3 @@ func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
372 349
 	}
373 350
 	response.Success(c, nil)
374 351
 }
375
-
376
-func (ct *AddressBook) BatchUpdateTags(c *gin.Context) {
377
-	f := &admin.BatchUpdateTagsForm{}
378
-	if err := c.ShouldBindJSON(f); err != nil {
379
-		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
380
-		return
381
-	}
382
-	u := service.AllService.UserService.CurUser(c)
383
-
384
-	abs := service.AllService.AddressBookService.List(1, 999, func(tx *gorm.DB) {
385
-		tx.Where("row_id in ?", f.RowIds)
386
-		tx.Where("user_id = ?", u.Id)
387
-	})
388
-	if abs.Total == 0 {
389
-		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
390
-		return
391
-	}
392
-	err := service.AllService.AddressBookService.BatchUpdateTags(abs.AddressBooks, f.Tags)
393
-	if err != nil {
394
-		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
395
-		return
396
-	}
397
-	response.Success(c, nil)
398
-}

+ 11 - 31
http/controller/admin/addressBookCollection.go

@@ -29,11 +29,6 @@ func (abc *AddressBookCollection) Detail(c *gin.Context) {
29 29
 	id := c.Param("id")
30 30
 	iid, _ := strconv.Atoi(id)
31 31
 	t := service.AllService.AddressBookService.CollectionInfoById(uint(iid))
32
-	u := service.AllService.UserService.CurUser(c)
33
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
34
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
35
-		return
36
-	}
37 32
 	if t.Id > 0 {
38 33
 		response.Success(c, t)
39 34
 		return
@@ -64,12 +59,11 @@ func (abc *AddressBookCollection) Create(c *gin.Context) {
64 59
 		response.Fail(c, 101, errList[0])
65 60
 		return
66 61
 	}
67
-	//t := f.ToAddressBookCollection()
68
-	t := f
69
-	u := service.AllService.UserService.CurUser(c)
70
-	if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
71
-		t.UserId = u.Id
62
+	if f.UserId == 0 {
63
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
64
+		return
72 65
 	}
66
+	t := f
73 67
 	err := service.AllService.AddressBookService.CreateCollection(t)
74 68
 	if err != nil {
75 69
 		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
@@ -98,10 +92,6 @@ func (abc *AddressBookCollection) List(c *gin.Context) {
98 92
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
99 93
 		return
100 94
 	}
101
-	u := service.AllService.UserService.CurUser(c)
102
-	if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
103
-		query.UserId = int(u.Id)
104
-	}
105 95
 	res := service.AllService.AddressBookService.ListCollection(query.Page, query.PageSize, func(tx *gorm.DB) {
106 96
 		if query.UserId > 0 {
107 97
 			tx.Where("user_id = ?", query.UserId)
@@ -137,11 +127,6 @@ func (abc *AddressBookCollection) Update(c *gin.Context) {
137 127
 		return
138 128
 	}
139 129
 	t := f //f.ToAddressBookCollection()
140
-	u := service.AllService.UserService.CurUser(c)
141
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
142
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
143
-		return
144
-	}
145 130
 	err := service.AllService.AddressBookService.UpdateCollection(t)
146 131
 	if err != nil {
147 132
 		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
@@ -173,20 +158,15 @@ func (abc *AddressBookCollection) Delete(c *gin.Context) {
173 158
 		response.Fail(c, 101, errList[0])
174 159
 		return
175 160
 	}
176
-	t := service.AllService.AddressBookService.CollectionInfoById(f.Id)
177
-	u := service.AllService.UserService.CurUser(c)
178
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
179
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
161
+	ex := service.AllService.AddressBookService.CollectionInfoById(f.Id)
162
+	if ex.Id == 0 {
163
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
180 164
 		return
181 165
 	}
182
-	if u.Id > 0 {
183
-		err := service.AllService.AddressBookService.DeleteCollection(t)
184
-		if err == nil {
185
-			response.Success(c, nil)
186
-			return
187
-		}
188
-		response.Fail(c, 101, err.Error())
166
+	err := service.AllService.AddressBookService.DeleteCollection(ex)
167
+	if err == nil {
168
+		response.Success(c, nil)
189 169
 		return
190 170
 	}
191
-	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
171
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
192 172
 }

+ 13 - 42
http/controller/admin/addressBookCollectionRule.go

@@ -35,10 +35,6 @@ func (abcr *AddressBookCollectionRule) List(c *gin.Context) {
35 35
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
36 36
 		return
37 37
 	}
38
-	u := service.AllService.UserService.CurUser(c)
39
-	if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
40
-		query.UserId = int(u.Id)
41
-	}
42 38
 
43 39
 	res := service.AllService.AddressBookService.ListRules(query.Page, query.PageSize, func(tx *gorm.DB) {
44 40
 		if query.UserId > 0 {
@@ -66,17 +62,11 @@ func (abcr *AddressBookCollectionRule) Detail(c *gin.Context) {
66 62
 	id := c.Param("id")
67 63
 	iid, _ := strconv.Atoi(id)
68 64
 	t := service.AllService.AddressBookService.RuleInfoById(uint(iid))
69
-	u := service.AllService.UserService.CurUser(c)
70
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
71
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
72
-		return
73
-	}
74 65
 	if t.Id > 0 {
75 66
 		response.Success(c, t)
76 67
 		return
77 68
 	}
78 69
 	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
79
-	return
80 70
 }
81 71
 
82 72
 // Create 创建地址簿规则
@@ -105,13 +95,8 @@ func (abcr *AddressBookCollectionRule) Create(c *gin.Context) {
105 95
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
106 96
 		return
107 97
 	}
108
-	//t := f.ToAddressBookCollection()
109 98
 	t := f
110
-	u := service.AllService.UserService.CurUser(c)
111
-	if t.UserId == 0 {
112
-		t.UserId = u.Id
113
-	}
114
-	msg, res := abcr.CheckForm(u, t)
99
+	msg, res := abcr.CheckForm(t)
115 100
 	if !res {
116 101
 		response.Fail(c, 101, response.TranslateMsg(c, msg))
117 102
 		return
@@ -124,9 +109,9 @@ func (abcr *AddressBookCollectionRule) Create(c *gin.Context) {
124 109
 	response.Success(c, nil)
125 110
 }
126 111
 
127
-func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.AddressBookCollectionRule) (string, bool) {
128
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
129
-		return "NoAccess", false
112
+func (abcr *AddressBookCollectionRule) CheckForm(t *model.AddressBookCollectionRule) (string, bool) {
113
+	if t.UserId == 0 {
114
+		return "ParamsError", false
130 115
 	}
131 116
 	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
132 117
 		return "ParamsError", false
@@ -141,15 +126,7 @@ func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.Address
141 126
 		if tou.Id == 0 {
142 127
 			return "ItemNotFound", false
143 128
 		}
144
-		//非管理员不能分享给非本组织用户
145
-		if tou.GroupId != u.GroupId && !service.AllService.UserService.IsAdmin(u) {
146
-			return "NoAccess", false
147
-		}
148 129
 	} else if t.Type == model.ShareAddressBookRuleTypeGroup {
149
-		if t.ToId != u.GroupId && !service.AllService.UserService.IsAdmin(u) {
150
-			return "NoAccess", false
151
-		}
152
-
153 130
 		tog := service.AllService.GroupService.InfoById(t.ToId)
154 131
 		if tog.Id == 0 {
155 132
 			return "ItemNotFound", false
@@ -194,9 +171,8 @@ func (abcr *AddressBookCollectionRule) Update(c *gin.Context) {
194 171
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
195 172
 		return
196 173
 	}
197
-	t := f //f.ToAddressBookCollection()
198
-	u := service.AllService.UserService.CurUser(c)
199
-	msg, res := abcr.CheckForm(u, t)
174
+	t := f
175
+	msg, res := abcr.CheckForm(t)
200 176
 	if !res {
201 177
 		response.Fail(c, 101, response.TranslateMsg(c, msg))
202 178
 		return
@@ -232,20 +208,15 @@ func (abcr *AddressBookCollectionRule) Delete(c *gin.Context) {
232 208
 		response.Fail(c, 101, errList[0])
233 209
 		return
234 210
 	}
235
-	t := service.AllService.AddressBookService.RuleInfoById(f.Id)
236
-	u := service.AllService.UserService.CurUser(c)
237
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
238
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
211
+	ex := service.AllService.AddressBookService.RuleInfoById(f.Id)
212
+	if ex.Id == 0 {
213
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
239 214
 		return
240 215
 	}
241
-	if t.Id > 0 {
242
-		err := service.AllService.AddressBookService.DeleteRule(t)
243
-		if err == nil {
244
-			response.Success(c, nil)
245
-			return
246
-		}
247
-		response.Fail(c, 101, err.Error())
216
+	err := service.AllService.AddressBookService.DeleteRule(ex)
217
+	if err == nil {
218
+		response.Success(c, nil)
248 219
 		return
249 220
 	}
250
-	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
221
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
251 222
 }

+ 212 - 0
http/controller/admin/my/addressBook.go

@@ -1,6 +1,7 @@
1 1
 package my
2 2
 
3 3
 import (
4
+	"Gwen/global"
4 5
 	"Gwen/http/request/admin"
5 6
 	"Gwen/http/response"
6 7
 	"Gwen/service"
@@ -11,6 +12,193 @@ import (
11 12
 
12 13
 type AddressBook struct{}
13 14
 
15
+// List 列表
16
+// @Tags 我的地址簿
17
+// @Summary 地址簿列表
18
+// @Description 地址簿列表
19
+// @Accept  json
20
+// @Produce  json
21
+// @Param page query int false "页码"
22
+// @Param page_size query int false "页大小"
23
+// @Param user_id query int false "用户id"
24
+// @Success 200 {object} response.Response{data=model.AddressBookList}
25
+// @Failure 500 {object} response.Response
26
+// @Router /admin/my/address_book/list [get]
27
+// @Security token
28
+func (ct *AddressBook) List(c *gin.Context) {
29
+	query := &admin.AddressBookQuery{}
30
+	if err := c.ShouldBindQuery(query); err != nil {
31
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
32
+		return
33
+	}
34
+	u := service.AllService.UserService.CurUser(c)
35
+	query.UserId = int(u.Id)
36
+	res := service.AllService.AddressBookService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
37
+		//预加载地址簿名称
38
+		tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
39
+			return txc.Select("id,name")
40
+		})
41
+		if query.Id != "" {
42
+			tx.Where("id like ?", "%"+query.Id+"%")
43
+		}
44
+		tx.Where("user_id = ?", query.UserId)
45
+		if query.Username != "" {
46
+			tx.Where("username like ?", "%"+query.Username+"%")
47
+		}
48
+		if query.Hostname != "" {
49
+			tx.Where("hostname like ?", "%"+query.Hostname+"%")
50
+		}
51
+		if query.CollectionId != nil && *query.CollectionId >= 0 {
52
+			tx.Where("collection_id = ?", query.CollectionId)
53
+		}
54
+	})
55
+
56
+	abCIds := make([]uint, 0)
57
+	for _, ab := range res.AddressBooks {
58
+		abCIds = append(abCIds, ab.CollectionId)
59
+	}
60
+	response.Success(c, res)
61
+}
62
+
63
+// Create 创建地址簿
64
+// @Tags 我的地址簿
65
+// @Summary 创建地址簿
66
+// @Description 创建地址簿
67
+// @Accept  json
68
+// @Produce  json
69
+// @Param body body admin.AddressBookForm true "地址簿信息"
70
+// @Success 200 {object} response.Response{data=model.AddressBook}
71
+// @Failure 500 {object} response.Response
72
+// @Router /admin/my/address_book/create [post]
73
+// @Security token
74
+func (ct *AddressBook) Create(c *gin.Context) {
75
+	f := &admin.AddressBookForm{}
76
+	if err := c.ShouldBindJSON(f); err != nil {
77
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
78
+		return
79
+	}
80
+	errList := global.Validator.ValidStruct(c, f)
81
+	if len(errList) > 0 {
82
+		response.Fail(c, 101, errList[0])
83
+		return
84
+	}
85
+	t := f.ToAddressBook()
86
+	u := service.AllService.UserService.CurUser(c)
87
+	t.UserId = u.Id
88
+	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
89
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
90
+		return
91
+	}
92
+
93
+	ex := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(t.UserId, t.Id, t.CollectionId)
94
+	if ex.RowId > 0 {
95
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemExists"))
96
+		return
97
+	}
98
+
99
+	err := service.AllService.AddressBookService.Create(t)
100
+	if err != nil {
101
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
102
+		return
103
+	}
104
+	response.Success(c, nil)
105
+}
106
+
107
+// Update 编辑
108
+// @Tags 我的地址簿
109
+// @Summary 地址簿编辑
110
+// @Description 地址簿编辑
111
+// @Accept  json
112
+// @Produce  json
113
+// @Param body body admin.AddressBookForm true "地址簿信息"
114
+// @Success 200 {object} response.Response{data=model.AddressBook}
115
+// @Failure 500 {object} response.Response
116
+// @Router /admin/my/address_book/update [post]
117
+// @Security token
118
+func (ct *AddressBook) Update(c *gin.Context) {
119
+	f := &admin.AddressBookForm{}
120
+	if err := c.ShouldBindJSON(f); err != nil {
121
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
122
+		return
123
+	}
124
+	errList := global.Validator.ValidStruct(c, f)
125
+	if len(errList) > 0 {
126
+		response.Fail(c, 101, errList[0])
127
+		return
128
+	}
129
+	if f.RowId == 0 {
130
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
131
+		return
132
+	}
133
+	u := service.AllService.UserService.CurUser(c)
134
+	if f.UserId != u.Id {
135
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
136
+		return
137
+	}
138
+
139
+	ex := service.AllService.AddressBookService.InfoByRowId(f.RowId)
140
+	if ex.RowId == 0 {
141
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
142
+		return
143
+	}
144
+	if ex.UserId != u.Id {
145
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
146
+		return
147
+	}
148
+	t := f.ToAddressBook()
149
+	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
150
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
151
+		return
152
+	}
153
+	err := service.AllService.AddressBookService.UpdateAll(t)
154
+	if err != nil {
155
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
156
+		return
157
+	}
158
+	response.Success(c, nil)
159
+}
160
+
161
+// Delete 删除
162
+// @Tags 我的地址簿
163
+// @Summary 地址簿删除
164
+// @Description 地址簿删除
165
+// @Accept  json
166
+// @Produce  json
167
+// @Param body body admin.AddressBookForm true "地址簿信息"
168
+// @Success 200 {object} response.Response
169
+// @Failure 500 {object} response.Response
170
+// @Router /admin/my/address_book/delete [post]
171
+// @Security token
172
+func (ct *AddressBook) Delete(c *gin.Context) {
173
+	f := &admin.AddressBookForm{}
174
+	if err := c.ShouldBindJSON(f); err != nil {
175
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
176
+		return
177
+	}
178
+	id := f.RowId
179
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
180
+	if len(errList) > 0 {
181
+		response.Fail(c, 101, errList[0])
182
+		return
183
+	}
184
+	ex := service.AllService.AddressBookService.InfoByRowId(f.RowId)
185
+	if ex.RowId == 0 {
186
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
187
+		return
188
+	}
189
+	u := service.AllService.UserService.CurUser(c)
190
+	if ex.UserId != u.Id {
191
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
192
+		return
193
+	}
194
+	err := service.AllService.AddressBookService.Delete(ex)
195
+	if err == nil {
196
+		response.Success(c, nil)
197
+		return
198
+	}
199
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
200
+	return
201
+}
14 202
 func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
15 203
 	f := &admin.BatchCreateFromPeersForm{}
16 204
 	if err := c.ShouldBindJSON(f); err != nil {
@@ -57,3 +245,27 @@ func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
57 245
 	}
58 246
 	response.Success(c, nil)
59 247
 }
248
+
249
+func (ct *AddressBook) BatchUpdateTags(c *gin.Context) {
250
+	f := &admin.BatchUpdateTagsForm{}
251
+	if err := c.ShouldBindJSON(f); err != nil {
252
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
253
+		return
254
+	}
255
+	u := service.AllService.UserService.CurUser(c)
256
+
257
+	abs := service.AllService.AddressBookService.List(1, 999, func(tx *gorm.DB) {
258
+		tx.Where("row_id in ?", f.RowIds)
259
+		tx.Where("user_id = ?", u.Id)
260
+	})
261
+	if abs.Total == 0 {
262
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
263
+		return
264
+	}
265
+	err := service.AllService.AddressBookService.BatchUpdateTags(abs.AddressBooks, f.Tags)
266
+	if err != nil {
267
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
268
+		return
269
+	}
270
+	response.Success(c, nil)
271
+}

+ 162 - 0
http/controller/admin/my/addressBookCollection.go

@@ -0,0 +1,162 @@
1
+package my
2
+
3
+import (
4
+	"Gwen/global"
5
+	"Gwen/http/request/admin"
6
+	"Gwen/http/response"
7
+	"Gwen/model"
8
+	"Gwen/service"
9
+	"github.com/gin-gonic/gin"
10
+	"gorm.io/gorm"
11
+)
12
+
13
+type AddressBookCollection struct {
14
+}
15
+
16
+// Create 创建地址簿名称
17
+// @Tags 我的地址簿名称
18
+// @Summary 创建地址簿名称
19
+// @Description 创建地址簿名称
20
+// @Accept  json
21
+// @Produce  json
22
+// @Param body body model.AddressBookCollection true "地址簿名称信息"
23
+// @Success 200 {object} response.Response{data=model.AddressBookCollection}
24
+// @Failure 500 {object} response.Response
25
+// @Router /admin/my/address_book_collection/create [post]
26
+// @Security token
27
+func (abc *AddressBookCollection) Create(c *gin.Context) {
28
+	f := &model.AddressBookCollection{}
29
+	if err := c.ShouldBindJSON(f); err != nil {
30
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
31
+		return
32
+	}
33
+	errList := global.Validator.ValidStruct(c, f)
34
+	if len(errList) > 0 {
35
+		response.Fail(c, 101, errList[0])
36
+		return
37
+	}
38
+	u := service.AllService.UserService.CurUser(c)
39
+	f.UserId = u.Id
40
+	err := service.AllService.AddressBookService.CreateCollection(f)
41
+	if err != nil {
42
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
43
+		return
44
+	}
45
+	response.Success(c, nil)
46
+}
47
+
48
+// List 列表
49
+// @Tags 我的地址簿名称
50
+// @Summary 地址簿名称列表
51
+// @Description 地址簿名称列表
52
+// @Accept  json
53
+// @Produce  json
54
+// @Param page query int false "页码"
55
+// @Param page_size query int false "页大小"
56
+// @Success 200 {object} response.Response{data=model.AddressBookCollectionList}
57
+// @Failure 500 {object} response.Response
58
+// @Router /admin/my/address_book_collection/list [get]
59
+// @Security token
60
+func (abc *AddressBookCollection) List(c *gin.Context) {
61
+	query := &admin.AddressBookCollectionQuery{}
62
+	if err := c.ShouldBindQuery(query); err != nil {
63
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
64
+		return
65
+	}
66
+	u := service.AllService.UserService.CurUser(c)
67
+	query.UserId = int(u.Id)
68
+	res := service.AllService.AddressBookService.ListCollection(query.Page, query.PageSize, func(tx *gorm.DB) {
69
+		tx.Where("user_id = ?", query.UserId)
70
+	})
71
+	response.Success(c, res)
72
+}
73
+
74
+// Update 编辑
75
+// @Tags 我的地址簿名称
76
+// @Summary 地址簿名称编辑
77
+// @Description 地址簿名称编辑
78
+// @Accept  json
79
+// @Produce  json
80
+// @Param body body model.AddressBookCollection true "地址簿名称信息"
81
+// @Success 200 {object} response.Response{data=model.AddressBookCollection}
82
+// @Failure 500 {object} response.Response
83
+// @Router /admin/my/address_book_collection/update [post]
84
+// @Security token
85
+func (abc *AddressBookCollection) Update(c *gin.Context) {
86
+	f := &model.AddressBookCollection{}
87
+	if err := c.ShouldBindJSON(f); err != nil {
88
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
89
+		return
90
+	}
91
+	errList := global.Validator.ValidStruct(c, f)
92
+	if len(errList) > 0 {
93
+		response.Fail(c, 101, errList[0])
94
+		return
95
+	}
96
+	if f.Id == 0 {
97
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
98
+		return
99
+	}
100
+	u := service.AllService.UserService.CurUser(c)
101
+	if f.UserId != u.Id {
102
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
103
+		return
104
+	}
105
+	ex := service.AllService.AddressBookService.CollectionInfoById(f.Id)
106
+	if ex.Id == 0 {
107
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
108
+		return
109
+	}
110
+	if ex.UserId != u.Id {
111
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
112
+		return
113
+	}
114
+
115
+	err := service.AllService.AddressBookService.UpdateCollection(f)
116
+	if err != nil {
117
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
118
+		return
119
+	}
120
+	response.Success(c, nil)
121
+}
122
+
123
+// Delete 删除
124
+// @Tags 我的地址簿名称
125
+// @Summary 地址簿名称删除
126
+// @Description 地址簿名称删除
127
+// @Accept  json
128
+// @Produce  json
129
+// @Param body body model.AddressBookCollection true "地址簿名称信息"
130
+// @Success 200 {object} response.Response
131
+// @Failure 500 {object} response.Response
132
+// @Router /admin/my/address_book_collection/delete [post]
133
+// @Security token
134
+func (abc *AddressBookCollection) Delete(c *gin.Context) {
135
+	f := &model.AddressBookCollection{}
136
+	if err := c.ShouldBindJSON(f); err != nil {
137
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
138
+		return
139
+	}
140
+	id := f.Id
141
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
142
+	if len(errList) > 0 {
143
+		response.Fail(c, 101, errList[0])
144
+		return
145
+	}
146
+	ex := service.AllService.AddressBookService.CollectionInfoById(f.Id)
147
+	if ex.Id == 0 {
148
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
149
+		return
150
+	}
151
+	u := service.AllService.UserService.CurUser(c)
152
+	if ex.UserId != u.Id {
153
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
154
+		return
155
+	}
156
+	err := service.AllService.AddressBookService.DeleteCollection(ex)
157
+	if err == nil {
158
+		response.Success(c, nil)
159
+		return
160
+	}
161
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
162
+}

+ 228 - 0
http/controller/admin/my/addressBookCollectionRule.go

@@ -0,0 +1,228 @@
1
+package my
2
+
3
+import (
4
+	"Gwen/global"
5
+	"Gwen/http/request/admin"
6
+	"Gwen/http/response"
7
+	"Gwen/model"
8
+	"Gwen/service"
9
+	"github.com/gin-gonic/gin"
10
+	"gorm.io/gorm"
11
+)
12
+
13
+type AddressBookCollectionRule struct {
14
+}
15
+
16
+// List 列表
17
+// @Tags 我的地址簿规则
18
+// @Summary 地址簿规则列表
19
+// @Description 地址簿规则列表
20
+// @Accept  json
21
+// @Produce  json
22
+// @Param page query int false "页码"
23
+// @Param page_size query int false "页大小"
24
+// @Param is_my query int false "是否是我的"
25
+// @Param user_id query int false "用户id"
26
+// @Param collection_id query int false "地址簿集合id"
27
+// @Success 200 {object} response.Response{data=model.AddressBookCollectionList}
28
+// @Failure 500 {object} response.Response
29
+// @Router /admin/my/address_book_collection_rule/list [get]
30
+// @Security token
31
+func (abcr *AddressBookCollectionRule) List(c *gin.Context) {
32
+	query := &admin.AddressBookCollectionRuleQuery{}
33
+	if err := c.ShouldBindQuery(query); err != nil {
34
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
35
+		return
36
+	}
37
+	u := service.AllService.UserService.CurUser(c)
38
+	query.UserId = int(u.Id)
39
+
40
+	res := service.AllService.AddressBookService.ListRules(query.Page, query.PageSize, func(tx *gorm.DB) {
41
+		tx.Where("user_id = ?", query.UserId)
42
+		if query.CollectionId > 0 {
43
+			tx.Where("collection_id = ?", query.CollectionId)
44
+		}
45
+	})
46
+	response.Success(c, res)
47
+}
48
+
49
+// Create 创建地址簿规则
50
+// @Tags 我的地址簿规则
51
+// @Summary 创建地址簿规则
52
+// @Description 创建地址簿规则
53
+// @Accept  json
54
+// @Produce  json
55
+// @Param body body model.AddressBookCollectionRule true "地址簿规则信息"
56
+// @Success 200 {object} response.Response{data=model.AddressBookCollection}
57
+// @Failure 500 {object} response.Response
58
+// @Router /admin/my/address_book_collection_rule/create [post]
59
+// @Security token
60
+func (abcr *AddressBookCollectionRule) Create(c *gin.Context) {
61
+	f := &model.AddressBookCollectionRule{}
62
+	if err := c.ShouldBindJSON(f); err != nil {
63
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
64
+		return
65
+	}
66
+	errList := global.Validator.ValidStruct(c, f)
67
+	if len(errList) > 0 {
68
+		response.Fail(c, 101, errList[0])
69
+		return
70
+	}
71
+	if f.Type != model.ShareAddressBookRuleTypePersonal && f.Type != model.ShareAddressBookRuleTypeGroup {
72
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
73
+		return
74
+	}
75
+	//t := f.ToAddressBookCollection()
76
+	t := f
77
+	u := service.AllService.UserService.CurUser(c)
78
+	t.UserId = u.Id
79
+	msg, res := abcr.CheckForm(u, t)
80
+	if !res {
81
+		response.Fail(c, 101, response.TranslateMsg(c, msg))
82
+		return
83
+	}
84
+	err := service.AllService.AddressBookService.CreateRule(t)
85
+	if err != nil {
86
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
87
+		return
88
+	}
89
+	response.Success(c, nil)
90
+}
91
+
92
+func (abcr *AddressBookCollectionRule) CheckForm(u *model.User, t *model.AddressBookCollectionRule) (string, bool) {
93
+	if t.UserId != u.Id {
94
+		return "NoAccess", false
95
+	}
96
+	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
97
+		return "ParamsError", false
98
+	}
99
+
100
+	//check to_id
101
+	if t.Type == model.ShareAddressBookRuleTypePersonal {
102
+		if t.ToId == t.UserId {
103
+			return "ParamsError", false
104
+		}
105
+		tou := service.AllService.UserService.InfoById(t.ToId)
106
+		if tou.Id == 0 {
107
+			return "ItemNotFound", false
108
+		}
109
+		//非管理员不能分享给非本组织用户
110
+		if tou.GroupId != u.GroupId {
111
+			return "NoAccess", false
112
+		}
113
+	} else if t.Type == model.ShareAddressBookRuleTypeGroup {
114
+		//非管理员不能分享给其他组
115
+		if t.ToId != u.GroupId {
116
+			return "NoAccess", false
117
+		}
118
+
119
+		tog := service.AllService.GroupService.InfoById(t.ToId)
120
+		if tog.Id == 0 {
121
+			return "ItemNotFound", false
122
+		}
123
+	} else {
124
+		return "ParamsError", false
125
+	}
126
+	// 重复检查
127
+	ex := service.AllService.AddressBookService.RulePersonalInfoByToIdAndCid(t.ToId, t.CollectionId)
128
+	if t.Id == 0 && ex.Id > 0 {
129
+		return "ItemExists", false
130
+	}
131
+	if t.Id > 0 && ex.Id > 0 && t.Id != ex.Id {
132
+		return "ItemExists", false
133
+	}
134
+	return "", true
135
+}
136
+
137
+// Update 编辑
138
+// @Tags 我的地址簿规则
139
+// @Summary 地址簿规则编辑
140
+// @Description 地址簿规则编辑
141
+// @Accept  json
142
+// @Produce  json
143
+// @Param body body model.AddressBookCollectionRule true "地址簿规则信息"
144
+// @Success 200 {object} response.Response{data=model.AddressBookCollection}
145
+// @Failure 500 {object} response.Response
146
+// @Router /admin/my/address_book_collection_rule/update [post]
147
+// @Security token
148
+func (abcr *AddressBookCollectionRule) Update(c *gin.Context) {
149
+	f := &model.AddressBookCollectionRule{}
150
+	if err := c.ShouldBindJSON(f); err != nil {
151
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
152
+		return
153
+	}
154
+	errList := global.Validator.ValidStruct(c, f)
155
+	if len(errList) > 0 {
156
+		response.Fail(c, 101, errList[0])
157
+		return
158
+	}
159
+	if f.Id == 0 {
160
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
161
+		return
162
+	}
163
+	u := service.AllService.UserService.CurUser(c)
164
+
165
+	ex := service.AllService.AddressBookService.RuleInfoById(f.Id)
166
+	if ex.Id == 0 {
167
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
168
+		return
169
+	}
170
+	if ex.UserId != u.Id {
171
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
172
+		return
173
+	}
174
+	t := f
175
+	msg, res := abcr.CheckForm(u, t)
176
+	if !res {
177
+		response.Fail(c, 101, response.TranslateMsg(c, msg))
178
+		return
179
+	}
180
+	err := service.AllService.AddressBookService.UpdateRule(t)
181
+	if err != nil {
182
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
183
+		return
184
+	}
185
+	response.Success(c, nil)
186
+}
187
+
188
+// Delete 删除
189
+// @Tags 我的地址簿规则
190
+// @Summary 地址簿规则删除
191
+// @Description 地址簿规则删除
192
+// @Accept  json
193
+// @Produce  json
194
+// @Param body body model.AddressBookCollectionRule true "地址簿规则信息"
195
+// @Success 200 {object} response.Response
196
+// @Failure 500 {object} response.Response
197
+// @Router /admin/my/address_book_collection_rule/delete [post]
198
+// @Security token
199
+func (abcr *AddressBookCollectionRule) Delete(c *gin.Context) {
200
+	f := &model.AddressBookCollectionRule{}
201
+	if err := c.ShouldBindJSON(f); err != nil {
202
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
203
+		return
204
+	}
205
+	id := f.Id
206
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
207
+	if len(errList) > 0 {
208
+		response.Fail(c, 101, errList[0])
209
+		return
210
+	}
211
+	ex := service.AllService.AddressBookService.RuleInfoById(f.Id)
212
+	if ex.Id == 0 {
213
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
214
+		return
215
+	}
216
+	u := service.AllService.UserService.CurUser(c)
217
+	if ex.UserId != u.Id {
218
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
219
+		return
220
+	}
221
+
222
+	err := service.AllService.AddressBookService.DeleteRule(ex)
223
+	if err == nil {
224
+		response.Success(c, nil)
225
+		return
226
+	}
227
+	response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
228
+}

+ 59 - 0
http/controller/admin/my/peer.go

@@ -0,0 +1,59 @@
1
+package my
2
+
3
+import (
4
+	"Gwen/http/request/admin"
5
+	"Gwen/http/response"
6
+	"Gwen/service"
7
+	"github.com/gin-gonic/gin"
8
+	"gorm.io/gorm"
9
+	"time"
10
+)
11
+
12
+type Peer struct {
13
+}
14
+
15
+// List 列表
16
+// @Tags 我的设备
17
+// @Summary 设备列表
18
+// @Description 设备列表
19
+// @Accept  json
20
+// @Produce  json
21
+// @Param page query int false "页码"
22
+// @Param page_size query int false "页大小"
23
+// @Param time_ago query int false "时间"
24
+// @Param id query string false "ID"
25
+// @Param hostname query string false "主机名"
26
+// @Param uuids query string false "uuids 用逗号分隔"
27
+// @Success 200 {object} response.Response{data=model.PeerList}
28
+// @Failure 500 {object} response.Response
29
+// @Router /admin/my/peer/list [get]
30
+// @Security token
31
+func (ct *Peer) List(c *gin.Context) {
32
+	query := &admin.PeerQuery{}
33
+	if err := c.ShouldBindQuery(query); err != nil {
34
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
35
+		return
36
+	}
37
+	u := service.AllService.UserService.CurUser(c)
38
+	res := service.AllService.PeerService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
39
+		tx.Where("user_id = ?", u.Id)
40
+		if query.TimeAgo > 0 {
41
+			lt := time.Now().Unix() - int64(query.TimeAgo)
42
+			tx.Where("last_online_time < ?", lt)
43
+		}
44
+		if query.TimeAgo < 0 {
45
+			lt := time.Now().Unix() + int64(query.TimeAgo)
46
+			tx.Where("last_online_time > ?", lt)
47
+		}
48
+		if query.Id != "" {
49
+			tx.Where("id like ?", "%"+query.Id+"%")
50
+		}
51
+		if query.Hostname != "" {
52
+			tx.Where("hostname like ?", "%"+query.Hostname+"%")
53
+		}
54
+		if query.Uuids != "" {
55
+			tx.Where("uuid in (?)", query.Uuids)
56
+		}
57
+	})
58
+	response.Success(c, res)
59
+}

+ 2 - 2
http/controller/admin/my/shareRecord.go

@@ -13,7 +13,7 @@ type ShareRecord struct {
13 13
 }
14 14
 
15 15
 // List 分享记录列表
16
-// @Tags 我的
16
+// @Tags 我的分享记录
17 17
 // @Summary 分享记录列表
18 18
 // @Description 分享记录列表
19 19
 // @Accept  json
@@ -38,7 +38,7 @@ func (sr *ShareRecord) List(c *gin.Context) {
38 38
 }
39 39
 
40 40
 // Delete 分享记录删除
41
-// @Tags 我的
41
+// @Tags 我的分享记录
42 42
 // @Summary 分享记录删除
43 43
 // @Description 分享记录删除
44 44
 // @Accept  json

+ 176 - 0
http/controller/admin/my/tag.go

@@ -0,0 +1,176 @@
1
+package my
2
+
3
+import (
4
+	"Gwen/global"
5
+	"Gwen/http/request/admin"
6
+	"Gwen/http/response"
7
+	"Gwen/service"
8
+	"github.com/gin-gonic/gin"
9
+	"gorm.io/gorm"
10
+)
11
+
12
+type Tag struct{}
13
+
14
+// List 列表
15
+// @Tags 我的标签
16
+// @Summary 标签列表
17
+// @Description 标签列表
18
+// @Accept  json
19
+// @Produce  json
20
+// @Param page query int false "页码"
21
+// @Param page_size query int false "页大小"
22
+// @Param is_my query int false "是否是我的"
23
+// @Param user_id query int false "用户id"
24
+// @Success 200 {object} response.Response{data=model.TagList}
25
+// @Failure 500 {object} response.Response
26
+// @Router /admin/my/tag/list [get]
27
+// @Security token
28
+func (ct *Tag) List(c *gin.Context) {
29
+	query := &admin.TagQuery{}
30
+	if err := c.ShouldBindQuery(query); err != nil {
31
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
32
+		return
33
+	}
34
+	u := service.AllService.UserService.CurUser(c)
35
+	query.UserId = int(u.Id)
36
+	res := service.AllService.TagService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
37
+		tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
38
+			return txc.Select("id,name")
39
+		})
40
+		tx.Where("user_id = ?", query.UserId)
41
+		if query.CollectionId != nil && *query.CollectionId >= 0 {
42
+			tx.Where("collection_id = ?", query.CollectionId)
43
+		}
44
+	})
45
+	response.Success(c, res)
46
+}
47
+
48
+// Create 创建标签
49
+// @Tags 我的标签
50
+// @Summary 创建标签
51
+// @Description 创建标签
52
+// @Accept  json
53
+// @Produce  json
54
+// @Param body body admin.TagForm true "标签信息"
55
+// @Success 200 {object} response.Response{data=model.Tag}
56
+// @Failure 500 {object} response.Response
57
+// @Router /admin/my/tag/create [post]
58
+// @Security token
59
+func (ct *Tag) Create(c *gin.Context) {
60
+	f := &admin.TagForm{}
61
+	if err := c.ShouldBindJSON(f); err != nil {
62
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
63
+		return
64
+	}
65
+	errList := global.Validator.ValidStruct(c, f)
66
+	if len(errList) > 0 {
67
+		response.Fail(c, 101, errList[0])
68
+		return
69
+	}
70
+	t := f.ToTag()
71
+	u := service.AllService.UserService.CurUser(c)
72
+	t.UserId = u.Id
73
+	err := service.AllService.TagService.Create(t)
74
+	if err != nil {
75
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
76
+		return
77
+	}
78
+	response.Success(c, nil)
79
+}
80
+
81
+// Update 编辑
82
+// @Tags 我的标签
83
+// @Summary 标签编辑
84
+// @Description 标签编辑
85
+// @Accept  json
86
+// @Produce  json
87
+// @Param body body admin.TagForm true "标签信息"
88
+// @Success 200 {object} response.Response{data=model.Tag}
89
+// @Failure 500 {object} response.Response
90
+// @Router /admin/my/tag/update [post]
91
+// @Security token
92
+func (ct *Tag) Update(c *gin.Context) {
93
+	f := &admin.TagForm{}
94
+	if err := c.ShouldBindJSON(f); err != nil {
95
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
96
+		return
97
+	}
98
+	errList := global.Validator.ValidStruct(c, f)
99
+	if len(errList) > 0 {
100
+		response.Fail(c, 101, errList[0])
101
+		return
102
+	}
103
+	if f.Id == 0 {
104
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
105
+		return
106
+	}
107
+
108
+	u := service.AllService.UserService.CurUser(c)
109
+	if f.UserId != u.Id {
110
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
111
+		return
112
+	}
113
+	ex := service.AllService.TagService.InfoById(f.Id)
114
+	if ex.Id == 0 {
115
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
116
+		return
117
+	}
118
+	if ex.UserId != u.Id {
119
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
120
+		return
121
+	}
122
+
123
+	t := f.ToTag()
124
+	if t.CollectionId > 0 && !service.AllService.AddressBookService.CheckCollectionOwner(t.UserId, t.CollectionId) {
125
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
126
+		return
127
+	}
128
+	err := service.AllService.TagService.Update(t)
129
+	if err != nil {
130
+		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
131
+		return
132
+	}
133
+	response.Success(c, nil)
134
+}
135
+
136
+// Delete 删除
137
+// @Tags 标签
138
+// @Summary 标签删除
139
+// @Description 标签删除
140
+// @Accept  json
141
+// @Produce  json
142
+// @Param body body admin.TagForm true "标签信息"
143
+// @Success 200 {object} response.Response
144
+// @Failure 500 {object} response.Response
145
+// @Router /admin/my/tag/delete [post]
146
+// @Security token
147
+func (ct *Tag) Delete(c *gin.Context) {
148
+	f := &admin.TagForm{}
149
+	if err := c.ShouldBindJSON(f); err != nil {
150
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
151
+		return
152
+	}
153
+	id := f.Id
154
+	errList := global.Validator.ValidVar(c, id, "required,gt=0")
155
+	if len(errList) > 0 {
156
+		response.Fail(c, 101, errList[0])
157
+		return
158
+	}
159
+	ex := service.AllService.TagService.InfoById(f.Id)
160
+	if ex.Id == 0 {
161
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
162
+		return
163
+	}
164
+	u := service.AllService.UserService.CurUser(c)
165
+	if ex.UserId != u.Id {
166
+		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
167
+		return
168
+	}
169
+	err := service.AllService.TagService.Delete(ex)
170
+	if err == nil {
171
+		response.Success(c, nil)
172
+		return
173
+	}
174
+	response.Fail(c, 101, err.Error())
175
+	return
176
+}

+ 14 - 23
http/controller/admin/tag.go

@@ -64,9 +64,9 @@ func (ct *Tag) Create(c *gin.Context) {
64 64
 		return
65 65
 	}
66 66
 	t := f.ToTag()
67
-	u := service.AllService.UserService.CurUser(c)
68
-	if !service.AllService.UserService.IsAdmin(u) || t.UserId == 0 {
69
-		t.UserId = u.Id
67
+	if t.UserId == 0 {
68
+		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
69
+		return
70 70
 	}
71 71
 	err := service.AllService.TagService.Create(t)
72 72
 	if err != nil {
@@ -96,10 +96,6 @@ func (ct *Tag) List(c *gin.Context) {
96 96
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
97 97
 		return
98 98
 	}
99
-	u := service.AllService.UserService.CurUser(c)
100
-	if !service.AllService.UserService.IsAdmin(u) || query.IsMy == 1 {
101
-		query.UserId = int(u.Id)
102
-	}
103 99
 	res := service.AllService.TagService.List(query.Page, query.PageSize, func(tx *gorm.DB) {
104 100
 		tx.Preload("Collection", func(txc *gorm.DB) *gorm.DB {
105 101
 			return txc.Select("id,name")
@@ -140,12 +136,12 @@ func (ct *Tag) Update(c *gin.Context) {
140 136
 		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
141 137
 		return
142 138
 	}
143
-	t := f.ToTag()
144
-	u := service.AllService.UserService.CurUser(c)
145
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
146
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
139
+	ex := service.AllService.TagService.InfoById(f.Id)
140
+	if ex.Id == 0 {
141
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
147 142
 		return
148 143
 	}
144
+	t := f.ToTag()
149 145
 	err := service.AllService.TagService.Update(t)
150 146
 	if err != nil {
151 147
 		response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
@@ -177,20 +173,15 @@ func (ct *Tag) Delete(c *gin.Context) {
177 173
 		response.Fail(c, 101, errList[0])
178 174
 		return
179 175
 	}
180
-	t := service.AllService.TagService.InfoById(f.Id)
181
-	u := service.AllService.UserService.CurUser(c)
182
-	if !service.AllService.UserService.IsAdmin(u) && t.UserId != u.Id {
183
-		response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
176
+	ex := service.AllService.TagService.InfoById(f.Id)
177
+	if ex.Id == 0 {
178
+		response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
184 179
 		return
185 180
 	}
186
-	if u.Id > 0 {
187
-		err := service.AllService.TagService.Delete(t)
188
-		if err == nil {
189
-			response.Success(c, nil)
190
-			return
191
-		}
192
-		response.Fail(c, 101, err.Error())
181
+	err := service.AllService.TagService.Delete(ex)
182
+	if err == nil {
183
+		response.Success(c, nil)
193 184
 		return
194 185
 	}
195
-	response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
186
+	response.Fail(c, 101, err.Error())
196 187
 }

+ 0 - 46
http/controller/admin/user.go

@@ -10,7 +10,6 @@ import (
10 10
 	"github.com/gin-gonic/gin"
11 11
 	"gorm.io/gorm"
12 12
 	"strconv"
13
-	"time"
14 13
 )
15 14
 
16 15
 type User struct {
@@ -295,51 +294,6 @@ func (ct *User) MyOauth(c *gin.Context) {
295 294
 	response.Success(c, res)
296 295
 }
297 296
 
298
-// MyPeer 列表
299
-// @Tags 设备
300
-// @Summary 我的设备列表
301
-// @Description 我的设备列表
302
-// @Accept  json
303
-// @Produce  json
304
-// @Param page query int false "页码"
305
-// @Param page_size query int false "页大小"
306
-// @Param time_ago query int false "时间"
307
-// @Param id query string false "ID"
308
-// @Param hostname query string false "主机名"
309
-// @Param uuids query string false "uuids 用逗号分隔"
310
-// @Success 200 {object} response.Response{data=model.PeerList}
311
-// @Failure 500 {object} response.Response
312
-// @Router /admin/user/myPeer [get]
313
-// @Security token
314
-func (ct *User) MyPeer(c *gin.Context) {
315
-	query := &admin.PeerQuery{}
316
-	if err := c.ShouldBindQuery(query); err != nil {
317
-		response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
318
-		return
319
-	}
320
-	u := service.AllService.UserService.CurUser(c)
321
-	res := service.AllService.PeerService.ListFilterByUserId(query.Page, query.PageSize, func(tx *gorm.DB) {
322
-		if query.TimeAgo > 0 {
323
-			lt := time.Now().Unix() - int64(query.TimeAgo)
324
-			tx.Where("last_online_time < ?", lt)
325
-		}
326
-		if query.TimeAgo < 0 {
327
-			lt := time.Now().Unix() + int64(query.TimeAgo)
328
-			tx.Where("last_online_time > ?", lt)
329
-		}
330
-		if query.Id != "" {
331
-			tx.Where("id like ?", "%"+query.Id+"%")
332
-		}
333
-		if query.Hostname != "" {
334
-			tx.Where("hostname like ?", "%"+query.Hostname+"%")
335
-		}
336
-		if query.Uuids != "" {
337
-			tx.Where("uuid in (?)", query.Uuids)
338
-		}
339
-	}, u.Id)
340
-	response.Success(c, res)
341
-}
342
-
343 297
 // groupUsers
344 298
 func (ct *User) GroupUsers(c *gin.Context) {
345 299
 	q := &admin.GroupUsersQuery{}

+ 51 - 17
http/router/admin.go

@@ -62,7 +62,7 @@ func UserBind(rg *gin.RouterGroup) {
62 62
 		aR.GET("/current", cont.Current)
63 63
 		aR.POST("/changeCurPwd", cont.ChangeCurPwd)
64 64
 		aR.POST("/myOauth", cont.MyOauth)
65
-		aR.GET("/myPeer", cont.MyPeer)
65
+		//aR.GET("/myPeer", cont.MyPeer)
66 66
 		aR.POST("/groupUsers", cont.GroupUsers)
67 67
 	}
68 68
 	aRP := rg.Group("/user").Use(middleware.AdminPrivilege())
@@ -90,7 +90,7 @@ func GroupBind(rg *gin.RouterGroup) {
90 90
 }
91 91
 
92 92
 func TagBind(rg *gin.RouterGroup) {
93
-	aR := rg.Group("/tag")
93
+	aR := rg.Group("/tag").Use(middleware.AdminPrivilege())
94 94
 	{
95 95
 		cont := &admin.Tag{}
96 96
 		aR.GET("/list", cont.List)
@@ -105,16 +105,14 @@ func AddressBookBind(rg *gin.RouterGroup) {
105 105
 	aR := rg.Group("/address_book")
106 106
 	{
107 107
 		cont := &admin.AddressBook{}
108
-		aR.GET("/list", cont.List)
109
-		aR.GET("/detail/:id", cont.Detail)
110
-		aR.POST("/create", cont.Create)
111
-		aR.POST("/update", cont.Update)
112
-		aR.POST("/delete", cont.Delete)
113 108
 		aR.POST("/shareByWebClient", cont.ShareByWebClient)
114 109
 
115
-		aR.POST("/batchUpdateTags", cont.BatchUpdateTags)
116
-
117 110
 		arp := aR.Use(middleware.AdminPrivilege())
111
+		arp.GET("/list", cont.List)
112
+		//arp.GET("/detail/:id", cont.Detail)
113
+		arp.POST("/create", cont.Create)
114
+		arp.POST("/update", cont.Update)
115
+		arp.POST("/delete", cont.Delete)
118 116
 		arp.POST("/batchCreate", cont.BatchCreate)
119 117
 		arp.POST("/batchCreateFromPeers", cont.BatchCreateFromPeers)
120 118
 
@@ -176,7 +174,7 @@ func AuditBind(rg *gin.RouterGroup) {
176 174
 	afR.POST("/batchDelete", cont.BatchFileDelete)
177 175
 }
178 176
 func AddressBookCollectionBind(rg *gin.RouterGroup) {
179
-	aR := rg.Group("/address_book_collection")
177
+	aR := rg.Group("/address_book_collection").Use(middleware.AdminPrivilege())
180 178
 	{
181 179
 		cont := &admin.AddressBookCollection{}
182 180
 		aR.GET("/list", cont.List)
@@ -188,7 +186,7 @@ func AddressBookCollectionBind(rg *gin.RouterGroup) {
188 186
 
189 187
 }
190 188
 func AddressBookCollectionRuleBind(rg *gin.RouterGroup) {
191
-	aR := rg.Group("/address_book_collection_rule")
189
+	aR := rg.Group("/address_book_collection_rule").Use(middleware.AdminPrivilege())
192 190
 	{
193 191
 		cont := &admin.AddressBookCollectionRule{}
194 192
 		aR.GET("/list", cont.List)
@@ -228,13 +226,49 @@ func FileBind(rg *gin.RouterGroup) {
228 226
 
229 227
 func MyBind(rg *gin.RouterGroup) {
230 228
 	{
231
-		msr := &my.ShareRecord{}
232
-		rg.GET("/my/share_record/list", msr.List)
233
-		rg.POST("/my/share_record/delete", msr.Delete)
234
-		rg.POST("/my/share_record/batchDelete", msr.BatchDelete)
229
+		cont := &my.ShareRecord{}
230
+		rg.GET("/my/share_record/list", cont.List)
231
+		rg.POST("/my/share_record/delete", cont.Delete)
232
+		rg.POST("/my/share_record/batchDelete", cont.BatchDelete)
233
+	}
234
+
235
+	{
236
+		cont := &my.AddressBook{}
237
+		rg.GET("/my/address_book/list", cont.List)
238
+		rg.POST("/my/address_book/create", cont.Create)
239
+		rg.POST("/my/address_book/update", cont.Update)
240
+		rg.POST("/my/address_book/delete", cont.Delete)
241
+		rg.POST("/my/address_book/batchCreateFromPeers", cont.BatchCreateFromPeers)
242
+		rg.POST("/my/address_book/batchUpdateTags", cont.BatchUpdateTags)
243
+	}
244
+
245
+	{
246
+		cont := &my.Tag{}
247
+		rg.GET("/my/tag/list", cont.List)
248
+		rg.POST("/my/tag/create", cont.Create)
249
+		rg.POST("/my/tag/update", cont.Update)
250
+		rg.POST("/my/tag/delete", cont.Delete)
251
+	}
252
+
253
+	{
254
+		cont := &my.AddressBookCollection{}
255
+		rg.GET("/my/address_book_collection/list", cont.List)
256
+		rg.POST("/my/address_book_collection/create", cont.Create)
257
+		rg.POST("/my/address_book_collection/update", cont.Update)
258
+		rg.POST("/my/address_book_collection/delete", cont.Delete)
259
+	}
260
+
261
+	{
262
+		cont := &my.AddressBookCollectionRule{}
263
+		rg.GET("/my/address_book_collection_rule/list", cont.List)
264
+		rg.POST("/my/address_book_collection_rule/create", cont.Create)
265
+		rg.POST("/my/address_book_collection_rule/update", cont.Update)
266
+		rg.POST("/my/address_book_collection_rule/delete", cont.Delete)
267
+	}
268
+	{
269
+		cont := &my.Peer{}
270
+		rg.GET("/my/peer/list", cont.List)
235 271
 
236
-		mab := &my.AddressBook{}
237
-		rg.POST("/my/address_book/batchCreateFromPeers", mab.BatchCreateFromPeers)
238 272
 	}
239 273
 }
240 274