mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Version checking (#3451)
* Ensure NINJA_ENVIRONMENT variable is present in .env file * Implement version checking in app * Remove password protection from check version route
This commit is contained in:
parent
5a7986c23b
commit
a8c15ef1c9
@ -40,9 +40,10 @@ MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
|
||||
MULTI_DB_ENABLED=true
|
||||
POSTMARK_API_TOKEN=
|
||||
|
||||
GOOGLE_MAPS_API_KEY=
|
||||
API_SECRET=superdoopersecrethere
|
||||
ERROR_EMAIL=
|
||||
|
||||
NINJA_ENVIRONMENT=selfhost
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
local_version.txt
|
||||
.env
|
||||
.phpunit.result.cache
|
||||
|
||||
|
1
VERSION.txt
Normal file
1
VERSION.txt
Normal file
@ -0,0 +1 @@
|
||||
0.0.1
|
@ -11,9 +11,10 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\Cron\RecurringInvoicesCron;
|
||||
use App\Jobs\Util\VersionCheck;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use App\Jobs\Cron\RecurringInvoicesCron;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@ -38,6 +39,7 @@ class Kernel extends ConsoleKernel
|
||||
// ->hourly();
|
||||
|
||||
$schedule->job(new RecurringInvoicesCron)->hourly();
|
||||
$schedule->job(new VersionCheck)->daily();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +148,14 @@ class PreviewController extends BaseController
|
||||
$invoice->setRelation('company', auth()->user()->company());
|
||||
$invoice->load('client');
|
||||
|
||||
$invoice_design = new Custom((object)request()->input('body'));
|
||||
\Log::error(print_r(request()->input('body'),1));
|
||||
|
||||
$design_object = json_decode(request()->input('body'));
|
||||
|
||||
if(!is_object($design_object))
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
|
||||
$invoice_design = new Custom($design_object);
|
||||
|
||||
$designer = new Designer($invoice, $invoice_design, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
|
||||
|
||||
|
@ -642,7 +642,10 @@ class QuoteController extends BaseController
|
||||
break;
|
||||
case 'approve':
|
||||
//make sure it hasn't already been approved!!
|
||||
return $quote->service()->approve()->save();
|
||||
if($quote->status_id != Quote::STATUS_SENT)
|
||||
return response()->json(['message' => 'Unable to approve this quote as it has expired.'], 400);
|
||||
|
||||
return $this->itemResponse($quote->service()->approve()->save());
|
||||
break;
|
||||
case 'convert':
|
||||
//convert quote to an invoice make sure we link the two entities!!!
|
||||
|
@ -66,11 +66,13 @@ class SelfUpdateController extends BaseController
|
||||
public function checkVersion(UpdaterManager $updater)
|
||||
{
|
||||
|
||||
//echo $updater->source()->getVersionInstalled();
|
||||
$file_version = storage_path().'app/local_version.txt';
|
||||
|
||||
//echo $updater->source()->isNewVersionAvailable();
|
||||
|
||||
//echo $updater->source()->getVersionAvailable();
|
||||
if(file_exists($file_version)){
|
||||
return response()->json(['message' => file_get_contents($file_version)]);
|
||||
}else{
|
||||
return response()->json(['message' => '0.0.0']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -40,6 +40,9 @@ class StoreCreditRequest extends FormRequest
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if($input['client_id'])
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
|
||||
|
@ -42,6 +42,9 @@ class UpdateCreditRequest extends FormRequest
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ class StoreInvoiceRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if($input['client_id'])
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
|
||||
|
@ -49,6 +49,9 @@ class UpdateInvoiceRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if($input['client_id'])
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
|
||||
|
@ -47,6 +47,9 @@ class UpdateQuoteRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
$input['client_id'] = $this->decodePrimaryKey($input['client_id']);
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
<?php
|
||||
namespace App\Jobs\Account; use App\Events\Account\AccountCreated; use App\Jobs\Company\CreateCompany; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; use App\Models\Account; use App\Models\User; use App\Notifications\Ninja\NewAccountCreated; use App\Utils\Ninja; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use Symfony\Component\HttpFoundation\Response; class CreateAccount { use Dispatchable; protected $request; public function __construct(array $sp660339) { $this->request = $sp660339; } public function handle() { if (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { return response()->json(array('message' => 'Self hosted installation limited to one account'), 400); } elseif (Ninja::boot()) { return response()->json(array('message' => Ninja::parse()), 401); } $sp794f3f = Account::create($this->request); $sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f); $sp035a66->load('account'); $sp794f3f->default_company_id = $sp035a66->id; $sp794f3f->save(); $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); if ($spaa9f78) { auth()->login($spaa9f78, false); } $spaa9f78->setCompany($sp035a66); $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { event(new AccountCreated($spaa9f78)); } $spaa9f78->fresh(); $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); return $sp794f3f; } }
|
||||
namespace App\Jobs\Account; use App\Events\Account\AccountCreated; use App\Jobs\Company\CreateCompany; use App\Jobs\Company\CreateCompanyToken; use App\Jobs\User\CreateUser; use App\Models\Account; use App\Models\User; use App\Notifications\Ninja\NewAccountCreated; use App\Utils\Ninja; use App\Utils\Traits\UserSessionAttributes; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Notification; use Symfony\Component\HttpFoundation\Response; class CreateAccount { use Dispatchable; protected $request; public function __construct(array $sp660339) { $this->request = $sp660339; } public function handle() { if (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { return response()->json(array('message' => Ninja::selfHostedMessage()), 400); } elseif (Ninja::boot()) { return response()->json(array('message' => Ninja::parse()), 401); } $sp794f3f = Account::create($this->request); $sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f); $sp035a66->load('account'); $sp794f3f->default_company_id = $sp035a66->id; $sp794f3f->save(); $spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true); if ($spaa9f78) { auth()->login($spaa9f78, false); } $spaa9f78->setCompany($sp035a66); $spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT'); $sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e); if ($spaa9f78) { event(new AccountCreated($spaa9f78)); } $spaa9f78->fresh(); $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); return $sp794f3f; } }
|
42
app/Jobs/Util/VersionCheck.php
Normal file
42
app/Jobs/Util/VersionCheck.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Util;
|
||||
|
||||
use App\Utils\Traits\BulkOptions;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class VersionCheck implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//$local_version = storage_path() . '/app/local_version.txt';
|
||||
$local_version = 'local_version.txt';
|
||||
|
||||
$version_file = file_get_contents(config('ninja.version_url'));
|
||||
|
||||
if(Storage::exists($local_version));
|
||||
Storage::delete($local_version);
|
||||
|
||||
Storage::disk('local')->put('local_version.txt', $version_file);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -62,6 +62,8 @@ class Credit extends BaseModel
|
||||
'line_items',
|
||||
'client_id',
|
||||
'footer',
|
||||
'design_id',
|
||||
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -95,6 +95,7 @@ class Invoice extends BaseModel
|
||||
'custom_surcharge_tax2',
|
||||
'custom_surcharge_tax3',
|
||||
'custom_surcharge_tax4',
|
||||
'design_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -64,6 +64,7 @@ class Quote extends BaseModel
|
||||
'line_items',
|
||||
'client_id',
|
||||
'footer',
|
||||
'design_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -86,9 +86,6 @@ class QuoteService
|
||||
public function approve() :QuoteService
|
||||
{
|
||||
|
||||
if($this->quote->status_id != Quote::STATUS_SENT)
|
||||
return response()->json(['message' => 'Unable to approve this quote as it has expired.'], 400);
|
||||
|
||||
$this->setStatus(Quote::STATUS_APPROVED)->save();
|
||||
|
||||
$invoice = null;
|
||||
|
@ -80,7 +80,7 @@ class CreditTransformer extends EntityTransformer
|
||||
'balance' => (float) $credit->balance,
|
||||
'client_id' => (string) $this->encodePrimaryKey($credit->client_id),
|
||||
'status_id' => (string) ($credit->status_id ?: 1),
|
||||
'design_id' => (string) ($credit->design_id ?: 1),
|
||||
'design_id' => (string) $this->encodePrimaryKey($credit->design_id),
|
||||
'invoice_id' => (string) ($credit->invoice_id ?: 1),
|
||||
'updated_at' => (int)$credit->updated_at,
|
||||
'archived_at' => (int)$credit->deleted_at,
|
||||
|
@ -90,7 +90,7 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'client_id' => (string) $this->encodePrimaryKey($invoice->client_id),
|
||||
'vendor_id' => (string) $this->encodePrimaryKey($invoice->vendor_id),
|
||||
'status_id' => (string) ($invoice->status_id ?: 1),
|
||||
'design_id' => (string) ($invoice->design_id ?: 1),
|
||||
'design_id' => (string) $this->encodePrimaryKey($invoice->design_id),
|
||||
'created_at' => (int)$invoice->created_at,
|
||||
'updated_at' => (int)$invoice->updated_at,
|
||||
'archived_at' => (int)$invoice->deleted_at,
|
||||
|
@ -80,7 +80,7 @@ class QuoteTransformer extends EntityTransformer
|
||||
'balance' => (float) $quote->balance,
|
||||
'client_id' => (string) $this->encodePrimaryKey($quote->client_id),
|
||||
'status_id' => (string)$quote->status_id,
|
||||
'design_id' => (string)$quote->design_id,
|
||||
'design_id' => (string) $this->encodePrimaryKey($quote->design_id),
|
||||
'invoice_id' => (string)$quote->invoice_id,
|
||||
'updated_at' => (int)$quote->updated_at,
|
||||
'archived_at' => (int)$quote->deleted_at,
|
||||
|
@ -67,4 +67,9 @@ class Ninja
|
||||
{
|
||||
return 'Invalid license.';
|
||||
}
|
||||
|
||||
public static function selfHostedMessage()
|
||||
{
|
||||
return 'Self hosted installation limited to one account';
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ return [
|
||||
'production' => env('NINJA_PROD', false),
|
||||
'license' => env('NINJA_LICENSE', ''),
|
||||
'app_name' => env('APP_NAME'),
|
||||
'version_url' => 'https://github.com/invoiceninja/invoiceninja/tree/v2/VERSION.txt',
|
||||
'site_url' => env('APP_URL', ''),
|
||||
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
|
||||
'app_version' => '0.0.1',
|
||||
|
@ -121,7 +121,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
|
||||
Route::post('self-update', 'SelfUpdateController@update')->middleware('password_protected');
|
||||
|
||||
Route::post('self-update/check_version', 'SelfUpdateController@checkVersion')->middleware('password_protected');
|
||||
Route::post('self-update/check_version', 'SelfUpdateController@checkVersion');
|
||||
|
||||
/*
|
||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||
|
Loading…
x
Reference in New Issue
Block a user