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

Merge pull request #5008 from turbo124/v5-stable

v5.1.12
This commit is contained in:
David Bomba 2021-03-01 22:00:53 +11:00 committed by GitHub
commit 52bf4afd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 167 additions and 26 deletions

View File

@ -1 +1 @@
5.1.11
5.1.12

View File

@ -286,11 +286,25 @@ class LoginController extends BaseController
}
if ($user) {
$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'));
$token = false;
try{
$token = $client->authenticate(request()->input('server_auth_code'));
}
catch(\Exception $e) {
return response()
->json(['message' => ctrans('texts.invalid_credentials')], 401)
->header('X-App-Version', config('ninja.app_version'))
->header('X-Api-Version', config('ninja.minimum_client_version'));
}
$refresh_token = '';

View File

@ -33,10 +33,12 @@ class SetEmailDb
];
if ($request->input('email') && config('ninja.db.multi_db_enabled')) {
nlog("trying to find db");
if (! MultiDB::userFindAndSetDb($request->input('email'))) {
if (! MultiDB::userFindAndSetDb($request->input('email')))
return response()->json($error, 400);
}
}
// else {
// return response()->json($error, 403);

View File

@ -13,6 +13,7 @@ namespace App\Http\Middleware;
use App\Libraries\MultiDB;
use App\Models\User;
use App\Utils\Ninja;
use Closure;
use Hashids\Hashids;
use Illuminate\Http\Request;
@ -26,7 +27,7 @@ class UserVerified
public function __construct(?User $user)
{
$this->user = $user ?: auth()->user();
$this->user = property_exists($user, 'id') ? $user : auth()->user();
}
/**
@ -38,6 +39,8 @@ class UserVerified
*/
public function handle($request, Closure $next)
{
if(Ninja::isSelfHost())
return $next($request);
$error = [
'message' => 'Email confirmation required.',

View File

@ -92,6 +92,8 @@ class CreateEntityPdf implements ShouldQueue
App::forgetInstance('translator');
Lang::replace(Ninja::transformTranslations($this->entity->client->getMergedSettings()));
$this->entity->service()->deletePdf();
if (config('ninja.phantomjs_pdf_generation')) {
return (new Phantom)->generate($this->invitation);
}

View File

@ -39,6 +39,8 @@ class UnlinkFile implements ShouldQueue
*/
public function handle()
{
// nlog("deleting");
// nlog($this->file_path);
Storage::disk($this->disk)->delete($this->file_path);
}
}

View File

@ -187,9 +187,10 @@ class MultiDB
//multi-db active
foreach (self::$dbs as $db) {
if (User::on($db)->where(['email' => $email])->get()->count() >= 1) { // if user already exists, validation will fail
if (User::on($db)->where(['email' => $email])->count() >= 1)
return true;
}
}
return false;

View File

@ -89,7 +89,9 @@ class CreditEmailEngine extends BaseEmailEngine
->setInvitation($this->invitation);
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);
$this->setAttachments([$this->credit->pdf_file_path()]);
// $this->setAttachments(['path' => $this->credit->pdf_file_path(), 'name' => basename($this->credit->pdf_file_path())]);
}
//attach third party documents

View File

@ -90,8 +90,8 @@ class QuoteEmailEngine extends BaseEmailEngine
if ($this->client->getSetting('pdf_email_attachment') !== false) {
// $this->setAttachments([$this->quote->pdf_file_path()]);
$this->setAttachments(['path' => $this->quote->pdf_file_path(), 'name' => basename($this->quote->pdf_file_path())]);
$this->setAttachments([$this->quote->pdf_file_path()]);
//$this->setAttachments(['path' => $this->quote->pdf_file_path(), 'name' => basename($this->quote->pdf_file_path())]);
}

View File

