1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge pull request #4427 from beganovich/v5-4425

(v5) Fix issue with multiple companies showing in dropdown
This commit is contained in:
Benjamin Beganović 2020-12-03 15:34:44 +01:00 committed by GitHub
commit 791111b3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 74 additions and 27 deletions

View File

@ -19,7 +19,6 @@ use App\Exceptions\ResourceDependencyMissing;
use App\Exceptions\ResourceNotAvailableForMigration;
use App\Jobs\Util\Import;
use App\Jobs\Util\StartMigration;
use App\Libraries\MultiDB;
use App\Mail\MigrationFailed;
use App\Models\Account;
use App\Models\Company;
@ -85,7 +84,6 @@ class ImportMigrations extends Command
foreach ($directory as $file) {
if ($file->getExtension() === 'zip') {
$user = $this->getUser();
$company = $this->getUser()->companies()->first();
@ -99,24 +97,24 @@ class ImportMigrations extends Command
throw new ProcessingMigrationArchiveFailed('Processing migration archive failed. Migration file is possibly corrupted.');
}
$filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME);
$filename = pathinfo($file->getRealPath(), PATHINFO_FILENAME);
$zip->extractTo(public_path("storage/migrations/{$filename}"));
$zip->close();
$zip->extractTo(public_path("storage/migrations/{$filename}"));
$zip->close();
$import_file = public_path("storage/migrations/$filename/migration.json");
$import_file = public_path("storage/migrations/$filename/migration.json");
Import::dispatch($import_file, $this->getUser()->companies()->first(), $this->getUser());
// StartMigration::dispatch($file->getRealPath(), $this->getUser(), $this->getUser()->companies()->first());
Import::dispatch($import_file, $this->getUser()->companies()->first(), $this->getUser());
// StartMigration::dispatch($file->getRealPath(), $this->getUser(), $this->getUser()->companies()->first());
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
\Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
if (app()->environment() !== 'production') {
info($e->getMessage());
}
}
catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
\Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
if (app()->environment() !== 'production') {
info($e->getMessage());
}
}}}
}
}
}
public function getUser(): User

View File

@ -13,6 +13,7 @@ namespace App\Http;
use App\Http\Middleware\ApiSecretCheck;
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\CheckClientExistence;
use App\Http\Middleware\CheckForMaintenanceMode;
use App\Http\Middleware\ClientPortalEnabled;
use App\Http\Middleware\ContactKeyLogin;
@ -155,5 +156,6 @@ class Kernel extends HttpKernel
'shop_token_auth' => ShopTokenAuth::class,
'phantom_secret' => PhantomSecret::class,
'contact_key_login' => ContactKeyLogin::class,
'check_client_existence' => CheckClientExistence::class,
];
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Middleware;
use App\Models\ClientContact;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class CheckClientExistence
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$multiple_contacts = ClientContact::query()
->where('email', auth('contact')->user()->email)
->whereNotNull('email')
->distinct('company_id')
->whereHas('client', function ($query) {
return $query->whereNull('deleted_at');
})
->get();
if (count($multiple_contacts) == 0) {
Auth::logout();
return redirect()->route('client.login');
}
if (count($multiple_contacts) == 1) {
Auth::guard('contact')->login($multiple_contacts[0], true);
}
session()->put('multiple_contacts', $multiple_contacts);
return $next($request);
}
}

View File

@ -11,7 +11,6 @@
namespace App\Http\ViewComposers;
use App\Models\ClientContact;
use App\Utils\Ninja;
use App\Utils\TranslationHelper;
use Illuminate\Support\Facades\Lang;
@ -55,7 +54,7 @@ class PortalComposer
$data['settings'] = auth()->user()->client->getMergedSettings();
$data['currencies'] = TranslationHelper::getCurrencies();
$data['multiple_contacts'] = ClientContact::where('email', auth('contact')->user()->email)->whereNotNull('email')->distinct('company_id')->get();
$data['multiple_contacts'] = session()->get('multiple_contacts');
return $data;
}

View File

@ -30,7 +30,6 @@ class DownloadInvoices extends Mailable
*/
public function build()
{
return $this->from(config('mail.from.name'), config('mail.from.address'))
->subject(ctrans('texts.download_files'))
->markdown(

View File

@ -83,7 +83,6 @@ class BaseEmailEngine implements EngineInterface
public function setAttachments($attachments)
{
$this->attachments = array_merge($this->getAttachments(), $attachments);
return $this;

View File

@ -27,7 +27,6 @@ class ExistingMigration extends Mailable
*/
public function build()
{
return $this->from(config('mail.from.name'), config('mail.from.address'))
->view('email.migration.existing');
}

View File

@ -31,7 +31,6 @@ class MigrationFailed extends Mailable
*/
public function build()
{
return $this->from(config('mail.from.name'), config('mail.from.address'))
->view('email.migration.failed');
}

View File

@ -105,7 +105,7 @@ class CreditCard
}
private function attemptPaymentUsingCreditCard(PaymentResponseRequest $request)
{
{
$checkout_response = $this->checkout->payment_hash->data->server_response;
$method = new TokenSource(

View File

@ -73,7 +73,6 @@ class RefundPayment
{
if ($this->refund_data['gateway_refund'] !== false && $this->total_refund > 0) {
if ($this->payment->company_gateway) {
$response = $this->payment->company_gateway->driver($this->payment->client)->refund($this->payment, $this->total_refund);
$this->payment->refunded += $this->total_refund;
@ -84,7 +83,6 @@ class RefundPayment
$this->payment->save();
throw new PaymentRefundFailed();
}
}
} else {
$this->payment->refunded += $this->total_refund;

View File

@ -23,7 +23,7 @@ return [
'date_time_format' => 'Y-m-d H:i',
'daily_email_limit' => 300,
'error_email' => env('ERROR_EMAIL', ''),
'mailer' => env('MAIL_MAILER',''),
'mailer' => env('MAIL_MAILER', ''),
'company_id' => 0,
'hash_salt' => env('HASH_SALT', ''),
'currency_converter_api_key' => env('OPENEXCHANGE_APP_ID', ''),

View File

@ -24,7 +24,7 @@ Route::get('tmp_pdf/{hash}', 'ClientPortal\TempRouteController@index')->name('tm
Route::get('client/key_login/{contact_key}', 'ClientPortal\ContactHashLoginController@login')->name('client.contact_login')->middleware(['contact_key_login']);
//todo implement domain DB
Route::group(['middleware' => ['auth:contact', 'locale'], 'prefix' => 'client', 'as' => 'client.'], function () {
Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence'], 'prefix' => 'client', 'as' => 'client.'], function () {
Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit
Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index')->middleware('portal_enabled');