@@ -233,6 +233,27 @@ func (authorityService *AuthorityService) GetStructAuthorityList(authorityID uin
233
233
return list , err
234
234
}
235
235
236
+ func (authorityService * AuthorityService ) CheckAuthorityIDAuth (authorityID , targetID uint ) (err error ) {
237
+ if ! global .GVA_CONFIG .System .UseStrictAuth {
238
+ return nil
239
+ }
240
+ authIDS , err := authorityService .GetStructAuthorityList (authorityID )
241
+ if err != nil {
242
+ return err
243
+ }
244
+ hasAuth := false
245
+ for _ , v := range authIDS {
246
+ if v == targetID {
247
+ hasAuth = true
248
+ break
249
+ }
250
+ }
251
+ if ! hasAuth {
252
+ return errors .New ("您提交的角色ID不合法" )
253
+ }
254
+ return nil
255
+ }
256
+
236
257
//@author: [piexlmax](https://github.com/piexlmax)
237
258
//@function: GetAuthorityInfo
238
259
//@description: 获取所有角色信息
@@ -251,22 +272,19 @@ func (authorityService *AuthorityService) GetAuthorityInfo(auth system.SysAuthor
251
272
//@return: error
252
273
253
274
func (authorityService * AuthorityService ) SetDataAuthority (adminAuthorityID uint , auth system.SysAuthority ) error {
254
- if global .GVA_CONFIG .System .UseStrictAuth {
255
- authids , err := AuthorityServiceApp .GetStructAuthorityList (adminAuthorityID )
275
+ var checkIDs []uint
276
+ checkIDs = append (checkIDs , auth .AuthorityId )
277
+ for i := range auth .DataAuthorityId {
278
+ checkIDs = append (checkIDs , auth .DataAuthorityId [i ].AuthorityId )
279
+ }
280
+
281
+ for i := range checkIDs {
282
+ err := authorityService .CheckAuthorityIDAuth (adminAuthorityID , checkIDs [i ])
256
283
if err != nil {
257
284
return err
258
285
}
259
- hasAuth := false
260
- for _ , v := range authids {
261
- if v == auth .AuthorityId {
262
- hasAuth = true
263
- break
264
- }
265
- }
266
- if ! hasAuth {
267
- return errors .New ("您提交的角色ID不合法" )
268
- }
269
286
}
287
+
270
288
var s system.SysAuthority
271
289
global .GVA_DB .Preload ("DataAuthorityId" ).First (& s , "authority_id = ?" , auth .AuthorityId )
272
290
err := global .GVA_DB .Model (& s ).Association ("DataAuthorityId" ).Replace (& auth .DataAuthorityId )
0 commit comments