From d401a6fb93ed36f4df5d479d7e0ef2367c975a78 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Feb 2016 10:37:38 +1100 Subject: [PATCH 1/9] Bug in Client API not paginating all results --- app/Http/Controllers/ClientApiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index 4f4a6212d1e1..62570aea2a2a 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -67,7 +67,7 @@ class ClientApiController extends BaseAPIController $clients = $clients->paginate(); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); - $paginator = Client::scope()->paginate(); + $paginator = Client::scope()->withTrashed()->paginate(); $data = $this->createCollection($clients, $transformer, ENTITY_CLIENT, $paginator); From ce58c581ef9da63cddcd3bf38d768a49004d0eab Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Feb 2016 15:27:42 +1100 Subject: [PATCH 2/9] Delete Client from API --- app/Http/Controllers/ClientApiController.php | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index 62570aea2a2a..6cd91d1d09f1 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -158,5 +158,45 @@ class ClientApiController extends BaseAPIController } + /** + * @SWG\Delete( + * path="/clients/{client_id}", + * tags={"client"}, + * summary="Delete a client", + * @SWG\Parameter( + * in="body", + * name="body", + * @SWG\Schema(ref="#/definitions/Client") + * ), + * @SWG\Response( + * response=200, + * description="Delete client", + * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client")) + * ), + * @SWG\Response( + * response="default", + * description="an ""unexpected"" error" + * ) + * ) + */ + + public function destroy($publicId) + { + + $client = Client::scope($publicId)->withTrashed()->first(); + $this->clientRepo->delete($client); + + $client = Client::scope($publicId) + ->with('country', 'contacts', 'industry', 'size', 'currency') + ->withTrashed() + ->first(); + + $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); + $data = $this->createItem($client, $transformer, ENTITY_CLIENT); + + return $this->response($data); + + } + } From 9ab8069de1c8340c82bf935614a354e98e1bd511 Mon Sep 17 00:00:00 2001 From: ridgarou Date: Tue, 9 Feb 2016 10:57:25 +0100 Subject: [PATCH 3/9] Update master.blade.php --- resources/views/master.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index c85f6d5bbd61..e12c4bf7ee1f 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -77,11 +77,11 @@ } } ); - /* + var appLocale = '{{App::getLocale()}}'; + $.extend( true, $.fn.datepicker.defaults, { - language:'{{App::getLocale()}}' + language: appLocale.replace("_", "-") }); - */ @if (env('FACEBOOK_PIXEL')) @@ -202,4 +202,4 @@ - \ No newline at end of file + From 55f26c9ea5e76dce72deb8667af40bc52acd49e6 Mon Sep 17 00:00:00 2001 From: ridgarou Date: Tue, 9 Feb 2016 11:12:23 +0100 Subject: [PATCH 4/9] Update jquery.datetimepicker.js --- public/js/jquery.datetimepicker.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/public/js/jquery.datetimepicker.js b/public/js/jquery.datetimepicker.js index 9c00413c2d4e..6d34e0e797cf 100644 --- a/public/js/jquery.datetimepicker.js +++ b/public/js/jquery.datetimepicker.js @@ -120,6 +120,14 @@ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ] }, + 'fr-CA': { //French - Canada + months: [ + "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" + ], + dayOfWeek: [ + "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" + ] + }, es: { // Spanish months: [ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" @@ -128,6 +136,14 @@ "Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb" ] }, + 'es-ES': { // Spanish - Spain + months: [ + "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" + ], + dayOfWeek: [ + "Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb" + ] + }, th: { // Thai months: [ 'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม' @@ -200,6 +216,14 @@ "Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør" ] }, + 'nb_NO': { // Norwegian + months: [ + "Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember" + ], + dayOfWeek: [ + "Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør" + ] + }, ja: { // Japanese months: [ "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" From 60530d3cbc1510f296fbd64e6ff92e130e8f8365 Mon Sep 17 00:00:00 2001 From: ridgarou Date: Tue, 9 Feb 2016 12:37:23 +0100 Subject: [PATCH 5/9] Update AccountRepository.php --- app/Ninja/Repositories/AccountRepository.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index af708fcb320f..defceff7193a 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -75,21 +75,21 @@ class AccountRepository ->where('clients.deleted_at', '=', null) ->where('clients.account_id', '=', \Auth::user()->account_id) ->whereRaw("clients.name <> ''") - ->select(\DB::raw("'Clients' as type, clients.public_id, clients.name, '' as token")); + ->select(\DB::raw("'" . trans('texts.clients') . "' as type, clients.public_id, clients.name, '' as token")); $contacts = \DB::table('clients') ->join('contacts', 'contacts.client_id', '=', 'clients.id') ->where('clients.deleted_at', '=', null) ->where('clients.account_id', '=', \Auth::user()->account_id) ->whereRaw("CONCAT(contacts.first_name, contacts.last_name, contacts.email) <> ''") - ->select(\DB::raw("'Contacts' as type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name, ' ', contacts.email) as name, '' as token")); + ->select(\DB::raw("'" . trans('texts.contacts') . "' as type, clients.public_id, CONCAT(contacts.first_name, ' ', contacts.last_name, ' ', contacts.email) as name, '' as token")); $invoices = \DB::table('clients') ->join('invoices', 'invoices.client_id', '=', 'clients.id') ->where('clients.account_id', '=', \Auth::user()->account_id) ->where('clients.deleted_at', '=', null) ->where('invoices.deleted_at', '=', null) - ->select(\DB::raw("'Invoices' as type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name, invoices.invoice_number as token")); + ->select(\DB::raw("'" . trans('texts.invoices') . "' as type, invoices.public_id, CONCAT(invoices.invoice_number, ': ', clients.name) as name, invoices.invoice_number as token")); $data = []; From 3878fe9324c37eb3af7ef77d3c58c9efc46a7c84 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Feb 2016 08:51:08 +1100 Subject: [PATCH 6/9] Validation rule realignment --- app/Http/Requests/UpdateInvoiceRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/UpdateInvoiceRequest.php b/app/Http/Requests/UpdateInvoiceRequest.php index 68fa2acaa708..4b32bf4ccead 100644 --- a/app/Http/Requests/UpdateInvoiceRequest.php +++ b/app/Http/Requests/UpdateInvoiceRequest.php @@ -32,7 +32,7 @@ class UpdateInvoiceRequest extends Request $invoiceId = Invoice::getPrivateId($publicId); $rules = [ - 'invoice_items' => 'required|valid_invoice_items', + 'invoice_items' => 'valid_invoice_items', 'invoice_number' => 'unique:invoices,invoice_number,'.$invoiceId.',id,account_id,'.Auth::user()->account_id, 'discount' => 'positive', ]; From 67b74b2a34112ea1adf1c72674f870c14c0d5658 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Feb 2016 11:26:21 +1100 Subject: [PATCH 7/9] Table locking for public_id integrity --- app/Models/EntityModel.php | 1 + app/Ninja/Repositories/ClientRepository.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index b8e7d651ada4..9483f84a8c6a 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -27,6 +27,7 @@ class EntityModel extends Eloquent $lastEntity = $className::withTrashed() ->scope(false, $entity->account_id) ->orderBy('public_id', 'DESC') + ->lockForUpdate() ->first(); if ($lastEntity) { diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 3e43d8f34f5f..ab9789f1cae9 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -66,6 +66,8 @@ class ClientRepository extends BaseRepository { $publicId = isset($data['public_id']) ? $data['public_id'] : false; + DB::beginTransaction(); + if (!$publicId || $publicId == '-1') { $client = Client::createNew(); } else { @@ -75,6 +77,9 @@ class ClientRepository extends BaseRepository $client->fill($data); $client->save(); + DB::commit(); + + /* if ( ! isset($data['contact']) && ! isset($data['contacts'])) { return $client; From 498d7cbca95d424e8c9daa847184b2bbd4980914 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Feb 2016 12:32:12 +1100 Subject: [PATCH 8/9] Revert "Table locking for public_id integrity" --- app/Models/EntityModel.php | 1 - app/Ninja/Repositories/ClientRepository.php | 5 ----- 2 files changed, 6 deletions(-) diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index 9483f84a8c6a..b8e7d651ada4 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -27,7 +27,6 @@ class EntityModel extends Eloquent $lastEntity = $className::withTrashed() ->scope(false, $entity->account_id) ->orderBy('public_id', 'DESC') - ->lockForUpdate() ->first(); if ($lastEntity) { diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index ab9789f1cae9..3e43d8f34f5f 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -66,8 +66,6 @@ class ClientRepository extends BaseRepository { $publicId = isset($data['public_id']) ? $data['public_id'] : false; - DB::beginTransaction(); - if (!$publicId || $publicId == '-1') { $client = Client::createNew(); } else { @@ -77,9 +75,6 @@ class ClientRepository extends BaseRepository $client->fill($data); $client->save(); - DB::commit(); - - /* if ( ! isset($data['contact']) && ! isset($data['contacts'])) { return $client; From a8cff1db95ac5104afec9240d26884cdcab13c5b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Feb 2016 13:05:32 +1100 Subject: [PATCH 9/9] Jump over duplicate checks if request comes from API --- app/Http/Middleware/DuplicateSubmissionCheck.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Middleware/DuplicateSubmissionCheck.php b/app/Http/Middleware/DuplicateSubmissionCheck.php index 2468f7ac9b77..407ffab60071 100644 --- a/app/Http/Middleware/DuplicateSubmissionCheck.php +++ b/app/Http/Middleware/DuplicateSubmissionCheck.php @@ -7,6 +7,11 @@ class DuplicateSubmissionCheck // Prevent users from submitting forms twice public function handle($request, Closure $next) { + + if ($request->is('api/v1/*')) { + return $next($request); + } + $path = $request->path(); if (strpos($path, 'charts_and_reports') !== false) {