@ -85,6 +85,7 @@ class Company extends BaseModel
'expense_inclusive_taxes',
'session_timeout',
'oauth_password_required',
'invoice_task_datelog',
];
protected $hidden = [

View File

@ -36,7 +36,11 @@ class CompanyPresenter extends EntityPresenter
$settings = $this->entity->settings;
}
return (strlen($settings->company_logo) > 0) ? url('') . $settings->company_logo : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
if(strlen($settings->company_logo))
return asset($settings->company_logo);
else
return 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
}
public function address($settings = null)
@ -91,13 +95,13 @@ class CompanyPresenter extends EntityPresenter
}
}
public function getSpcQrCode($client_currency, $invoice_number, $balance)
public function getSpcQrCode($client_currency, $invoice_number, $balance_due_raw)
{
$settings = $this->entity->settings;
return
"SPC\n0200\n1\nCH860021421411198240K\nK\n{$this->name}\n{$settings->address1}\n{$settings->postal_code} {$settings->city}\n\n\nCH\n\n\n\n\n\n\n\n{$balance}\n{$client_currency}\n\n\n\n\n\n\n\nNON\n\n{$invoice_number}\nEPD\n";
"SPC\n0200\n1\nCH860021421411198240K\nK\n{$this->name}\n{$settings->address1}\n{$settings->postal_code} {$settings->city}\n\n\nCH\n\n\n\n\n\n\n\n{$balance_due_raw}\n{$client_currency}\n\n\n\n\n\n\n\nNON\n\n{$invoice_number}\nEPD\n";
}
}

View File

@ -200,25 +200,27 @@ class Quote extends BaseModel
return new QuoteService($this);
}
public function pdf_file_path($invitation = null, string $type = 'url')
{
if (! $invitation) {
$invitation = $this->invitations->where('client_contact_id', $this->client->primary_contact()->first()->id)->first();
$invitation = $this->invitations->first();
}
$storage_path = Storage::$type($this->client->quote_filepath().$this->number.'.pdf');
if (Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
return $storage_path;
nlog($storage_path);
if (! Storage::exists($this->client->quote_filepath().$this->number.'.pdf')) {
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($invitation);
}
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
CreateEntityPdf::dispatchNow($invitation);
return $storage_path;
}
/**
* @param int $status
* @return string

View File

@ -37,7 +37,7 @@ class CreditObserver
*/
public function updated(Credit $credit)
{
UnlinkFile::dispatchNow(config('filesystems.default'), $credit->client->credit_filepath() . $credit->number.'.pdf');
}
/**

View File

@ -51,8 +51,6 @@ class QuoteObserver
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
}
UnlinkFile::dispatchNow(config('filesystems.default'), $quote->client->quote_filepath() . $quote->number.'.pdf');
}
/**

View File

@ -11,6 +11,7 @@
namespace App\Services\Credit;
use App\Jobs\Util\UnlinkFile;
use App\Models\Credit;
use App\Utils\Traits\MakesHash;
@ -134,7 +135,14 @@ class CreditService
return $this;
}
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->credit->client->credit_filepath() . $this->credit->number.'.pdf');
return $this;
}
/**
* Saves the credit.
* @return Credit object

View File

@ -12,6 +12,7 @@
namespace App\Services\Quote;
use App\Events\Quote\QuoteWasApproved;
use App\Jobs\Util\UnlinkFile;
use App\Models\Invoice;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
@ -189,6 +190,13 @@ class QuoteService
return $this;
}
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->quote->client->quote_filepath() . $this->quote->number.'.pdf');
return $this;
}
/**
* Saves the quote.
* @return Quote|null

View File

@ -11,6 +11,7 @@
namespace App\Services\Recurring;
use App\Jobs\Util\UnlinkFile;
use App\Models\RecurringInvoice;
use App\Services\Recurring\GetInvoicePdf;
use Illuminate\Support\Carbon;
@ -84,6 +85,13 @@ class RecurringService
return (new GetInvoicePdf($this->recurring_entity, $contact))->run();
}
public function deletePdf()
{
UnlinkFile::dispatchNow(config('filesystems.default'), $this->recurring_entity->client->recurring_invoice_filepath() . $this->recurring_entity->number.'.pdf');
return $this;
}
public function save()
{
$this->recurring_entity->save();

View File

@ -13,7 +13,7 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', ''),
'app_version' => '5.1.11',
'app_version' => '5.1.12',
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false),

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddInvoiceTaskDatelogProperty extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function(Blueprint $table){
$table->boolean('invoice_task_datelog')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
/**
* @test
*/
class RangeDetectionTest extends TestCase
{
public function setUp() :void
{
parent::setUp();
}
public function test_range_detection()
{
$ranges = [];
$ranges[] = [100, 105];
$ranges[] = [106, 110];
$ranges[] = [110, 115];
$expanded_ranges = [];
foreach($ranges as $range)
{
$expanded_ranges = array_merge(array_values($expanded_ranges),array_values($this->makeRanges($range)));
}
$value_count_array = array_count_values($expanded_ranges);
$value_count_array = array_diff($value_count_array, [1]);
$this->assertEquals(count($value_count_array), 1);
}
private function makeRanges(array $range)
{
return range($range[0], $range[1]);
}
}