improved tenant identification
This commit is contained in:
@@ -31,14 +31,14 @@ class CreateCompany extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$current_company_id = company_id();
|
||||
|
||||
event(new CompanyCreating($this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->company = Company::create($this->request->all());
|
||||
|
||||
// Clear settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
$this->company->makeCurrent();
|
||||
|
||||
$this->callSeeds();
|
||||
|
||||
@@ -47,6 +47,10 @@ class CreateCompany extends Job
|
||||
|
||||
event(new CompanyCreated($this->company));
|
||||
|
||||
if (!empty($current_company_id)) {
|
||||
company($current_company_id)->makeCurrent();
|
||||
}
|
||||
|
||||
return $this->company;
|
||||
}
|
||||
|
||||
@@ -106,6 +110,5 @@ class CreateCompany extends Job
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
setting()->forgetAll();
|
||||
}
|
||||
}
|
||||
|
||||
55
app/Jobs/Common/CreateMediableForExport.php
Normal file
55
app/Jobs/Common/CreateMediableForExport.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\JobShouldQueue;
|
||||
use App\Notifications\Common\ExportCompleted;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class CreateMediableForExport extends JobShouldQueue
|
||||
{
|
||||
protected $user;
|
||||
|
||||
protected $file_name;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $user
|
||||
* @param $file_name
|
||||
*/
|
||||
public function __construct($user, $file_name)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->file_name = $file_name;
|
||||
|
||||
$this->onQueue('jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$source = storage_path('app/uploads/' . $this->file_name);
|
||||
$destination = storage_path('app/uploads/' . company_id() . '/exports/');
|
||||
|
||||
// Create exports directory
|
||||
if (!File::isDirectory($destination)) {
|
||||
File::makeDirectory($destination);
|
||||
}
|
||||
|
||||
File::move($source, $destination . $this->file_name);
|
||||
|
||||
// Create the media record
|
||||
$media = $this->importMedia($this->file_name, 'exports');
|
||||
|
||||
$this->user->attachMedia($media, 'export');
|
||||
|
||||
$download_url = route('uploads.download', ['id' => $media->id, 'company_id' => company_id()]);
|
||||
|
||||
$this->user->notify(new ExportCompleted($download_url));
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,17 @@ class DeleteCompany extends Job
|
||||
|
||||
protected $company;
|
||||
|
||||
protected $active_company_id;
|
||||
protected $current_company_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($company, $active_company_id)
|
||||
public function __construct($company)
|
||||
{
|
||||
$this->company = $company;
|
||||
$this->active_company_id = $active_company_id;
|
||||
$this->current_company_id = company_id();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,14 +56,14 @@ class DeleteCompany extends Job
|
||||
public function authorize()
|
||||
{
|
||||
// Can't delete active company
|
||||
if ($this->company->id == $this->active_company_id) {
|
||||
if ($this->company->id == $this->current_company_id) {
|
||||
$message = trans('companies.error.delete_active');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
// Check if user can access company
|
||||
if (!$this->isUserCompany($this->company->id)) {
|
||||
if ($this->isNotUserCompany($this->company->id)) {
|
||||
$message = trans('companies.error.not_user_company');
|
||||
|
||||
throw new \Exception($message);
|
||||
|
||||
@@ -60,7 +60,7 @@ class DeleteDashboard extends Job
|
||||
}
|
||||
|
||||
// Check if user can access dashboard
|
||||
if (!$this->isUserDashboard($this->dashboard->id)) {
|
||||
if ($this->isNotUserDashboard($this->dashboard->id)) {
|
||||
$message = trans('dashboards.error.not_user_dashboard');
|
||||
|
||||
throw new \Exception($message);
|
||||
|
||||
@@ -16,7 +16,7 @@ class UpdateCompany extends Job
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $active_company_id;
|
||||
protected $current_company_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
@@ -24,11 +24,11 @@ class UpdateCompany extends Job
|
||||
* @param $company
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($company, $request, $active_company_id)
|
||||
public function __construct($company, $request)
|
||||
{
|
||||
$this->company = $company;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->active_company_id = $active_company_id;
|
||||
$this->current_company_id = company_id();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,10 +45,7 @@ class UpdateCompany extends Job
|
||||
\DB::transaction(function () {
|
||||
$this->company->update($this->request->all());
|
||||
|
||||
// Clear current and load given company settings
|
||||
setting()->setExtraColumns(['company_id' => $this->company->id]);
|
||||
setting()->forgetAll();
|
||||
setting()->load(true);
|
||||
$this->company->makeCurrent();
|
||||
|
||||
if ($this->request->has('name')) {
|
||||
setting()->set('company.name', $this->request->get('name'));
|
||||
@@ -89,11 +86,14 @@ class UpdateCompany extends Job
|
||||
}
|
||||
|
||||
setting()->save();
|
||||
setting()->forgetAll();
|
||||
});
|
||||
|
||||
event(new CompanyUpdated($this->company, $this->request));
|
||||
|
||||
if (!empty($this->current_company_id)) {
|
||||
company($this->current_company_id)->makeCurrent();
|
||||
}
|
||||
|
||||
return $this->company;
|
||||
}
|
||||
|
||||
@@ -105,14 +105,14 @@ class UpdateCompany extends Job
|
||||
public function authorize()
|
||||
{
|
||||
// Can't disable active company
|
||||
if (($this->request->get('enabled', 1) == 0) && ($this->company->id == $this->active_company_id)) {
|
||||
if (($this->request->get('enabled', 1) == 0) && ($this->company->id == $this->current_company_id)) {
|
||||
$message = trans('companies.error.disable_active');
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
// Check if user can access company
|
||||
if (!$this->isUserCompany($this->company->id)) {
|
||||
if ($this->isNotUserCompany($this->company->id)) {
|
||||
$message = trans('companies.error.not_user_company');
|
||||
|
||||
throw new \Exception($message);
|
||||
|
||||
@@ -77,7 +77,7 @@ class UpdateDashboard extends Job
|
||||
}
|
||||
|
||||
// Check if user can access dashboard
|
||||
if (!$this->isUserDashboard($this->dashboard->id)) {
|
||||
if ($this->isNotUserDashboard($this->dashboard->id)) {
|
||||
$message = trans('dashboards.error.not_user_dashboard');
|
||||
|
||||
throw new \Exception($message);
|
||||
|
||||
Reference in New Issue
Block a user