1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00

Merge branch 'v5-develop' into v5-stable

This commit is contained in:
David Bomba 2021-05-31 17:18:46 +10:00
commit f5e718fcd4
12 changed files with 1129 additions and 80 deletions

View File

@ -1 +1 @@
5.1.66 5.1.67

View File

@ -12,12 +12,12 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Jobs\Ninja\SendReminders; use App\Jobs\Ninja\SendReminders;
use App\Jobs\Util\WebHookHandler;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Quote; use App\Models\Quote;
use App\Models\Webhook; use App\Models\Webhook;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Jobs\Util\WebhookHandler;
class SendRemindersCron extends Command class SendRemindersCron extends Command
{ {
@ -90,6 +90,7 @@ class SendRemindersCron extends Command
$invoices->each(function ($invoice) { $invoices->each(function ($invoice) {
WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company);
}); });
$quotes = Quote::where('is_deleted', 0) $quotes = Quote::where('is_deleted', 0)

View File

@ -245,8 +245,8 @@ class CompanySettings extends BaseSettings
public $hide_paid_to_date = false; //@TODO where? public $hide_paid_to_date = false; //@TODO where?
public $embed_documents = false; //@TODO where? public $embed_documents = false; //@TODO where?
public $all_pages_header = false; //@implemented public $all_pages_header = false; //@deprecated 31-05-2021
public $all_pages_footer = false; //@implemented public $all_pages_footer = false; //@deprecated 31-05-2021
public $pdf_variables = ''; //@implemented public $pdf_variables = ''; //@implemented
public $portal_custom_head = ''; //@TODO @BEN public $portal_custom_head = ''; //@TODO @BEN

View File

@ -585,4 +585,61 @@ class ClientController extends BaseController
} }
/**
* Update the specified resource in storage.
*
* @param UploadClientRequest $request
* @param Client $client
* @return Response
*
*
*
* @OA\Put(
* path="/api/v1/clients/{id}/adjust_ledger",
* operationId="adjustLedger",
* tags={"clients"},
* summary="Adjust the client ledger to rebalance",
* description="Adjust the client ledger to rebalance",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Client Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the client object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Client"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function adjustLedger(Request $request, Client $client)
{
}
} }

View File

@ -11,10 +11,13 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Requests\Export\StoreExportRequest; use App\Http\Requests\Import\ImportJsonRequest;
use App\Jobs\Company\CompanyExport; use App\Jobs\Company\CompanyExport;
use App\Jobs\Company\CompanyImport;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
class ImportJsonController extends BaseController class ImportJsonController extends BaseController
{ {
@ -53,12 +56,41 @@ class ImportJsonController extends BaseController
* ), * ),
* ) * )
*/ */
public function index(StoreExportRequest $request) public function index(ImportJsonRequest $request)
{ {
// CompanyExport::dispatch(auth()->user()->getCompany(), auth()->user()); $import_file = $request->file('files');
$contents = $this->unzipFile($import_file->getPathname());
$hash = Str::random(32);
Cache::put( $hash, base64_encode( $contents ), 3600 );
CompanyImport::dispatch(auth()->user()->getCompany(), auth()->user(), $hash, $request->all());
return response()->json(['message' => 'Processing'], 200); return response()->json(['message' => 'Processing'], 200);
} }
private function unzipFile($file_contents)
{
$zip = new ZipArchive();
$archive = $zip->open($file_contents);
$filename = pathinfo($file_contents, PATHINFO_FILENAME);
$zip->extractTo(public_path("storage/backups/{$filename}"));
$zip->close();
$file_location = public_path("storage/backups/$filename/backup.json");
if (! file_exists($file_location))
throw new NonExistingMigrationFile('Backup file does not exist, or it is corrupted.');
$data = json_decode(file_get_contents($file_location));
unlink($file_contents);
unlink($file_location);
return $data
}
} }

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 App\Http\Requests\Client;
use App\Http\Requests\Request;
use App\Utils\Traits\MakesHash;
use Illuminate\Validation\Rule;
class AdjustClientLedgerRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->client);
}
public function rules()
{
/* Ensure we have a client name, and that all emails are unique*/
$rules = [];
return $rules;
}
public function messages()
{
return [
];
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
}

