mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
move away from session variables
This commit is contained in:
parent
1986714927
commit
74a01f8731
@ -121,7 +121,7 @@ class ClientController extends Controller
|
||||
*/
|
||||
public function create(CreateClientRequest $request)
|
||||
{
|
||||
$client = ClientFactory::create($this->getCurrentCompanyId(), auth()->user()->id);
|
||||
$client = ClientFactory::create(auth()->user()->company(), auth()->user()->id);
|
||||
|
||||
$data = [
|
||||
'client' => $client,
|
||||
|
@ -20,7 +20,8 @@ class TokenAuth
|
||||
|
||||
if( $request->header('X-API-TOKEN') && ($user = CompanyToken::whereRaw("BINARY `token`= ?",[$request->header('X-API-TOKEN')])->first()->user ) )
|
||||
{
|
||||
|
||||
//$user->with('company');
|
||||
|
||||
auth()->login($user);
|
||||
|
||||
}
|
||||
|
@ -36,11 +36,11 @@ class HeaderComposer
|
||||
$companies = auth()->user()->companies;
|
||||
|
||||
$data['current_company'] = $companies->first(function ($company){
|
||||
return $company->id == $this->getCurrentCompanyId();
|
||||
return $company->id == auth()->user()->company()->id;
|
||||
});
|
||||
|
||||
$data['companies'] = $companies->reject(function ($company){
|
||||
return $company->id == $this->getCurrentCompanyId();
|
||||
return $company->id == auth()->user()->company->id;
|
||||
});
|
||||
|
||||
return $data;
|
||||
|
@ -30,7 +30,7 @@ class BaseModel extends Model
|
||||
|
||||
public function scopeScope($query)
|
||||
{
|
||||
$query->where($this->getTable() .'.company_id', '=', $this->getCurrentCompanyId());
|
||||
$query->where($this->getTable() .'.company_id', '=', auth()->user()->company()->id);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\Traits\UserTrait;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -62,7 +63,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
public function token()
|
||||
{
|
||||
return $this->tokens->first();
|
||||
return $this->tokens()->first();
|
||||
}
|
||||
|
||||
public function tokens()
|
||||
@ -87,7 +88,11 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->companies()->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
$ct = CompanyToken::whereToken(request()->header('X-API-TOKEN'))->first();
|
||||
|
||||
return $ct->company;
|
||||
|
||||
// return $this->companies()->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,11 +110,14 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
* querying directly on the pivot table relationship
|
||||
*
|
||||
* @return Collection
|
||||
* @deprecated
|
||||
*/
|
||||
public function user_company()
|
||||
{
|
||||
$ct = CompanyToken::whereToken(request()->header('X-API-TOKEN'))->first();
|
||||
|
||||
return $this->user_companies->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
return $ct->company;
|
||||
//return $this->user_companies->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
|
||||
}
|
||||
|
||||
@ -121,7 +129,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function companyId() :int
|
||||
{
|
||||
|
||||
return $this->getCurrentCompanyId();
|
||||
return $this->company()->id;
|
||||
|
||||
}
|
||||
|
||||
@ -133,7 +141,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function permissions()
|
||||
{
|
||||
|
||||
$permissions = json_decode($this->user_company()->permissions);
|
||||
$permissions = json_decode($this->company()->permissions);
|
||||
|
||||
if (! $permissions)
|
||||
return [];
|
||||
@ -149,7 +157,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function settings()
|
||||
{
|
||||
|
||||
return json_decode($this->user_company()->settings);
|
||||
return json_decode($this->company()->settings);
|
||||
|
||||
}
|
||||
|
||||
@ -161,7 +169,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function isAdmin() : bool
|
||||
{
|
||||
|
||||
return (bool) $this->user_company()->is_admin;
|
||||
return (bool) $this->company()->is_admin;
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,11 @@ trait MakesHeaderData
|
||||
$companies = auth()->user()->companies;
|
||||
|
||||
$data['current_company'] = $companies->first(function ($company){
|
||||
return $company->id == $this->getCurrentCompanyId();
|
||||
return $company->id == auth()->user()->company()->id;
|
||||
});
|
||||
|
||||
$data['companies'] = $companies->reject(function ($company){
|
||||
return $company->id == $this->getCurrentCompanyId();
|
||||
return $company->id == auth()->user()->company()->id;
|
||||
});
|
||||
|
||||
return $data;
|
||||
|
@ -29,6 +29,8 @@ Route::group(['middleware' => ['api_secret_check','token_auth']], function () {
|
||||
|
||||
Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit
|
||||
|
||||
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
||||
|
||||
Route::resource('invoices', 'InvoiceController'); // name = (invoices. index / create / show / update / destroy / edit
|
||||
|
||||
Route::post('invoices/bulk', 'InvoiceController@bulk')->name('invoices.bulk');
|
||||
@ -41,8 +43,6 @@ Route::group(['middleware' => ['api_secret_check','token_auth']], function () {
|
||||
|
||||
Route::post('recurring_invoices/bulk', 'RecurringInvoiceController@bulk')->name('recurring_invoices.bulk');
|
||||
|
||||
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
||||
|
||||
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
||||
|
||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||
|
@ -19,11 +19,12 @@ class CollectionMergingTest extends TestCase
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Session::start();
|
||||
|
||||
$this->setCurrentCompanyId(1);
|
||||
|
||||
$this->terms = PaymentTerm::scope()->get();
|
||||
$this->terms = PaymentTerm::all();
|
||||
}
|
||||
|
||||
public function testBlankCollectionReturned()
|
||||
|
Loading…
x
Reference in New Issue
Block a user