1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00

Merge pull request #3932 from turbo124/v2

Fixes
This commit is contained in:
David Bomba 2020-07-25 09:19:47 +10:00 committed by GitHub
commit 8b9104e9f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 38 deletions

View File

@ -132,52 +132,90 @@ class BaseController extends Controller
protected function refreshResponse($query)
{
$this->buildManager();
// $this->manager->parseIncludes($includes);
$this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY;
if ($this->serializer === EntityTransformer::API_SERIALIZER_JSON) {
$this->manager->setSerializer(new JsonApiSerializer());
} else {
$this->manager->setSerializer(new ArraySerializer());
}
$transformer = new $this->entity_transformer(Input::get('serializer'));
$includes = $transformer->getDefaultIncludes();
$includes = $this->getRequestIncludes($includes);
//info(print_r($includes,1));
$updated_at = request()->has('updated_at') ? request()->input('updated_at') : 0;
$updated_at = date('Y-m-d H:i:s', $updated_at);
//info($updated_at);
$query->with(
[
'company' => function ($query) use($updated_at){$query->whereNotNull('updated_at');},
'company.clients' =>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.tax_rates'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.groups'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.company_gateways'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.clients.contacts'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.products'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.invoices'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.invoices.invitations.contact'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.invoices.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.invoices.documents'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.payments'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.quotes.invitations.contact'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.quotes.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.quotes.documents'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.credits.documents'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.credits.invitations.contact'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.credits.invitations'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.payment_terms'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.vendors.contacts'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.expenses'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.tasks'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.projects'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company.designs'=>function ($query) use($updated_at){$query->where('updated_at', '>=', $updated_at);},
'company' => function ($query) use($updated_at){
$query->whereNotNull('updated_at');
},
'company.clients'=>function ($query) use($updated_at){
$query->where('clients.updated_at', '>=', $updated_at)->with('contacts');
},
'company.tax_rates'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.groups'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.company_gateways'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('gateway');
},
'company.products'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.invoices'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('invitations','documents');
},
'company.payments'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('paymentables');
},
'company.quotes'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('invitations','documents');
},
'company.credits'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('invitations','documents');
},
'company.payment_terms'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.vendors'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at)->with('contacts');
},
'company.expenses'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.tasks'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.projects'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
'company.designs'=>function ($query) use($updated_at){
$query->where('updated_at', '>=', $updated_at);
},
]
);
$data = $this->createCollection($query, $transformer, $this->entity_type);
return $this->response($data);
if (is_a($query, "Illuminate\Database\Eloquent\Builder")) {
$limit = Input::get('per_page', 20);
$paginator = $query->paginate($limit);
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
} else {
$resource = new Collection($query, $transformer, $this->entity_type);
}
return $this->response($this->manager->createData($resource)->toArray());
}
protected function listResponse($query)

View File

@ -50,7 +50,7 @@ class QueryLogging
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
// if($count > 100)
// if($count > 700)
// Log::info($queries);
}

View File

@ -220,7 +220,6 @@ class BaseRepository
$tmp_data = $data;
/* We need to unset some variable as we sometimes unguard the model */
if (isset($tmp_data['invitations'])) {
unset($tmp_data['invitations']);
}

View File

@ -31,6 +31,7 @@ class CreateInvitations extends AbstractService
$invitation = InvoiceInvitation::whereCompanyId($this->invoice->company_id)
->whereClientContactId($contact->id)
->whereInvoiceId($this->invoice->id)
->withTrashed()
->first();
if (!$invitation && $contact->send_email) {

View File

@ -10,7 +10,7 @@ return [
'app_name' => env('APP_NAME'),
'app_env' => env('APP_ENV', 'selfhosted'),
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => env('APP_URL', ''),
'app_url' => rtrim(env('APP_URL', ''), '/') . '/',
'app_domain' => env('APP_DOMAIN', ''),
'app_version' => '5.0.12',
'minimum_client_version' => '5.0.12',

View File

@ -75,7 +75,7 @@
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/flutter_service_worker.js?v={{sha1(time())}}');
navigator.serviceWorker.register('/flutter_service_worker.js?v={{ md5(public_path('flutter_service_worker.js')) }}');
});
}

View File

@ -125,6 +125,15 @@ class InvoiceTest extends TestCase
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $invoice)
->assertStatus(200);
//test that the same request should produce a validation error due
//to duplicate number being used.
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $invoice)
->assertStatus(302);
}
public function testDeleteInvoice()