fixes #8817 - look up reports with all joins from host scoped_search
This changes the optimisation in d50c799 which caused errors for users with host filters referencing tables other than hosts.
When retrieving all reports joined with authorised hosts, the nested joins need to be passed into AR via .joins on the main scope (reports) rather than what happened with scoped_search, which only specifies the joins on the inner scope. In that case, they're ignored and not included in the table list.
Retrieving the conditionals and tables from scoped_search directly allows us to build up a more correct authorisation AR query with joins.
Related issues
Bug #8817: PGError: ERROR: missing FROM-clause entry for table "hostgroups"
fixes #8817 - look up reports with all joins from host scoped_search
This changes the optimisation in d50c799 which caused errors for users with
host filters referencing tables other than hosts.
When retrieving all reports joined with authorised hosts, the nested joins need
to be passed into AR via .joins on the main scope (reports) rather than what
happened with scoped_search, which only specifies the joins on the inner scope.
In that case, they're ignored and not included in the table list.
Retrieving the conditionals and tables from scoped_search directly allows us to
build up a more correct authorisation AR query with joins.