mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for UserFilters as no company() scope is possible
This commit is contained in:
parent
7b40340047
commit
295a435762
@ -61,10 +61,29 @@ class UserFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
|
||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
return $this->builder->whereHas('company_users', function ($q) {
|
||||
$q->where('company_id', '=', auth()->user()->company()->id);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the base with() function as no company ID
|
||||
* exists on the user table
|
||||
*
|
||||
* @param string $value Hashed ID of the user to return back in the dataset
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function with(string $value = ''): Builder
|
||||
{
|
||||
|
||||
if(strlen($value) == 0)
|
||||
return $this->builder;
|
||||
|
||||
return $this->builder
|
||||
->orWhere($this->with_property, $value)
|
||||
->orderByRaw("{$this->with_property} = ? DESC", [$value])
|
||||
->where('account_id', auth()->user()->account_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,19 @@ class UserTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testUserFiltersWith()
|
||||
{
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->get('/api/v1/users?with='.$this->user->hashed_id);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function testUserList()
|
||||
{
|
||||
$response = $this->withHeaders([
|
||||
|
Loading…
x
Reference in New Issue
Block a user