diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php index c2deaa4ac..9f568d241 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/GroupController.php @@ -3,12 +3,12 @@ namespace Webkul\Admin\Http\Controllers\Settings; use Illuminate\Http\JsonResponse; -use Illuminate\View\View; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\Event; +use Illuminate\View\View; +use Webkul\Admin\DataGrids\Setting\GroupDataGrid; use Webkul\Admin\Http\Controllers\Controller; use Webkul\User\Repositories\GroupRepository; -use Webkul\Admin\DataGrids\Setting\GroupDataGrid; class GroupController extends Controller { diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php index a647939ba..fd7e7dd2d 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/RoleController.php @@ -2,12 +2,13 @@ namespace Webkul\Admin\Http\Controllers\Settings; +use Illuminate\View\View; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Event; -use Illuminate\View\View; -use Webkul\Admin\DataGrids\Setting\RoleDataGrid; -use Webkul\Admin\Http\Controllers\Controller; use Webkul\User\Repositories\RoleRepository; +use Webkul\User\Repositories\UserRepository; +use Webkul\Admin\Http\Controllers\Controller; +use Webkul\Admin\DataGrids\Setting\RoleDataGrid; class RoleController extends Controller { @@ -16,12 +17,13 @@ class RoleController extends Controller * * @return void */ - public function __construct(protected RoleRepository $roleRepository) {} - + public function __construct( + protected RoleRepository $roleRepository, + protected UserRepository $userRepository + ) {} + /** * Display a listing of the resource. - * - * @return \Illuminate\View\View */ public function index(): View|JsonResponse { @@ -52,34 +54,37 @@ public function store() $this->validate(request(), [ 'name' => 'required', 'permission_type' => 'required', + 'description' => 'required', ]); Event::dispatch('settings.role.create.before'); - $roleData = request()->all(); + $data = request()->only([ + 'name', + 'description', + 'permission_type', + 'permissions', + ]); - if ($roleData['permission_type'] == 'custom') { - if (! isset($roleData['permissions'])) { - $roleData['permissions'] = []; + if ($data['permission_type'] == 'custom') { + if (! isset($data['permissions'])) { + $data['permissions'] = []; } } - $role = $this->roleRepository->create($roleData); + $role = $this->roleRepository->create($data); Event::dispatch('settings.role.create.after', $role); - session()->flash('success', trans('admin::app.settings.roles.create-success')); + session()->flash('success', trans('admin::app.settings.roles.index.create-success')); return redirect()->route('admin.settings.roles.index'); } /** * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\View\View */ - public function edit($id) + public function edit(int $id): View { $role = $this->roleRepository->findOrFail($id); @@ -89,31 +94,31 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param int $id * @return \Illuminate\Http\Response */ - public function update($id) + public function update(int $id) { $this->validate(request(), [ 'name' => 'required', - 'permission_type' => 'required', + 'permission_type' => 'required|in:all,custom', + 'description' => 'required', ]); Event::dispatch('settings.role.update.before', $id); - $roleData = request()->all(); - - if ($roleData['permission_type'] == 'custom') { - if (! isset($roleData['permissions'])) { - $roleData['permissions'] = []; - } - } + $data = array_merge(request()->only([ + 'name', + 'description', + 'permission_type', + ]), [ + 'permissions' => request()->has('permissions') ? request('permissions') : [], + ]); - $role = $this->roleRepository->update($roleData, $id); + $role = $this->roleRepository->update($data, $id); Event::dispatch('settings.role.update.after', $role); - session()->flash('success', trans('admin::app.settings.roles.update-success')); + session()->flash('success', trans('admin::app.settings.roles.index.update-success')); return redirect()->route('admin.settings.roles.index'); } @@ -121,10 +126,9 @@ public function update($id) /** * Remove the specified resource from storage. * - * @param int $id * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(int $id) { $response = [ 'responseCode' => 400, @@ -133,11 +137,11 @@ public function destroy($id) $role = $this->roleRepository->findOrFail($id); if ($role->admins && $role->admins->count() >= 1) { - $response['message'] = trans('admin::app.settings.roles.being-used'); + $response['message'] = trans('admin::app.settings.roles.index.being-used'); session()->flash('error', $response['message']); } elseif ($this->roleRepository->count() == 1) { - $response['message'] = trans('admin::app.settings.roles.last-delete-error'); + $response['message'] = trans('admin::app.settings.roles.index.last-delete-error'); session()->flash('error', $response['message']); } else { @@ -145,13 +149,13 @@ public function destroy($id) Event::dispatch('settings.role.delete.before', $id); if (auth()->guard('user')->user()->role_id == $id) { - $response['message'] = trans('admin::app.settings.roles.current-role-delete-error'); + $response['message'] = trans('admin::app.settings.roles.index.current-role-delete-error'); } else { $this->roleRepository->delete($id); Event::dispatch('settings.role.delete.after', $id); - $message = trans('admin::app.settings.roles.delete-success'); + $message = trans('admin::app.settings.roles.index.delete-success'); $response = [ 'responseCode' => 200, diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index a35c1e453..b628e4a47 100644 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -250,21 +250,6 @@ Route::get('', 'SettingController@index')->name('admin.settings.index'); - // Roles Routes - Route::prefix('roles')->group(function () { - Route::get('', 'RoleController@index')->name('admin.settings.roles.index'); - - Route::get('create', 'RoleController@create')->name('admin.settings.roles.create'); - - Route::post('create', 'RoleController@store')->name('admin.settings.roles.store'); - - Route::get('edit/{id}', 'RoleController@edit')->name('admin.settings.roles.edit'); - - Route::put('edit/{id}', 'RoleController@update')->name('admin.settings.roles.update'); - - Route::delete('{id}', 'RoleController@destroy')->name('admin.settings.roles.delete'); - }); - // Users Routes Route::prefix('users')->group(function () { Route::get('', 'UserController@index')->name('admin.settings.users.index'); @@ -337,7 +322,6 @@ Route::delete('{id}', 'SourceController@destroy')->name('admin.settings.sources.delete'); }); - // Email Templates Routes Route::prefix('email-templates')->group(function () { Route::get('', 'EmailTemplateController@index')->name('admin.settings.email_templates.index'); diff --git a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php index 9d2f37768..4634f5084 100644 --- a/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php +++ b/packages/Webkul/Admin/src/Providers/AdminServiceProvider.php @@ -6,9 +6,9 @@ use Illuminate\Foundation\AliasLoader; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Blade; +use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Webkul\Admin\Http\Middleware\Locale; -use Illuminate\Support\Facades\Route; class AdminServiceProvider extends ServiceProvider { diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 6c26e0c9c..5513e0c76 100644 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -119,6 +119,7 @@ 'index' => [ 'title' => 'Products', 'create-btn' => 'Create Product', + 'datagrid' => [ 'allocated' => 'Allocated', 'delete' => 'Delete', @@ -167,9 +168,18 @@ 'roles' => [ 'index' => [ - 'create-btn' => 'Create Roles', - 'title' => 'Roles', - 'settings' => 'Settings', + 'being-used' => 'Role can not be deleted, as this is being used in admin user.', + 'create-btn' => 'Create Roles', + 'create-success' => 'Role created successfully.', + 'current-role-delete-error' => 'Can not delete role assigned to the current user.', + 'delete-failed' => 'Role can not be deleted.', + 'delete-success' => 'Role deleted successfully.', + 'last-delete-error' => 'At least one role is required.', + 'settings' => 'Settings', + 'title' => 'Roles', + 'update-success' => 'Role updated successfully.', + 'user-define-error' => 'Can not delete system role.', + 'datagrid' => [ 'all' => 'All', 'custom' => 'Custom', diff --git a/packages/Webkul/Admin/src/Resources/views/settings/roles/create.blade.php b/packages/Webkul/Admin/src/Resources/views/settings/roles/create.blade.php index e520eeb4f..2addc18cc 100644 --- a/packages/Webkul/Admin/src/Resources/views/settings/roles/create.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/settings/roles/create.blade.php @@ -4,11 +4,12 @@ @lang('admin::app.settings.roles.create.title') - {!! view_render_event('krayin.settings.roles.create.before') !!} + {!! view_render_event('krayin.admin.settings.roles.create.before') !!} + - {!! view_render_event('krayin.settings.roles.create.create_form_controls.before') !!} + {!! view_render_event('krayin.admin.settings.roles.create.form_controls.before') !!}

@@ -38,8 +39,7 @@ class="primary-button"

- - {!! view_render_event('krayin.settings.roles.create.card.access_control.before') !!} + {!! view_render_event('krayin.admin.settings.roles.create.card.access_control.before') !!}
@@ -57,14 +57,13 @@ class="primary-button"
- {!! view_render_event('krayin.settings.roles.create.card.access_control.after') !!} - + {!! view_render_event('krayin.admin.settings.roles.create.card.access_control.after') !!}
- {!! view_render_event('krayin.settings.roles.create.card.accordion.general.before') !!} + {!! view_render_event('krayin.admin.settings.roles.create.card.accordion.general.before') !!} @@ -116,16 +115,14 @@ class="primary-button" - {!! view_render_event('krayin.settings.roles.create.card.accordion.general.after') !!} - + {!! view_render_event('krayin.admin.settings.roles.create.card.accordion.general.after') !!}
- {!! view_render_event('krayin.settings.roles.create.create_form_controls.after') !!} - + {!! view_render_event('krayin.admin.settings.roles.create.create_form_controls.after') !!} - {!! view_render_event('krayin.settings.roles.create.after') !!} + {!! view_render_event('krayin.admin.settings.roles.create.after') !!} @pushOnce('scripts')