it is a bit clumsy repeating the tests from l on l i refactored this block if  tenant id  in search opts search opts  project id  search opts  tenant id  else if  all tenants  in search opts action detail  if is detail else  index authorize context  action s get all tenants action else if context project id search opts  project id  context project id if  user id  not in search opts search opts  user id  context user id if  all tenants  in search opts del search opts  all tenants  however you still need  all users currently there is no way to query for all users in your context tenant without passing your tenant id explicitly 