mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #4863 from turbo124/v5-develop
Google Authentication
This commit is contained in:
commit
1d7717888a
@ -49,19 +49,26 @@ class DesignUpdate extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//always return state to first DB
|
||||
|
||||
$current_db = config('database.default');
|
||||
|
||||
if (! config('ninja.db.multi_db_enabled')) {
|
||||
$this->handleOnDb();
|
||||
} else {
|
||||
|
||||
//multiDB environment, need to
|
||||
foreach (MultiDB::$dbs as $db) {
|
||||
MultiDB::setDB($db);
|
||||
|
||||
$this->handleOnDb($db);
|
||||
}
|
||||
|
||||
MultiDB::setDB($current_db);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function handleOnDb()
|
||||
|
@ -289,7 +289,7 @@ class LoginController extends BaseController
|
||||
$client = new Google_Client();
|
||||
$client->setClientId(config('ninja.auth.google.client_id'));
|
||||
$client->setClientSecret(config('ninja.auth.google.client_secret'));
|
||||
|
||||
$client->setRedirectUri(config('ninja.app_url'));
|
||||
$token = $client->authenticate(request()->input('server_auth_code'));
|
||||
|
||||
$refresh_token = '';
|
||||
|
@ -25,6 +25,7 @@ use Illuminate\Queue\Middleware\RateLimited;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Turbo124\Beacon\Jobs\Database\MySQL\DbStatus;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class CheckCompanyData implements ShouldQueue
|
||||
{
|
||||
@ -36,6 +37,7 @@ class CheckCompanyData implements ShouldQueue
|
||||
|
||||
public $company_data = [];
|
||||
|
||||
public $is_valid;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -54,6 +56,7 @@ class CheckCompanyData implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->is_valid = true;
|
||||
|
||||
$this->checkInvoiceBalances();
|
||||
$this->checkInvoicePayments();
|
||||
@ -68,15 +71,14 @@ class CheckCompanyData implements ShouldQueue
|
||||
else
|
||||
$cache_instance = Cache::add($this->hash, '');
|
||||
|
||||
$cache_instance[$this->company->company_hash] = $this->company_data;
|
||||
$this->company_data['company_hash'] = $this->company->company_hash;
|
||||
|
||||
Cache::put($this->hash, $cache_instance, now()->addMinutes(30));
|
||||
|
||||
nlog(Cache::get($this->hash));
|
||||
|
||||
nlog($this->company_data);
|
||||
|
||||
if(!$this->isValid)
|
||||
if(!$this->is_valid)
|
||||
$this->company_data['status'] = 'errors';
|
||||
else
|
||||
$this->company_data['status'] = 'success';
|
||||
@ -109,13 +111,13 @@ class CheckCompanyData implements ShouldQueue
|
||||
|
||||
$wrong_balances++;
|
||||
|
||||
$this->company_data[] = "# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance} \n";
|
||||
$this->company_data[] = "# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance} ";
|
||||
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->company_data[] = "{$wrong_balances} clients with incorrect balances\n";
|
||||
$this->company_data[] = "{$wrong_balances} clients with incorrect balances";
|
||||
}
|
||||
|
||||
private function checkInvoicePayments()
|
||||
@ -135,14 +137,14 @@ class CheckCompanyData implements ShouldQueue
|
||||
if ((string)$total_paid != (string)($invoice->amount - $invoice->balance - $total_credit)) {
|
||||
$wrong_balances++;
|
||||
|
||||
$this->company_data[] = $client->present()->name.' - '.$client->id." - Total Amount = {$total_amount} != Calculated Total = {$calculated_paid_amount} - Total Refund = {$total_refund} Total credit = {$total_credit}\n";
|
||||
$this->company_data[] = $client->present()->name.' - '.$client->id." - Total Amount = {$total_amount} != Calculated Total = {$calculated_paid_amount} - Total Refund = {$total_refund} Total credit = {$total_credit}";
|
||||
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances\n";
|
||||
$this->company_data[] = "{$wrong_balances} clients with incorrect invoice balances";
|
||||
}
|
||||
|
||||
private function checkPaidToDates()
|
||||
@ -176,9 +178,9 @@ class CheckCompanyData implements ShouldQueue
|
||||
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
|
||||
$wrong_paid_to_dates++;
|
||||
|
||||
$this->company_data[] = $client->present()->name.'id = # '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}\n";
|
||||
$this->company_data[] = $client->present()->name.'id = # '.$client->id." - Paid to date does not match Client Paid To Date = {$client->paid_to_date} - Invoice Payments = {$total_invoice_payments}";
|
||||
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
});
|
||||
|
||||
@ -206,13 +208,13 @@ class CheckCompanyData implements ShouldQueue
|
||||
if ($ledger && (string) $invoice_balance != (string) $client->balance) {
|
||||
$wrong_paid_to_dates++;
|
||||
|
||||
$this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0')."\n";
|
||||
$this->company_data[] = $client->present()->name.' - '.$client->id." - calculated client balances do not match {$invoice_balance} - ".rtrim($client->balance, '0')."";
|
||||
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances\n";
|
||||
$this->company_data[] = "{$wrong_paid_to_dates} clients with incorrect client balances";
|
||||
}
|
||||
|
||||
private function checkContacts()
|
||||
@ -224,10 +226,10 @@ class CheckCompanyData implements ShouldQueue
|
||||
->orderBy('id')
|
||||
->get(['id']);
|
||||
|
||||
$this->company_data[] = $contacts->count().' contacts without a contact_key\n';
|
||||
$this->company_data[] = $contacts->count().' contacts without a contact_key';
|
||||
|
||||
if ($contacts->count() > 0) {
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
|
||||
// if ($this->option('fix') == 'true') {
|
||||
@ -244,7 +246,7 @@ class CheckCompanyData implements ShouldQueue
|
||||
|
||||
// check for missing contacts
|
||||
$clients = DB::table('clients')
|
||||
->where('company_id', $this->company->id)
|
||||
->where('clients.company_id', $this->company->id)
|
||||
->leftJoin('client_contacts', function ($join) {
|
||||
$join->on('client_contacts.client_id', '=', 'clients.id')
|
||||
->whereNull('client_contacts.deleted_at');
|
||||
@ -258,10 +260,10 @@ class CheckCompanyData implements ShouldQueue
|
||||
|
||||
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']);
|
||||
|
||||
$this->company_data[] = $clients->count().' clients without any contacts\n';
|
||||
$this->company_data[] = $clients->count().' clients without any contacts';
|
||||
|
||||
if ($clients->count() > 0) {
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
|
||||
// if ($this->option('fix') == 'true') {
|
||||
@ -293,10 +295,10 @@ class CheckCompanyData implements ShouldQueue
|
||||
// }
|
||||
|
||||
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]);
|
||||
$this->company_data[] = $clients->count().' clients without a single primary contact\n';
|
||||
$this->company_data[] = $clients->count().' clients without a single primary contact';
|
||||
|
||||
if ($clients->count() > 0) {
|
||||
$this->isValid = false;
|
||||
$this->is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,11 +337,20 @@ class CheckCompanyData implements ShouldQueue
|
||||
->get(["{$table}.id"]);
|
||||
|
||||
if ($records->count()) {
|
||||
$this->isValid = false;
|
||||
$this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id\n";
|
||||
$this->is_valid = false;
|
||||
$this->company_data[] = $records->count()." {$table} records with incorrect {$entityType} company id";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function pluralizeEntityType($type)
|
||||
{
|
||||
if ($type === 'company') {
|
||||
return 'companies';
|
||||
}
|
||||
|
||||
return $type.'s';
|
||||
}
|
||||
}
|
||||
|
@ -210,12 +210,11 @@ class Import implements ShouldQueue
|
||||
// $this->fixClientBalances();
|
||||
$check_data = CheckCompanyData::dispatchNow($this->company, md5(time()));
|
||||
|
||||
|
||||
if($check_data['status'] == 'errors')
|
||||
throw new ProcessingMigrationArchiveFailed($check_data);
|
||||
// if($check_data['status'] == 'errors')
|
||||
// throw new ProcessingMigrationArchiveFailed(implode("\n", $check_data));
|
||||
|
||||
Mail::to($this->user)
|
||||
->send(new MigrationCompleted($this->company, $check_data));
|
||||
->send(new MigrationCompleted($this->company, implode("<br>",$check_data)));
|
||||
|
||||
/*After a migration first some basic jobs to ensure the system is up to date*/
|
||||
VersionCheck::dispatch();
|
||||
|
@ -34,7 +34,7 @@ class MigrationCompleted extends Mailable
|
||||
public function build()
|
||||
{
|
||||
$data['settings'] = $this->company->settings;
|
||||
$data['company'] = $this->company;
|
||||
$data['company'] = $this->company->fresh();
|
||||
$data['whitelabel'] = $this->company->account->isPaid() ? true : false;
|
||||
$data['check_data'] = $this->check_data;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||
<env name="MAIL_MAILER" value="array"/>
|
||||
<env name="DB_CONNECTION" value="sqlite"/>
|
||||
<env name="DB_CONNECTION" value="mysql"/>
|
||||
<env name="DB_DATABASE" value=":memory:"/>
|
||||
</php>
|
||||
<logging/>
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
<p><img src="{{ $company->present()->logo() }}"></p>
|
||||
|
||||
@if(isset($company) && count($company->clients) >=1)
|
||||
<p><b>Clients Imported:</b> {{ count($company->clients) }} </p>
|
||||
@if(isset($company) && $company->clients->count() >=1)
|
||||
<p><b>Clients Imported:</b> {{ $company->clients->count() }} </p>
|
||||
@endif
|
||||
|
||||
@if(isset($company) && count($company->products) >=1)
|
||||
@ -75,7 +75,7 @@
|
||||
|
||||
<p><b>Data Quality:</b></p>
|
||||
|
||||
<p> {{ $check_data }} </p>
|
||||
<p> {!! $check_data !!} </p>
|
||||
|
||||
<a href="{{ url('/') }}" target="_blank" class="button">{{ ctrans('texts.account_login')}}</a>
|
||||
|
||||
|
@ -34,6 +34,7 @@ class InvitationTest extends TestCase
|
||||
|
||||
public function testInvitationSanity()
|
||||
{
|
||||
|
||||
$this->assertEquals($this->invoice->invitations->count(), 2);
|
||||
|
||||
$invitations = $this->invoice->invitations()->get();
|
||||
@ -46,11 +47,20 @@ class InvitationTest extends TestCase
|
||||
|
||||
$this->invoice->line_items = [];
|
||||
|
||||
$response = null;
|
||||
|
||||
try {
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $this->invoice->toArray())
|
||||
->assertStatus(200);
|
||||
])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $this->invoice->toArray());
|
||||
} catch (\Exception $e) {
|
||||
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user