Status Check Added
This commit is contained in:
parent
c67f75986a
commit
6c3f106708
|
|
@ -1337,10 +1337,10 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => ':source في :name يتم استخدام هذا المورد',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'product-copied' => 'تم نسخ المنتج',
|
||||
'error-while-copying' => 'خطأ في نسخ المنتج',
|
||||
'product-can-not-be-copied' => 'لا يمكن نسخ منتجات الحجز',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'لا يمكن حذف القناة الافتراضية',
|
||||
'create-success' => 'إنشاء الاسم بنجاح:name',
|
||||
'update-success' => 'تحديث الاسم بنجاح :name ',
|
||||
|
|
|
|||
|
|
@ -1344,10 +1344,10 @@ return [
|
|||
'response' =>
|
||||
[
|
||||
'being-used' => 'Diese Ressource :name wird verwendet in :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'product-copied' => 'Das Produkt wurde kopiert',
|
||||
'error-while-copying' => 'Fehler beim Kopieren des Produkts',
|
||||
'product-can-not-be-copied' => 'Produkte vom Typ :type können nicht kopiert werden.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Der Standardkanal kann nicht gelöscht werden',
|
||||
'create-success' => ':name erfolgreich erstellt.',
|
||||
'update-success' => ':name erfolgreich aktualisiert.',
|
||||
|
|
|
|||
|
|
@ -1353,10 +1353,10 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'This resource :name is getting used in :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'product-copied' => 'The Product has been copied',
|
||||
'error-while-copying' => 'Something went wrong while trying to copy the product',
|
||||
'product-can-not-be-copied' => 'Products of type :type can not be copied',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Cannot delete the default channel',
|
||||
'create-success' => ':name created successfully.',
|
||||
'update-success' => ':name updated successfully.',
|
||||
|
|
|
|||
|
|
@ -1346,10 +1346,10 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Este recurso: :name está siendo usado en :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'product-copied' => 'El Producto ha sido copiado',
|
||||
'error-while-copying' => 'Se produjo un error al intentar copiar el producto',
|
||||
'product-can-not-be-copied' => 'Productos del tipo :type no se pueden copiar',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'No puede borrar el canal predeterminado',
|
||||
'create-success' => ':name :name creado con éxito.',
|
||||
'update-success' => ':name actualizado con éxito.',
|
||||
|
|
|
|||
|
|
@ -1337,7 +1337,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => ' مورد استفاده قرار می گیرد :source در :name این منبع',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'کانال پیش فرض حذف نمی شود',
|
||||
'create-success' => ' با موفقیت ایجاد شد :name',
|
||||
'update-success' => ' با موفقیت به روز شد :name',
|
||||
|
|
|
|||
|
|
@ -1360,10 +1360,10 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Cette ressource :name est utilisée dans :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'product-copied' => 'Le produit a été copié',
|
||||
'error-while-copying' => 'Une erreur s\'est produite lors de la tentative de copie du produit',
|
||||
'product-can-not-be-copied' => 'Les produits de type :type ne peuvent pas être copiés',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Impossible de supprimer la chaîne par défaut',
|
||||
'create-success' => ':name créé avec succès.',
|
||||
'update-success' => ':name mis à jour avec succès.',
|
||||
|
|
|
|||
|
|
@ -1340,7 +1340,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Questo resource :name is getting used in :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Non è possibile eliminare il canale di default',
|
||||
'create-success' => ':name creato con successo.',
|
||||
'update-success' => ':name aggiornato con successo.',
|
||||
|
|
|
|||
|
|
@ -1334,7 +1334,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Deze bron :name is wennen :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Kan het standaardkanaal niet verwijderen',
|
||||
'create-success' => ':name succesvol gemaakt.',
|
||||
'update-success' => ':name succesvol geupdatet.',
|
||||
|
|
|
|||
|
|
@ -1337,7 +1337,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Ten zasób :name est używana w :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Nie można usunąć domyślnego kanału',
|
||||
'create-success' => ':name została utworzona pomyślnie.',
|
||||
'update-success' => ':name została zaktualizowana pomyślnie.',
|
||||
|
|
|
|||
|
|
@ -1336,7 +1336,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => 'Este recurso :name está sendo usado em :source',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Não é possível excluir o canal padrão',
|
||||
'create-success' => ':name criado com sucesso.',
|
||||
'update-success' => ':name atualizaco com sucesso.',
|
||||
|
|
|
|||
|
|
@ -1324,7 +1324,7 @@ return [
|
|||
|
||||
'response' => [
|
||||
'being-used' => ':name isimli kaynak :source isimli kaynakta kullanılıyor.',
|
||||
'single-admin-present' => 'Cannot change the role if only one admin with all access is present.',
|
||||
'cannot-change' => 'Cannot change the :name.',
|
||||
'cannot-delete-default' => 'Varsayılan kanal silinemez.',
|
||||
'create-success' => ':name başarıyla oluşturuldu.',
|
||||
'update-success' => ':name başarıyla güncellendi.',
|
||||
|
|
|
|||
|
|
@ -124,46 +124,17 @@ class UserController extends Controller
|
|||
*/
|
||||
public function update(UserForm $request, $id)
|
||||
{
|
||||
$data = $request->all();
|
||||
$data = $this->prepareUserData($request, $id);
|
||||
|
||||
$user = $this->adminRepository->find($id);
|
||||
|
||||
/**
|
||||
* Is password changed.
|
||||
*/
|
||||
$isPasswordChanged = false;
|
||||
|
||||
if (! $data['password']) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$isPasswordChanged = true;
|
||||
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status update.
|
||||
*/
|
||||
$data['status'] = isset($data['status']) ? 1 : 0;
|
||||
|
||||
/**
|
||||
* Is user with `permission_type` all role changed.
|
||||
*/
|
||||
$isRoleChanged = $user->role->permission_type === 'all'
|
||||
&& isset($data['role_id'])
|
||||
&& (int) $data['role_id'] !== $user->role_id;
|
||||
|
||||
if ($isRoleChanged && $this->adminRepository->countAdminsWithAllAccess() === 1) {
|
||||
session()->flash('error', trans('admin::app.response.single-admin-present'));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
if ($data instanceof \Illuminate\Http\RedirectResponse) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
Event::dispatch('user.admin.update.before', $id);
|
||||
|
||||
$admin = $this->adminRepository->update($data, $id);
|
||||
|
||||
if ($isPasswordChanged) {
|
||||
if (isset($data['password']) && $data['password']) {
|
||||
Event::dispatch('user.admin.update-password', $admin);
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +153,7 @@ class UserController extends Controller
|
|||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$user = $this->adminRepository->findOrFail($id);
|
||||
$this->adminRepository->findOrFail($id);
|
||||
|
||||
if ($this->adminRepository->count() == 1) {
|
||||
session()->flash('error', trans('admin::app.response.last-delete-error', ['name' => 'Admin']));
|
||||
|
|
@ -255,4 +226,66 @@ class UserController extends Controller
|
|||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate user data.
|
||||
*
|
||||
* @param \Webkul\User\Http\Requests\UserForm $request
|
||||
* @param int $id
|
||||
* @return array|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function prepareUserData(UserForm $request, $id)
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
$user = $this->adminRepository->find($id);
|
||||
|
||||
/**
|
||||
* Password check.
|
||||
*/
|
||||
if (! $data['password']) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is user with `permission_type` all changed status.
|
||||
*/
|
||||
$data['status'] = isset($data['status']) ? 1 : 0;
|
||||
|
||||
$isStatusChangedToInactive = (int) $data['status'] === 0 && (int) $user->status === 1;
|
||||
|
||||
if ($isStatusChangedToInactive && $this->adminRepository->countAdminsWithAllAccessAndActiveStatus() === 1) {
|
||||
return $this->cannotChangeRedirectResponse('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is user with `permission_type` all role changed.
|
||||
*/
|
||||
$isRoleChanged = $user->role->permission_type === 'all'
|
||||
&& isset($data['role_id'])
|
||||
&& (int) $data['role_id'] !== $user->role_id;
|
||||
|
||||
if ($isRoleChanged && $this->adminRepository->countAdminsWithAllAccess() === 1) {
|
||||
return $this->cannotChangeRedirectResponse('role');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cannot change redirect response.
|
||||
*
|
||||
* @param string $columnName
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function cannotChangeRedirectResponse(string $columnName): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
session()->flash('error', trans('admin::app.response.cannot-change', [
|
||||
'name' => $columnName
|
||||
]));
|
||||
|
||||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||
|
||||
class UserForm extends FormRequest
|
||||
{
|
||||
protected $rules;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
|
|
@ -25,7 +23,7 @@ class UserForm extends FormRequest
|
|||
*/
|
||||
public function rules()
|
||||
{
|
||||
$this->rules = [
|
||||
$rules = [
|
||||
'name' => 'required',
|
||||
'email' => 'email|unique:admins,email',
|
||||
'password' => 'nullable',
|
||||
|
|
@ -35,9 +33,9 @@ class UserForm extends FormRequest
|
|||
];
|
||||
|
||||
if ($this->method() == 'PUT') {
|
||||
$this->rules['email'] = 'email|unique:admins,email,' . $this->route('id');
|
||||
$rules['email'] = 'email|unique:admins,email,' . $this->route('id');
|
||||
}
|
||||
|
||||
return $this->rules;
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,22 @@ class AdminRepository extends Repository
|
|||
{
|
||||
return $this->getModel()
|
||||
->leftJoin('roles', 'admins.role_id', '=', 'roles.id')
|
||||
->where(["roles.permission_type" => "all"])
|
||||
->where('roles.permission_type', 'all')
|
||||
->get()
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count admins with all access and active status.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countAdminsWithAllAccessAndActiveStatus(): int
|
||||
{
|
||||
return $this->getModel()
|
||||
->leftJoin('roles', 'admins.role_id', '=', 'roles.id')
|
||||
->where('admins.status', 1)
|
||||
->where('roles.permission_type', 'all')
|
||||
->get()
|
||||
->count();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue