improved tenant identification
This commit is contained in:
@@ -9,6 +9,16 @@ use Illuminate\View\Factory as ViewFactory;
|
||||
|
||||
class Macro extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
@@ -24,6 +34,59 @@ class Macro extends ServiceProvider
|
||||
return !$this->isApi();
|
||||
});
|
||||
|
||||
Request::macro('isAuth', function () {
|
||||
return $this->is('auth/*');
|
||||
});
|
||||
|
||||
Request::macro('isNotAuth', function () {
|
||||
return !$this->isAuth();
|
||||
});
|
||||
|
||||
Request::macro('isInstall', function () {
|
||||
return $this->is('install/*');
|
||||
});
|
||||
|
||||
Request::macro('isNotInstall', function () {
|
||||
return !$this->isInstall();
|
||||
});
|
||||
|
||||
Request::macro('isSigned', function ($company_id) {
|
||||
return $this->is($company_id . '/signed/*');
|
||||
});
|
||||
|
||||
Request::macro('isNotSigned', function ($company_id) {
|
||||
return !$this->isSigned($company_id);
|
||||
});
|
||||
|
||||
Request::macro('isPortal', function ($company_id) {
|
||||
return $this->is($company_id . '/portal') || $this->is($company_id . '/portal/*');
|
||||
});
|
||||
|
||||
Request::macro('isNotPortal', function ($company_id) {
|
||||
return !$this->isPortal($company_id);
|
||||
});
|
||||
|
||||
Request::macro('isWizard', function ($company_id) {
|
||||
return $this->is($company_id . '/wizard') || $this->is($company_id . '/wizard/*');
|
||||
});
|
||||
|
||||
Request::macro('isNotWizard', function ($company_id) {
|
||||
return !$this->isWizard($company_id);
|
||||
});
|
||||
|
||||
Request::macro('isAdmin', function ($company_id) {
|
||||
return $this->isNotApi()
|
||||
&& $this->isNotAuth()
|
||||
&& $this->isNotInstall()
|
||||
&& $this->isNotSigned($company_id)
|
||||
&& $this->isNotPortal($company_id)
|
||||
&& $this->isNotWizard($company_id);
|
||||
});
|
||||
|
||||
Request::macro('isNotAdmin', function ($company_id) {
|
||||
return !$this->isAdmin($company_id);
|
||||
});
|
||||
|
||||
Str::macro('filename', function ($string, $separator = '-') {
|
||||
// Replace @ with the word 'at'
|
||||
$string = str_replace('@', $separator.'at'.$separator, $string);
|
||||
@@ -47,14 +110,4 @@ class Macro extends ServiceProvider
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,7 @@ use Illuminate\Support\ServiceProvider as Provider;
|
||||
class Observer extends Provider
|
||||
{
|
||||
/**
|
||||
* Register bindings in the container.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Transaction::observe('App\Observers\Transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -26,4 +16,14 @@ class Observer extends Provider
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Transaction::observe('App\Observers\Transaction');
|
||||
}
|
||||
}
|
||||
|
||||
102
app/Providers/Queue.php
Normal file
102
app/Providers/Queue.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Notifications\Common\ImportFailed;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Support\ServiceProvider as Provider;
|
||||
|
||||
class Queue extends Provider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
app('queue')->createPayloadUsing(function ($connection, $queue, $payload) {
|
||||
$company_id = company_id();
|
||||
|
||||
if (empty($company_id)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ['company_id' => $company_id];
|
||||
});
|
||||
|
||||
app('events')->listen(JobProcessing::class, function ($event) {
|
||||
$payload = $event->job->payload();
|
||||
|
||||
if (!array_key_exists('company_id', $payload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$company = company($payload['company_id']);
|
||||
|
||||
if (empty($company)) {
|
||||
$event->job->delete();
|
||||
}
|
||||
|
||||
$company->makeCurrent();
|
||||
});
|
||||
|
||||
app('events')->listen(JobFailed::class, function ($event) {
|
||||
if (!$event->exception instanceof \Maatwebsite\Excel\Validators\ValidationException) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = $event->job->getRawBody();
|
||||
if (empty($body) || !is_string($body)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$payload = json_decode($body);
|
||||
if (empty($payload) || empty($payload->data) || empty($payload->data->command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$excel_job = unserialize($payload->data->command);
|
||||
if (!$excel_job instanceof \Maatwebsite\Excel\Jobs\ReadChunk) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ref = new \ReflectionProperty($excel_job, 'import');
|
||||
$ref->setAccessible(true);
|
||||
|
||||
// Get import class
|
||||
$class = $ref->getValue($excel_job);
|
||||
|
||||
if (!$class instanceof \App\Abstracts\Import) {
|
||||
return;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
foreach ($event->exception->failures() as $failure) {
|
||||
$message = trans('messages.error.import_column', [
|
||||
'message' => collect($failure->errors())->first(),
|
||||
'column' => $failure->attribute(),
|
||||
'line' => $failure->row(),
|
||||
]);
|
||||
|
||||
$errors[] = $message;
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$class->user->notify(new ImportFailed($errors));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,8 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapCommonRoutes()
|
||||
{
|
||||
Facade::middleware('common')
|
||||
Facade::prefix('{company_id}')
|
||||
->middleware('common')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/common.php'));
|
||||
}
|
||||
@@ -120,7 +121,7 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapWizardRoutes()
|
||||
{
|
||||
Facade::prefix('wizard')
|
||||
Facade::prefix('{company_id}/wizard')
|
||||
->middleware('wizard')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/wizard.php'));
|
||||
@@ -135,7 +136,8 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapAdminRoutes()
|
||||
{
|
||||
Facade::middleware('admin')
|
||||
Facade::prefix('{company_id}')
|
||||
->middleware('admin')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/admin.php'));
|
||||
}
|
||||
@@ -149,7 +151,7 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapPortalRoutes()
|
||||
{
|
||||
Facade::prefix('portal')
|
||||
Facade::prefix('{company_id}/portal')
|
||||
->middleware('portal')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/portal.php'));
|
||||
@@ -164,7 +166,7 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapSignedRoutes()
|
||||
{
|
||||
Facade::prefix('signed')
|
||||
Facade::prefix('{company_id}/signed')
|
||||
->middleware('signed')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/signed.php'));
|
||||
|
||||
Reference in New Issue
Block a user