diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 9f20eff..15f9fb3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -8,16 +8,14 @@ use App\Exceptions\Api\V2\ApiErrorException; use App\Exceptions\Api\V2\CrmException; use App\Http\Resources\Api\V2\ApiResponse as V2ApiResponse; use App\Lib\Helper; -use App\Mail\ExceptionAlert; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Mail; use Illuminate\Validation\ValidationException; +use Kwaadpepper\ExceptionHandler\Exceptions\ExceptionHandler; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Throwable; @@ -66,16 +64,7 @@ class Handler extends ExceptionHandler if (get_class($e) == RedirectTo::class) { abort(redirect($e->url)); } - try { - if (!config('app.debug')) { - if ($this->shouldntReport($e)) { - return; - } - Mail::send(new ExceptionAlert($e)); - } - } finally { - parent::report($e); - } + parent::report($e); } /** diff --git a/app/Mail/ExceptionAlert.php b/app/Mail/ExceptionAlert.php deleted file mode 100644 index 48ca654..0000000 --- a/app/Mail/ExceptionAlert.php +++ /dev/null @@ -1,49 +0,0 @@ -exception = $exception; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - return $this->view('mail.exception') - ->subject('Need help !, an error occured in your application, please check Logs ASAP') - ->text('mail.exception-plain') - ->with('appName', config('app.name')) - ->with('appUrl', config('app.url')) - ->with('exception', $this->exception) - ->with('url', app()->runningInConsole() ? 'CONSOLE' : ( - (request() and request()->fullUrl()) ? - request()->fullUrl() : 'none')) - ->to( - config('mail.contactsList.serviceweb', 'informatique.internet@ldc.fr'), - sprintf('%s Exception Handler', config('app.name')) - ); - } -} diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 32ce105..88de709 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -44,17 +44,6 @@ class Brand extends Model CrudAction::create(), CrudAction::update() ] - ], - 'services' => [ - 'label' => Str::ucfirst(Str::plural(trans('models.classes.services'))), - 'type' => CrudType::belongsToMany(), - 'belongsToMany' => Service::class, - 'belongsToManyLabel' => 'name', - 'actions' => [ - CrudAction::view(), - CrudAction::create(), - CrudAction::update(), - ] ] ]; parent::__construct($attributes); diff --git a/app/Models/Service.php b/app/Models/Service.php index b358d7b..feea457 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -54,7 +54,9 @@ class Service extends Model 'belongsTo' => Brand::class, 'actions' => [ CrudAction::viewAny(), - CrudAction::view() + CrudAction::view(), + CrudAction::create(), + CrudAction::update() ] ], ]; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 73af49a..098590a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,8 @@ namespace App\Providers; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Pagination\Paginator; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\URL; @@ -32,9 +34,33 @@ class AppServiceProvider extends ServiceProvider //! Important pourra etre retiré quand la V1 sera supprimé // empeche l'encapsulation dans data JsonResource::withoutWrapping(); + + // LOCAL HTTPS FIX if (!in_array(config('app.env'), ['local', 'testing'])) { URL::forceScheme('https'); } + // HA PROXY FIX + App::singleton('clientIp', function () { + if ( + config('app.env') === 'local' + ) { + return request()->getClientIp(); + } else { + return request()->server('HTTP_X_FORWARDED_FOR') ?? + request()->getClientIp(); + } + }); + // LOCAL FORCE eg: for Carbon + setlocale(LC_ALL, \sprintf( + '%s_%s.UTF-8', + config('app.locale'), + \strtoupper(config('app.locale')) + )); + Carbon::setLocale(config('app.locale')); + // FORCE BOOTSTRAP PAGINATOR + if (!app()->runningInConsole()) { + Paginator::useBootstrap(); + } Paginator::useBootstrap(); diff --git a/clients/V2 b/clients/V2 index 9aa309f..0fa8c8d 160000 --- a/clients/V2 +++ b/clients/V2 @@ -1 +1 @@ -Subproject commit 9aa309f57bdfd202cc2674fd646465e1c341d005 +Subproject commit 0fa8c8d691f72c9d48a5db296a830920ef25534a diff --git a/composer.json b/composer.json index b4fc2b5..a754ddd 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "guzzlehttp/guzzle": "^7.0.1", "kwaadpepper/crud-policies": "^0.1.17", "kwaadpepper/enum": "^2.0", + "kwaadpepper/exception-handler": "^0.0.1", "laravel-lang/lang": "~7.0", "laravel/framework": "^8.39", "laravel/tinker": "^2.5", diff --git a/composer.lock b/composer.lock index 146429d..e1b9812 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "52ddf0e771e6661178474f2a87aeaf7e", + "content-hash": "04e9185626e4a8f3439e76f10ed8baf6", "packages": [ { "name": "arondeparon/laravel-request-sanitizer", @@ -1847,6 +1847,67 @@ }, "time": "2021-08-13T10:11:43+00:00" }, + { + "name": "kwaadpepper/exception-handler", + "version": "0.0.1", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/exception-handler.git", + "reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/exception-handler/zipball/a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f", + "reference": "a7d3dc8a573752fd3e14b16cfc7bc367a9b4a69f", + "shasum": "" + }, + "require": { + "illuminate/support": "~7|~8", + "laravel/framework": "~7|~8" + }, + "require-dev": { + "orchestra/testbench": "^6.13", + "phpunit/phpunit": "~9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ExceptionHandler\\ExceptionHandlerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ExceptionHandler\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Send emails when exceptions occurs", + "homepage": "https://github.com/kwaadpepper/exception-handler", + "keywords": [ + "email", + "exception", + "laravel", + "policies" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/exception-handler/issues", + "source": "https://github.com/Kwaadpepper/exception-handler/tree/0.0.1" + }, + "time": "2021-08-31T20:28:29+00:00" + }, { "name": "laravel-lang/lang", "version": "7.0.9", diff --git a/config/exception-handler.php b/config/exception-handler.php new file mode 100644 index 0000000..e6bd69b --- /dev/null +++ b/config/exception-handler.php @@ -0,0 +1,17 @@ + !config('app.debug'), + + /** + * Put a developper secured mailbox in here + * so you can receive email if things go mad + */ + 'contactsList' => [ + env('MAIL_LIST_SERVICEWEB', 'equipe.web@ldc.fr') + ] +]; diff --git a/resources/views/mail/exception-plain.blade.php b/resources/views/mail/exception-plain.blade.php deleted file mode 100644 index 966ae73..0000000 --- a/resources/views/mail/exception-plain.blade.php +++ /dev/null @@ -1,13 +0,0 @@ -{{ $appName }} Exception Handler - -Une erreur est survenue sur {{ $appName }} {{ $appUrl }} - -{{ $exception->getMessage() }} - -url : {{ $url ?? 'none' }} -date : {{ date('Y-m-d H:i:s') }} -code : {{$exception->getCode() }} -file : {{$exception->getFile() }} -line : {{$exception->getLine() }} - -Veuillez vérifier les logs pour en voir la trace. diff --git a/resources/views/mail/exception.blade.php b/resources/views/mail/exception.blade.php deleted file mode 100644 index 18e4298..0000000 --- a/resources/views/mail/exception.blade.php +++ /dev/null @@ -1,18 +0,0 @@ - - - - {{ config('app.name') }} Exception Handler - - - -

Une erreur est survenue sur {{ $appName }} {{ $appUrl }}

-

{{ $exception->getMessage() }}

-

url : {{ $url ?? 'none' }}

-

date : {{ date('Y-m-d H:i:s') }}

-

code : {{$exception->getCode() }}

-

file : {{$exception->getFile() }}

-

line : {{$exception->getLine() }}

-

Veuillez vérifier les logs pour en voir la trace.

- - -