mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Re work the way we harvest a user token
This commit is contained in:
parent
51c5b96b68
commit
f4ae84e954
@ -112,9 +112,13 @@ class UserFilters extends QueryFilters
|
||||
*/
|
||||
public function entityFilter()
|
||||
{
|
||||
|
||||
return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
//return $this->builder->user_companies()->whereCompanyId(auth()->user()->company()->id);
|
||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||
return $this->builder->whereHas('user_companies', function($q)
|
||||
{
|
||||
$q->where('company_id', '=', auth()->user()->company()->id);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -55,7 +55,7 @@ class UserController extends BaseController
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(UserFilters $filster)
|
||||
public function index(UserFilters $filters)
|
||||
{
|
||||
$users = User::filter($filters);
|
||||
|
||||
@ -96,7 +96,7 @@ class UserController extends BaseController
|
||||
]);
|
||||
|
||||
$user->load('companies');
|
||||
|
||||
|
||||
return $this->itemResponse($user);
|
||||
|
||||
}
|
||||
|
@ -89,21 +89,20 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function tokens()
|
||||
public function token()
|
||||
{
|
||||
return $this->hasMany(CompanyToken::class)->orderBy('id', 'ASC');
|
||||
return $this->hasOne(CompanyToken::class)->orderBy('id', 'ASC');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return first user token
|
||||
*
|
||||
* @return token object
|
||||
*/
|
||||
public function token()
|
||||
{
|
||||
return $this->tokens()->first();
|
||||
}
|
||||
//public function token()
|
||||
//{
|
||||
// return $this->tokens()->first();
|
||||
//}
|
||||
|
||||
/**
|
||||
* Returns all companies a user has access to.
|
||||
@ -122,7 +121,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->tokens()->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company;
|
||||
return $this->token->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@ use App\Policies\ProductPolicy;
|
||||
use App\Policies\QuotePolicy;
|
||||
use App\Policies\RecurringInvoicePolicy;
|
||||
use App\Policies\RecurringQuotePolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
use Auth;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
@ -52,8 +52,8 @@ class UserTransformer extends EntityTransformer
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = [
|
||||
'company_token',
|
||||
|
||||
// 'company_token',
|
||||
'token',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -61,7 +61,6 @@ class UserTransformer extends EntityTransformer
|
||||
*/
|
||||
protected $availableIncludes = [
|
||||
'companies',
|
||||
'company_tokens',
|
||||
];
|
||||
|
||||
|
||||
@ -101,12 +100,12 @@ class UserTransformer extends EntityTransformer
|
||||
|
||||
}
|
||||
|
||||
public function includeCompanyToken(User $user)
|
||||
public function includeToken(User $user)
|
||||
{
|
||||
|
||||
$transformer = new CompanyTokenTransformer($this->serializer);
|
||||
|
||||
return $this->includeItem($user->token(), $transformer, CompanyToken::class);
|
||||
return $this->includeItem($user->token, $transformer, CompanyToken::class);
|
||||
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,8 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth'], 'prefix' =
|
||||
|
||||
Route::post('payments/bulk', 'PaymentController@bulk')->name('payments.bulk');
|
||||
|
||||
Route::resource('users', 'UserController'); // name = (users. index / create / show / update / destroy / edit
|
||||
|
||||
/*
|
||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||
|
||||
@ -75,7 +77,6 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth'], 'prefix' =
|
||||
|
||||
Route::post('expenses/bulk', 'ExpenseController@bulk')->name('expenses.bulk');
|
||||
|
||||
Route::resource('user', 'UserProfileController'); // name = (clients. index / create / show / update / destroy / edit
|
||||
|
||||
Route::get('settings', 'SettingsController@index')->name('user.settings');
|
||||
*/
|
||||
|
@ -116,7 +116,7 @@ class ClientTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 3)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
@ -72,7 +72,7 @@ class InvoiceTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
@ -135,7 +135,7 @@ class InvoiceTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
@ -72,7 +72,7 @@ class PaymentTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
@ -135,7 +135,7 @@ class PaymentTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
@ -72,7 +72,7 @@ class QuoteTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
@ -135,7 +135,7 @@ class QuoteTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
@ -72,7 +72,7 @@ class RecurringInvoiceTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
@ -135,7 +135,7 @@ class RecurringInvoiceTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
@ -72,7 +72,7 @@ class RecurringQuoteTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
@ -135,7 +135,7 @@ class RecurringQuoteTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens->first()->company);
|
||||
$this->assertNotNull($user->token->company);
|
||||
|
||||
factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user