update GetUsersByPermissionFunc
This commit is contained in:
		
							parent
							
								
									eb52943468
								
							
						
					
					
						commit
						59426ad48f
					
				
							
								
								
									
										27
									
								
								user/db.go
								
								
								
								
							
							
						
						
									
										27
									
								
								user/db.go
								
								
								
								
							|  | @ -79,6 +79,33 @@ func roleFindByID(ctx context.Context, id primitive.ObjectID) (model.DBRole, err | |||
| 	return doc, err | ||||
| } | ||||
| 
 | ||||
| func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBRole) { | ||||
| 	var ( | ||||
| 		col = database.GetRoleCol() | ||||
| 	) | ||||
| 	docs = make([]model.DBRole, 0) | ||||
| 
 | ||||
| 	cursor, err := col.Find(ctx, cond, opts...) | ||||
| 	if err != nil { | ||||
| 		logger.Error("usermngmt - Role - Find", logger.LogData{ | ||||
| 			"cond": cond, | ||||
| 			"opts": opts, | ||||
| 			"err":  err.Error(), | ||||
| 		}) | ||||
| 		return | ||||
| 	} | ||||
| 	defer cursor.Close(ctx) | ||||
| 	if err = cursor.All(ctx, &docs); err != nil { | ||||
| 		logger.Error("usermngmt - Role - Decode", logger.LogData{ | ||||
| 			"cond": cond, | ||||
| 			"opts": opts, | ||||
| 			"err":  err.Error(), | ||||
| 		}) | ||||
| 		return | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) { | ||||
| 	var ( | ||||
| 		col = database.GetPermissionCol() | ||||
|  |  | |||
|  | @ -225,6 +225,13 @@ func GetUsersByPermission(queryParams model.UserByPermissionQuery) (r model.User | |||
| 	for _, value := range permissions { | ||||
| 		roles = append(roles, value.RoleID) | ||||
| 	} | ||||
| 
 | ||||
| 	// Get admin role
 | ||||
| 	adminRoles := roleFindByCondition(ctx, bson.M{"isAdmin": true}) | ||||
| 	for _, value := range adminRoles { | ||||
| 		roles = append(roles, value.ID) | ||||
| 	} | ||||
| 
 | ||||
| 	if len(roles) < 0 { | ||||
| 		return | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue