From c0244f24efd1eed6f5589d2c4dae9777eaa50941 Mon Sep 17 00:00:00 2001 From: Antoine Le Gonidec Date: Wed, 10 Jul 2024 17:16:13 +0200 Subject: [PATCH] Convert the PHP package into a Laravel Module cf. https://laravelmodules.com/ --- CHANGELOG | 5 + Config/config.php | 5 + .../Commands/FetchEmails.php | 6 +- ...2710_drop_emails_on_customers_deletion.php | 0 ...2728_drop_unicity_from_customer_emails.php | 0 ...d_mailbox_id_column_to_customers_table.php | 0 .../MMFRestrictedCustomersDatabaseSeeder.php | 21 ++++ {src => Entities}/Customer.php | 4 +- {src => Entities}/Email.php | 2 +- {src => Entities}/Mailbox.php | 4 +- .../Controllers/ConversationsController.php | 6 +- .../Controllers/CrmController.php | 12 +- .../Controllers/CustomersController.php | 10 +- Http/routes.php | 33 ++++++ .../MMFRestrictedCustomersServiceProvider.php | 109 ++++++++++++++++++ README.md | 38 +++--- .../views/conversations/search.blade.php | 0 .../views/create_customer.blade.php | 0 .../partials/customers_table.blade.php | 0 .../customers/partials/edit_form.blade.php | 0 .../views/customers/update.blade.php | 0 composer.json | 22 ++-- module.json | 25 ++++ routes/web.php | 36 ------ ...coutRestrictedCustomersServiceProvider.php | 38 ------ start.php | 17 +++ 26 files changed, 267 insertions(+), 126 deletions(-) create mode 100644 Config/config.php rename {src/Console => Console}/Commands/FetchEmails.php (98%) rename {database/migrations => Database/Migrations}/2024_07_10_162710_drop_emails_on_customers_deletion.php (100%) rename {database/migrations => Database/Migrations}/2024_07_10_162728_drop_unicity_from_customer_emails.php (100%) rename {database/migrations => Database/Migrations}/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php (100%) create mode 100644 Database/Seeders/MMFRestrictedCustomersDatabaseSeeder.php rename {src => Entities}/Customer.php (98%) rename {src => Entities}/Email.php (94%) rename {src => Entities}/Mailbox.php (73%) rename {src/Http => Http}/Controllers/ConversationsController.php (96%) rename {src/Http => Http}/Controllers/CrmController.php (98%) rename {src/Http => Http}/Controllers/CustomersController.php (96%) create mode 100644 Http/routes.php create mode 100644 Providers/MMFRestrictedCustomersServiceProvider.php rename {resources => Resources}/views/conversations/search.blade.php (100%) rename {resources => Resources}/views/create_customer.blade.php (100%) rename {resources => Resources}/views/customers/partials/customers_table.blade.php (100%) rename {resources => Resources}/views/customers/partials/edit_form.blade.php (100%) rename {resources => Resources}/views/customers/update.blade.php (100%) create mode 100644 module.json delete mode 100644 routes/web.php delete mode 100644 src/FreescoutRestrictedCustomersServiceProvider.php create mode 100644 start.php diff --git a/CHANGELOG b/CHANGELOG index 8168e24..f1f9f14 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +0.7.0 + + * Convert the PHP package into a Laravel module, + cf. https://laravelmodules.com/ + 0.6.1 * Fix the ability to rollback migrations. diff --git a/Config/config.php b/Config/config.php new file mode 100644 index 0000000..01799fd --- /dev/null +++ b/Config/config.php @@ -0,0 +1,5 @@ + 'MMFRestrictedCustomers' +]; diff --git a/src/Console/Commands/FetchEmails.php b/Console/Commands/FetchEmails.php similarity index 98% rename from src/Console/Commands/FetchEmails.php rename to Console/Commands/FetchEmails.php index 71e8629..11cbc2e 100644 --- a/src/Console/Commands/FetchEmails.php +++ b/Console/Commands/FetchEmails.php @@ -4,10 +4,10 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers\Console\Commands; +namespace Modules\MMFRestrictedCustomers\Console\Commands; use App\Conversation; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; +use Modules\MMFRestrictedCustomers\Customer; use App\Events\CustomerCreatedConversation; use App\Events\CustomerReplied; use App\Thread; @@ -21,7 +21,7 @@ class FetchEmails extends BaseFetchEmails { * * @var string */ - protected $signature = 'freescout-restricted-customers:fetch-emails {--days=3} {--unseen=1} {--identifier=dummy} {--mailboxes=0}'; + protected $signature = 'mmfrestrictedcustomers:fetch-emails {--days=3} {--unseen=1} {--identifier=dummy} {--mailboxes=0}'; /** * Save email from customer as thread. diff --git a/database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php b/Database/Migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php similarity index 100% rename from database/migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php rename to Database/Migrations/2024_07_10_162710_drop_emails_on_customers_deletion.php diff --git a/database/migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php b/Database/Migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php similarity index 100% rename from database/migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php rename to Database/Migrations/2024_07_10_162728_drop_unicity_from_customer_emails.php diff --git a/database/migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php b/Database/Migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php similarity index 100% rename from database/migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php rename to Database/Migrations/2024_07_10_162735_add_mailbox_id_column_to_customers_table.php diff --git a/Database/Seeders/MMFRestrictedCustomersDatabaseSeeder.php b/Database/Seeders/MMFRestrictedCustomersDatabaseSeeder.php new file mode 100644 index 0000000..2d5c1b1 --- /dev/null +++ b/Database/Seeders/MMFRestrictedCustomersDatabaseSeeder.php @@ -0,0 +1,21 @@ +call("OthersTableSeeder"); + } +} diff --git a/src/Customer.php b/Entities/Customer.php similarity index 98% rename from src/Customer.php rename to Entities/Customer.php index e76798f..b198280 100644 --- a/src/Customer.php +++ b/Entities/Customer.php @@ -4,14 +4,14 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers; +namespace Modules\MMFRestrictedCustomers; use App\CustomerChannel; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; use Watson\Rememberable\Rememberable; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Mailbox; +use Modules\MMFRestrictedCustomers\Mailbox; use App\Customer as BaseCustomer; class Customer extends BaseCustomer { diff --git a/src/Email.php b/Entities/Email.php similarity index 94% rename from src/Email.php rename to Entities/Email.php index fd8deb5..fe0d5a5 100644 --- a/src/Email.php +++ b/Entities/Email.php @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers; +namespace Modules\MMFRestrictedCustomers; use Illuminate\Database\Eloquent\Model; use Watson\Rememberable\Rememberable; diff --git a/src/Mailbox.php b/Entities/Mailbox.php similarity index 73% rename from src/Mailbox.php rename to Entities/Mailbox.php index 76cfd1a..9d0b352 100644 --- a/src/Mailbox.php +++ b/Entities/Mailbox.php @@ -4,9 +4,9 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers; +namespace Modules\MMFRestrictedCustomers; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; +use Modules\MMFRestrictedCustomers\Customer; use App\Mailbox as BaseMailbox; class Mailbox extends BaseMailbox { diff --git a/src/Http/Controllers/ConversationsController.php b/Http/Controllers/ConversationsController.php similarity index 96% rename from src/Http/Controllers/ConversationsController.php rename to Http/Controllers/ConversationsController.php index c8ce45b..fb929e5 100644 --- a/src/Http/Controllers/ConversationsController.php +++ b/Http/Controllers/ConversationsController.php @@ -4,13 +4,13 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers; +namespace Modules\MMFRestrictedCustomers\Http\Controllers; use App\Conversation; use App\User; use Illuminate\Http\Request; use App\Http\Controllers\ConversationsController as BaseConversationsController; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; +use Modules\MMFRestrictedCustomers\Customer; class ConversationsController extends BaseConversationsController { /** @@ -91,7 +91,7 @@ class ConversationsController extends BaseConversationsController { $search_mailbox = $mailboxes[0]; } - return view('freescout-restricted-customers::conversations/search', [ + return view('mmfrestrictedcustomers::conversations/search', [ 'folder' => $folder, 'q' => $request->q, 'filters' => $filters, diff --git a/src/Http/Controllers/CrmController.php b/Http/Controllers/CrmController.php similarity index 98% rename from src/Http/Controllers/CrmController.php rename to Http/Controllers/CrmController.php index a8902b3..eac0a8c 100644 --- a/src/Http/Controllers/CrmController.php +++ b/Http/Controllers/CrmController.php @@ -4,7 +4,7 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers; +namespace Modules\MMFRestrictedCustomers\Http\Controllers; use App\Conversation; use Modules\Crm\Entities\CustomerField; @@ -14,9 +14,9 @@ use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Routing\Controller; use Modules\Crm\Http\Controllers\CrmController as BaseCrmController; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Email; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Mailbox; +use Modules\MMFRestrictedCustomers\Customer; +use Modules\MMFRestrictedCustomers\Email; +use Modules\MMFRestrictedCustomers\Mailbox; class CrmController extends BaseCrmController { public function createCustomer(Request $request) { @@ -26,7 +26,7 @@ class CrmController extends BaseCrmController { $user = auth()->user(); $mailboxes = $user->mailboxesCanView(); - return view('freescout-restricted-customers::create_customer', [ + return view('mmfrestrictedcustomers::create_customer', [ 'customer' => $customer, 'mailboxes' => $mailboxes, 'emails' => [''], @@ -68,7 +68,7 @@ class CrmController extends BaseCrmController { } if ($fail || $validator->fails()) { - return redirect()->route('freescout-restricted-customers.create_customer') + return redirect()->route('mmfrestrictedcustomers.create_customer') ->withErrors($validator) ->withInput(); } diff --git a/src/Http/Controllers/CustomersController.php b/Http/Controllers/CustomersController.php similarity index 96% rename from src/Http/Controllers/CustomersController.php rename to Http/Controllers/CustomersController.php index eb1bd11..c2fb742 100644 --- a/src/Http/Controllers/CustomersController.php +++ b/Http/Controllers/CustomersController.php @@ -4,14 +4,14 @@ SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE */ -namespace MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers; +namespace Modules\MMFRestrictedCustomers\Http\Controllers; use App\Conversation; use App\Email; use Illuminate\Http\Request; use Validator; use App\Http\Controllers\CustomersController as BaseCustomersController; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer; +use Modules\MMFRestrictedCustomers\Customer; class CustomersController extends BaseCustomersController { /** @@ -36,7 +36,7 @@ class CustomersController extends BaseCustomersController { $emails = ['']; } - return view('freescout-restricted-customers::customers/update', [ + return view('mmfrestrictedcustomers::customers/update', [ 'customer' => $customer, 'mailboxes' => $mailboxes, 'emails' => $emails, @@ -382,11 +382,11 @@ class CustomersController extends BaseCustomersController { // Conversations navigation case 'customers_pagination': - $customers = app('MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\ConversationsController')->searchCustomers($request, $user); + $customers = app('Modules\MMFRestrictedCustomers\Http\Controllers\ConversationsController')->searchCustomers($request, $user); $response['status'] = 'success'; - $response['html'] = view('freescout-restricted-customers::customers/partials/customers_table', [ + $response['html'] = view('mmfrestrictedcustomers::customers/partials/customers_table', [ 'customers' => $customers, ])->render(); break; diff --git a/Http/routes.php b/Http/routes.php new file mode 100644 index 0000000..5de0ae1 --- /dev/null +++ b/Http/routes.php @@ -0,0 +1,33 @@ + + */ + +use Illuminate\Support\Facades\Route; +use Modules\MMFRestrictedCustomers\Http\Controllers\ConversationsController; +use Modules\MMFRestrictedCustomers\Http\Controllers\CrmController; +use Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController; + +Route::group(['middleware' => 'web', 'prefix' => \Helper::getSubdirectory(), 'namespace' => 'Modules\MMFRestrictedCustomers\Http\Controllers'], function() { + // Customers + Route::get('/customers/{id}/edit', CustomersController::class . '@update')->name('customers.update'); + Route::post('/customers/{id}/edit', CustomersController::class . '@updateSave'); + Route::get('/customers/{id}/', CustomersController::class . '@conversations')->name('customers.conversations'); + Route::get('/customers/ajax-search', ['uses' => CustomersController::class . '@ajaxSearch', 'laroute' => true])->name('customers.ajax_search'); + Route::post('/customers/ajax', ['uses' => CustomersController::class . '@ajax', 'laroute' => true])->name('customers.ajax'); + // Conversations + Route::get('/search', ConversationsController::class . '@search')->name('conversations.search'); + // Crm module + Route::group([ 'roles' => ['user', 'admin'] ], function() { + Route::get('/customers/new', CrmController::class . '@createCustomer')->name('mmfrestrictedcustomers.create_customer'); + Route::post('/customers/new', CrmController::class . '@createCustomerSave'); + Route::get('/crm/ajax-html/{action}/{param?}', ['uses' => CrmController::class . '@ajaxHtml'])->name('crm.ajax_html'); + Route::get('/customers/fields/ajax-search', ['uses' => CrmController::class . '@ajaxSearch', 'laroute' => true])->name('crm.ajax_search'); + Route::post('/crm/ajax', ['uses' => CrmController::class . '@ajax', 'laroute' => true])->name('crm.ajax'); + }); + Route::group([ 'roles' => ['admin'] ], function() { + Route::post('/customers/export', ['uses' => CrmController::class . '@export'])->name('crm.export'); + Route::post('/crm/ajax-admin', ['uses' => CrmController::class . '@ajaxAdmin', 'laroute' => true])->name('crm.ajax_admin'); + }); +}); diff --git a/Providers/MMFRestrictedCustomersServiceProvider.php b/Providers/MMFRestrictedCustomersServiceProvider.php new file mode 100644 index 0000000..b247376 --- /dev/null +++ b/Providers/MMFRestrictedCustomersServiceProvider.php @@ -0,0 +1,109 @@ +registerConfig(); + $this->registerViews(); + $this->registerFactories(); + $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + $this->commands([ + FetchEmails::class, + ]); + $this->hooks(); + } + + /** + * Module hooks. + */ + public function hooks() { + // + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() { + $this->registerTranslations(); + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() { + $this->publishes([ + __DIR__.'/../Config/config.php' => config_path('mmfrestrictedcustomers.php'), + ], 'config'); + $this->mergeConfigFrom( + __DIR__.'/../Config/config.php', 'mmfrestrictedcustomers' + ); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() { + $viewPath = resource_path('views/modules/mmfrestrictedcustomers'); + + $sourcePath = __DIR__.'/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ],'views'); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/mmfrestrictedcustomers'; + }, \Config::get('view.paths')), [$sourcePath]), 'mmfrestrictedcustomers'); + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() { + $this->loadJsonTranslationsFrom(__DIR__ .'/../Resources/lang'); + } + + /** + * Register an additional directory of factories. + * @source https://github.com/sebastiaanluca/laravel-resource-flow/blob/develop/src/Modules/ModuleServiceProvider.php#L66 + */ + public function registerFactories() { + if (! app()->environment('production')) { + app(Factory::class)->load(__DIR__ . '/../Database/factories'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() { + return []; + } +} diff --git a/README.md b/README.md index ca31dc5..73218f3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You have been warned. ### Install the package with composer ``` -composer require "millions-missing-france/freescout-restricted-customers" "0.6.1" +composer require "millions-missing-france/mmfrestrictedcustomers" "0.6.1" ``` ### Edit the application routes @@ -44,11 +44,11 @@ should be replaced with: ```php // Customers -Route::get('/customers/{id}/edit', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController@update')->name('customers.update'); -Route::post('/customers/{id}/edit', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController@updateSave'); -Route::get('/customers/{id}/', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController@conversations')->name('customers.conversations'); -Route::get('/customers/ajax-search', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController@ajaxSearch', 'laroute' => true])->name('customers.ajax_search'); -Route::post('/customers/ajax', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController@ajax', 'laroute' => true])->name('customers.ajax'); +Route::get('/customers/{id}/edit', '\Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController@update')->name('customers.update'); +Route::post('/customers/{id}/edit', '\Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController@updateSave'); +Route::get('/customers/{id}/', '\Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController@conversations')->name('customers.conversations'); +Route::get('/customers/ajax-search', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController@ajaxSearch', 'laroute' => true])->name('customers.ajax_search'); +Route::post('/customers/ajax', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CustomersController@ajax', 'laroute' => true])->name('customers.ajax'); ``` This other section should be edited too: @@ -78,7 +78,7 @@ Route::get('/mailbox/{mailbox_id}/new-ticket', 'ConversationsController@create') Route::get('/mailbox/{mailbox_id}/clone-ticket/{from_thread_id}', 'ConversationsController@cloneConversation')->name('conversations.clone_conversation'); //Route::get('/conversation/draft/{id}', 'ConversationsController@draft')->name('conversations.draft'); Route::get('/conversation/ajax-html/{action}', ['uses' => 'ConversationsController@ajaxHtml', 'laroute' => true])->name('conversations.ajax_html'); -Route::get('/search', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\ConversationsController@search')->name('conversations.search'); +Route::get('/search', '\Modules\MMFRestrictedCustomers\Http\Controllers\ConversationsController@search')->name('conversations.search'); Route::get('/conversation/undo-reply/{thread_id}', 'ConversationsController@undoReply')->name('conversations.undo'); Route::get('/mailbox/{mailbox_id}/chats', 'ConversationsController@chats')->name('conversations.chats'); ``` @@ -107,19 +107,19 @@ Route::group(['middleware' => ['web', 'auth', 'roles'], 'roles' => ['admin'], 'p should be replaced with: ```php -Route::group(['middleware' => ['web', 'auth', 'roles'], 'roles' => ['user', 'admin'], 'prefix' => \Helper::getSubdirectory(), 'namespace' => 'MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers'], function() +Route::group(['middleware' => ['web', 'auth', 'roles'], 'roles' => ['user', 'admin'], 'prefix' => \Helper::getSubdirectory(), 'namespace' => 'Modules\MMFRestrictedCustomers\Http\Controllers'], function() { - Route::get('/customers/new', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@createCustomer')->name('freescout-restricted-customers.create_customer'); - Route::post('/customers/new', '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@createCustomerSave'); - Route::get('/crm/ajax-html/{action}/{param?}', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@ajaxHtml'])->name('crm.ajax_html'); - Route::get('/customers/fields/ajax-search', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@ajaxSearch', 'laroute' => true])->name('crm.ajax_search'); - Route::post('/crm/ajax', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@ajax', 'laroute' => true])->name('crm.ajax'); + Route::get('/customers/new', '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@createCustomer')->name('mmfrestrictedcustomers.create_customer'); + Route::post('/customers/new', '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@createCustomerSave'); + Route::get('/crm/ajax-html/{action}/{param?}', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@ajaxHtml'])->name('crm.ajax_html'); + Route::get('/customers/fields/ajax-search', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@ajaxSearch', 'laroute' => true])->name('crm.ajax_search'); + Route::post('/crm/ajax', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@ajax', 'laroute' => true])->name('crm.ajax'); }); -Route::group(['middleware' => ['web', 'auth', 'roles'], 'roles' => ['admin'], 'prefix' => \Helper::getSubdirectory(), 'namespace' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers'], function() +Route::group(['middleware' => ['web', 'auth', 'roles'], 'roles' => ['admin'], 'prefix' => \Helper::getSubdirectory(), 'namespace' => '\Modules\MMFRestrictedCustomers\Http\Controllers'], function() { - Route::post('/customers/export', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@export'])->name('crm.export'); - Route::post('/crm/ajax-admin', ['uses' => '\MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController@ajaxAdmin', 'laroute' => true])->name('crm.ajax_admin'); + Route::post('/customers/export', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@export'])->name('crm.export'); + Route::post('/crm/ajax-admin', ['uses' => '\Modules\MMFRestrictedCustomers\Http\Controllers\CrmController@ajaxAdmin', 'laroute' => true])->name('crm.ajax_admin'); }); ``` @@ -134,7 +134,7 @@ At line 173, this route call: should be replaced with: ```php - $html = __('Customers').' \' class="btn btn-bordered btn-xs" style="position:relative;top:-1px;margin-left:4px;">'; + $html = __('Customers').' \' class="btn btn-bordered btn-xs" style="position:relative;top:-1px;margin-left:4px;">'; ``` ### Edit the artisan commands @@ -151,8 +151,8 @@ At the lines 107-108, this: should be replaced with: ```php - $fetch_command_identifier = \Helper::getWorkerIdentifier('freescout-restricted-customers:fetch-emails'); - $fetch_command_name = 'freescout-restricted-customers:fetch-emails' + $fetch_command_identifier = \Helper::getWorkerIdentifier('mmfrestrictedcustomers:fetch-emails'); + $fetch_command_name = 'mmfrestrictedcustomers:fetch-emails' ``` ### Update the database schema diff --git a/resources/views/conversations/search.blade.php b/Resources/views/conversations/search.blade.php similarity index 100% rename from resources/views/conversations/search.blade.php rename to Resources/views/conversations/search.blade.php diff --git a/resources/views/create_customer.blade.php b/Resources/views/create_customer.blade.php similarity index 100% rename from resources/views/create_customer.blade.php rename to Resources/views/create_customer.blade.php diff --git a/resources/views/customers/partials/customers_table.blade.php b/Resources/views/customers/partials/customers_table.blade.php similarity index 100% rename from resources/views/customers/partials/customers_table.blade.php rename to Resources/views/customers/partials/customers_table.blade.php diff --git a/resources/views/customers/partials/edit_form.blade.php b/Resources/views/customers/partials/edit_form.blade.php similarity index 100% rename from resources/views/customers/partials/edit_form.blade.php rename to Resources/views/customers/partials/edit_form.blade.php diff --git a/resources/views/customers/update.blade.php b/Resources/views/customers/update.blade.php similarity index 100% rename from resources/views/customers/update.blade.php rename to Resources/views/customers/update.blade.php diff --git a/composer.json b/composer.json index cb1a90d..3e79ef7 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "millions-missing-france/freescout-restricted-customers", "description": "Freescout restricted customers - Restrict access to Freescout customers to specific mailboxes", - "version": "0.6.1", + "version": "0.7.0", "type": "library", "license": ["AGPL-3.0-only"], "authors": [ @@ -10,19 +10,19 @@ "email": "info@millionsmissing.fr" } ], - "require": { - "laravel/framework": "v5.5.40" - }, - "autoload": { - "psr-4": { - "MillionsMissingFrance\\FreescoutRestrictedCustomers\\": "src" - } - }, "extra": { "laravel": { "providers": [ - "MillionsMissingFrance\\FreescoutRestrictedCustomers\\FreescoutRestrictedCustomersServiceProvider" - ] + "Modules\\MMFRestrictedCustomers\\Providers\\MMFRestrictedCustomersServiceProvider" + ], + "aliases": { + + } + } + }, + "autoload": { + "psr-4": { + "Modules\\MMFRestrictedCustomers\\": "" } } } diff --git a/module.json b/module.json new file mode 100644 index 0000000..725ff0e --- /dev/null +++ b/module.json @@ -0,0 +1,25 @@ +{ + "name": "MMFRestrictedCustomers", + "alias": "mmfrestrictedcustomers", + "description": "Freescout restricted customers - Restrict access to Freescout customers to specific mailboxes", + "version": "0.7.0", + "detailsUrl": "", + "author": "Millions Missing FRANCE", + "authorUrl": "info@millionsmissing.fr", + "requiredAppVersion": "1.8.117", + "license": "AGPL-3.0-only", + "keywords": [], + "active": 0, + "order": 0, + "providers": [ + "Modules\\MMFRestrictedCustomers\\Providers\\MMFRestrictedCustomersServiceProvider" + ], + "aliases": {}, + "files": [ + "start.php" + ], + "requires": [], + "requiredModules": { + "crm": "1.0.46" + } +} diff --git a/routes/web.php b/routes/web.php deleted file mode 100644 index 4e5bc86..0000000 --- a/routes/web.php +++ /dev/null @@ -1,36 +0,0 @@ - - */ - -use Illuminate\Support\Facades\Route; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\ConversationsController; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CrmController; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Http\Controllers\CustomersController; - -// FIXME: Routes are not correctly exposed to the main application, -// routes/web.php and Modules/Crm/Http/routes.php must be manually edited. - -// Customers -Route::get('/customers/{id}/edit', CustomersController::class . '@update')->name('customers.update'); -Route::post('/customers/{id}/edit', CustomersController::class . '@updateSave'); -Route::get('/customers/{id}/', CustomersController::class . '@conversations')->name('customers.conversations'); -Route::get('/customers/ajax-search', ['uses' => CustomersController::class . '@ajaxSearch', 'laroute' => true])->name('customers.ajax_search'); -Route::post('/customers/ajax', ['uses' => CustomersController::class . '@ajax', 'laroute' => true])->name('customers.ajax'); -// Conversations -Route::get('/search', ConversationsController::class . '@search')->name('conversations.search'); -// Crm module -Route::group([ 'roles' => ['user', 'admin'] ], function() { - Route::get('/customers/new', CrmController::class . '@createCustomer')->name('freescout-restricted-customers.create_customer'); - // The Crm module initialization will crash if no route named "crm.create_customer" is set. - Route::get('/customers/new', CrmController::class . '@createCustomer')->name('crm.create_customer'); - Route::post('/customers/new', CrmController::class . '@createCustomerSave'); - Route::get('/crm/ajax-html/{action}/{param?}', ['uses' => CrmController::class . '@ajaxHtml'])->name('crm.ajax_html'); - Route::get('/customers/fields/ajax-search', ['uses' => CrmController::class . '@ajaxSearch', 'laroute' => true])->name('crm.ajax_search'); - Route::post('/crm/ajax', ['uses' => CrmController::class . '@ajax', 'laroute' => true])->name('crm.ajax'); -}); -Route::group([ 'roles' => ['admin'] ], function() { - Route::post('/customers/export', ['uses' => CrmController::class . '@export'])->name('crm.export'); - Route::post('/crm/ajax-admin', ['uses' => CrmController::class . '@ajaxAdmin', 'laroute' => true])->name('crm.ajax_admin'); -}); diff --git a/src/FreescoutRestrictedCustomersServiceProvider.php b/src/FreescoutRestrictedCustomersServiceProvider.php deleted file mode 100644 index eb5577c..0000000 --- a/src/FreescoutRestrictedCustomersServiceProvider.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ - -namespace MillionsMissingFrance\FreescoutRestrictedCustomers; - -use Illuminate\Support\Facades\Route; -use Illuminate\Support\ServiceProvider; -use MillionsMissingFrance\FreescoutRestrictedCustomers\Console\Commands\FetchEmails; - -class FreescoutRestrictedCustomersServiceProvider extends ServiceProvider { - public function register() { - // - } - - public function boot() { - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); - $this->registerRoutes(); - $this->loadViewsFrom(__DIR__.'/../resources/views', 'freescout-restricted-customers'); - $this->commands([ - FetchEmails::class, - ]); - } - - protected function registerRoutes() { - Route::group($this->routeConfiguration(), function () { - $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); - }); - } - - protected function routeConfiguration() { - return [ - 'middleware' => ['web', 'auth', 'roles'], - ]; - } -} diff --git a/start.php b/start.php new file mode 100644 index 0000000..140a105 --- /dev/null +++ b/start.php @@ -0,0 +1,17 @@ +routesAreCached()) { + require __DIR__ . '/Http/routes.php'; +}