View File

@ -0,0 +1,39 @@
<?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 App\Http\Requests\Import;
use App\Http\Requests\Request;
class ImportJsonRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
public function rules()
{
return [
// 'import_type' => 'required',
// 'files' => 'required_without:hash|array|min:1|max:6',
// 'hash' => 'nullable|string',
// 'column_map' => 'required_with:hash|array',
// 'skip_header' => 'required_with:hash|boolean',
// 'files.*' => 'file|mimes:csv,txt',
];
}
}

File diff suppressed because it is too large Load Diff

View File

@ -35,9 +35,9 @@ class WebhookHandler implements ShouldQueue
private $company; private $company;
public $tries = 5; //number of retries public $tries = 3; //number of retries
public $backoff = 5; //seconds to wait until retry public $backoff = 10; //seconds to wait until retry
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;

View File

@ -14,8 +14,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => '5.1.66', 'app_version' => '5.1.67',
'app_tag' => '5.1.66-release', 'app_tag' => '5.1.67-release',
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', ''), 'api_secret' => env('API_SECRET', ''),

View File

@ -34,6 +34,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
Route::post('claim_license', 'LicenseController@index')->name('license.index'); Route::post('claim_license', 'LicenseController@index')->name('license.index');
Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit
Route::put('clients/{client}/adjust_ledger', 'ClientController@adjustLedger')->name('clients.adjust_ledger');
Route::put('clients/{client}/upload', 'ClientController@upload')->name('clients.upload'); Route::put('clients/{client}/upload', 'ClientController@upload')->name('clients.upload');
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk'); Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');

View File

@ -283,7 +283,6 @@ class ImportCompanyTest extends TestCase
$obj_array = (array)$obj; $obj_array = (array)$obj;
unset($obj_array['user_id']); unset($obj_array['user_id']);
unset($obj_array['company_id']); unset($obj_array['company_id']);
unset($obj_array['account_id']);
unset($obj_array['hashed_id']); unset($obj_array['hashed_id']);
unset($obj_array['id']); unset($obj_array['id']);
unset($obj_array['tax_rate_id']); unset($obj_array['tax_rate_id']);
@ -315,10 +314,8 @@ class ImportCompanyTest extends TestCase
$obj_array = (array)$obj; $obj_array = (array)$obj;
unset($obj_array['user_id']); unset($obj_array['user_id']);
unset($obj_array['company_id']); unset($obj_array['company_id']);
unset($obj_array['account_id']);
unset($obj_array['hashed_id']); unset($obj_array['hashed_id']);
unset($obj_array['id']); unset($obj_array['id']);
unset($obj_array['tax_rate_id']);
$new_obj = ExpenseCategory::firstOrNew( $new_obj = ExpenseCategory::firstOrNew(
['name' => $obj->name, 'company_id' => $this->company->id], ['name' => $obj->name, 'company_id' => $this->company->id],
@ -348,10 +345,8 @@ class ImportCompanyTest extends TestCase
$obj_array = (array)$obj; $obj_array = (array)$obj;
unset($obj_array['user_id']); unset($obj_array['user_id']);
unset($obj_array['company_id']); unset($obj_array['company_id']);
unset($obj_array['account_id']);
unset($obj_array['hashed_id']); unset($obj_array['hashed_id']);
unset($obj_array['id']); unset($obj_array['id']);
unset($obj_array['tax_rate_id']);
$new_obj = TaskStatus::firstOrNew( $new_obj = TaskStatus::firstOrNew(
['name' => $obj->name, 'company_id' => $this->company->id], ['name' => $obj->name, 'company_id' => $this->company->id],