Skip to content

Commit 91bd036

Browse files
committed
issue #2141 has been fixed.
1 parent b03e64c commit 91bd036

File tree

3 files changed

+69
-63
lines changed

3 files changed

+69
-63
lines changed

packages/Webkul/Admin/src/Http/Controllers/Settings/UserController.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\JsonResponse;
66
use Illuminate\Http\Resources\Json\JsonResource;
7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Facades\Event;
89
use Illuminate\Support\Facades\Mail;
910
use Illuminate\View\View;
@@ -58,25 +59,24 @@ public function store(): View|JsonResponse
5859
'password' => 'nullable',
5960
'confirm_password' => 'nullable|required_with:password|same:password',
6061
'role_id' => 'required',
62+
'status' => 'boolean|in:0,1',
63+
'view_permission' => 'string|in:global,group,individual',
6164
]);
6265

6366
$data = request()->all();
6467

65-
if (isset($data['password']) && $data['password']) {
68+
if (
69+
isset($data['password'])
70+
&& $data['password']
71+
) {
6672
$data['password'] = bcrypt($data['password']);
6773
}
6874

69-
$data['status'] = $data['status'] ? 1 : 0;
70-
7175
Event::dispatch('settings.user.create.before');
7276

7377
$admin = $this->userRepository->create($data);
7478

75-
$admin->view_permission = $data['view_permission'];
76-
77-
$admin->save();
78-
79-
$admin->groups()->sync(request('groups') ?? []);
79+
$admin->groups()->sync($data['groups'] ?? []);
8080

8181
try {
8282
Mail::queue(new UserCreatedNotification($admin));
@@ -110,34 +110,34 @@ public function edit(int $id): View|JsonResponse
110110
public function update(int $id): JsonResponse
111111
{
112112
$this->validate(request(), [
113-
'email' => 'required|email|unique:users,email,'.$id,
114-
'name' => 'required',
115-
'password' => 'nullable',
113+
'email' => 'required|email|unique:users,email,' . $id,
114+
'name' => 'required|string',
115+
'password' => 'nullable|string|min:6',
116116
'confirm_password' => 'nullable|required_with:password|same:password',
117-
'role_id' => 'required',
117+
'role_id' => 'required|integer|exists:roles,id',
118+
'status' => 'nullable|boolean|in:0,1',
119+
'view_permission' => 'required|string|in:global,group,individual',
118120
]);
119121

120122
$data = request()->all();
121123

122-
if (! $data['password']) {
123-
unset($data['password'], $data['confirm_password']);
124+
if (empty($data['password'])) {
125+
$data = Arr::except($data, ['password', 'confirm_password']);
124126
} else {
125127
$data['password'] = bcrypt($data['password']);
126128
}
127129

128-
if (auth()->guard('user')->user()->id != $id) {
129-
$data['status'] = $data['status'] ? 1 : 0;
130+
$authUser = auth()->guard('user')->user();
131+
132+
if ($authUser->id == $id) {
133+
$data['status'] = true;
130134
}
131135

132136
Event::dispatch('settings.user.update.before', $id);
133137

134138
$admin = $this->userRepository->update($data, $id);
135139

136-
$admin->view_permission = $data['view_permission'];
137-
138-
$admin->save();
139-
140-
$admin->groups()->sync(request()->input('groups') ?? []);
140+
$admin->groups()->sync($data['groups'] ?? []);
141141

142142
Event::dispatch('settings.user.update.after', $admin);
143143

@@ -147,6 +147,7 @@ public function update(int $id): JsonResponse
147147
]);
148148
}
149149

150+
150151
/**
151152
* Search user results.
152153
*/

packages/Webkul/Admin/src/Resources/views/settings/users/index.blade.php

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<div class="flex items-center gap-x-2.5">
1818
{!! view_render_event('admin.settings.users.index.create_button.before') !!}
19-
19+
2020
<!-- Create button for User -->
2121
@if (bouncer()->hasPermission('settings.user.users.create'))
2222
<div class="flex items-center gap-x-2.5">
@@ -46,7 +46,7 @@ class="primary-button"
4646
id="users-settings-template"
4747
>
4848
{!! view_render_event('admin.settings.users.index.datagrid.before') !!}
49-
49+
5050
<!-- Datagrid -->
5151
<x-admin::datagrid
5252
:src="route('admin.settings.users.index')"
@@ -63,7 +63,7 @@ class="primary-button"
6363
<template v-if="isLoading">
6464
<x-admin::shimmer.datagrid.table.body />
6565
</template>
66-
66+
6767
<template v-else>
6868
<div
6969
v-for="record in available.records"
@@ -86,10 +86,10 @@ class="icon-checkbox-outline peer-checked:icon-checkbox-select cursor-pointer ro
8686
:for="`mass_action_select_record_${record.id}`"
8787
></label>
8888
</div>
89-
89+
9090
<!-- Users Id -->
9191
<p>@{{ record.id }}</p>
92-
92+
9393
<!-- Users Name and Profile -->
9494
<div class="flex items-center gap-2.5">
9595
<template v-if="record.name.image">
@@ -118,7 +118,7 @@ class="flex h-9 w-9 items-center justify-center rounded-full"
118118
>
119119
@{{ record.status == 1 ? '@lang('admin::app.settings.users.index.active')' : '@lang('admin::app.settings.users.index.inactive')' }}
120120
</span>
121-
121+
122122
<!-- Users Creation Date -->
123123
<p>@{{ record.created_at }}</p>
124124
@@ -131,7 +131,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
131131
>
132132
</span>
133133
</a>
134-
134+
135135
<a @click="performAction(record.actions.find(action => action.index === 'delete'))">
136136
<span
137137
:class="record.actions.find(action => action.index === 'delete')?.icon"
@@ -160,7 +160,7 @@ class="hidden border-b px-4 py-4 text-black dark:border-gray-800 dark:text-gray-
160160
class="peer hidden"
161161
v-model="applied.massActions.indices"
162162
>
163-
163+
164164
<span class="icon-checkbox-outline peer-checked:icon-checkbox-select cursor-pointer rounded-md text-2xl text-gray-500 peer-checked:text-brandColor">
165165
</span>
166166
</label>
@@ -179,7 +179,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
179179
>
180180
</span>
181181
</a>
182-
182+
183183
<a @click="performAction(record.actions.find(action => action.index === 'delete'))">
184184
<span
185185
:class="record.actions.find(action => action.index === 'delete')?.icon"
@@ -204,15 +204,15 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
204204
</template>
205205
</template>
206206
</x-admin::datagrid>
207-
207+
208208
{!! view_render_event('admin.users.index.datagrid.after') !!}
209-
209+
210210
<x-admin::form
211211
v-slot="{ meta, values, errors, handleSubmit }"
212212
as="div"
213213
ref="modalForm"
214214
>
215-
<form
215+
<form
216216
@submit="handleSubmit($event, updateOrCreate)"
217217
ref="userForm"
218218
>
@@ -222,10 +222,10 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
222222
<!-- Modal Header -->
223223
<x-slot:header>
224224
<p class="text-lg font-bold text-gray-800 dark:text-white">
225-
@{{
225+
@{{
226226
selectedType == 'create'
227227
? "@lang('admin::app.settings.users.index.create.title')"
228-
: "@lang('admin::app.settings.users.index.edit.title')"
228+
: "@lang('admin::app.settings.users.index.edit.title')"
229229
}}
230230
</p>
231231
</x-slot>
@@ -328,7 +328,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
328328
{!! view_render_event('admin.settings.users.index.form.password.after') !!}
329329
330330
{!! view_render_event('admin.settings.users.index.form.role_id.before') !!}
331-
331+
332332
<div class="flex gap-4">
333333
<!-- Role -->
334334
<x-admin::form.control-group class="flex-1">
@@ -347,11 +347,11 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
347347
v-for="role in roles"
348348
:key="role.id"
349349
:value="role.id"
350-
>
351-
@{{ role.name }}
350+
>
351+
@{{ role.name }}
352352
</option>
353353
</x-admin::form.control-group.control>
354-
354+
355355
<x-admin::form.control-group.error control-name="role_id" />
356356
</x-admin::form.control-group>
357357
@@ -372,7 +372,7 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
372372
<option value="global" selected>
373373
@lang('admin::app.settings.users.index.create.global')
374374
</option>
375-
375+
376376
<option value="group">
377377
@lang('admin::app.settings.users.index.create.group')
378378
</option>
@@ -392,13 +392,12 @@ class="cursor-pointer rounded-md p-1.5 text-2xl transition-all hover:bg-gray-200
392392
393393
<!-- Group -->
394394
<x-admin::form.control-group>
395-
<x-admin::form.control-group.label class="required">
395+
<x-admin::form.control-group.label>
396396
@lang('admin::app.settings.users.index.create.group')
397397
</x-admin::form.control-group.label>
398398
399399
<v-field
400400
name="groups[]"
401-
rules="required"
402401
label="@lang('admin::app.settings.users.index.create.group')"
403402
multiple
404403
v-model="user.groups"
@@ -446,7 +445,7 @@ class="flex min-h-[39px] w-full rounded-md border px-3 py-2 text-sm text-gray-60
446445
::checked="parseInt(user.status || 0)"
447446
/>
448447
</x-admin::form.control-group>
449-
448+
450449
{!! view_render_event('admin.settings.users.index.form.status.after') !!}
451450
</x-slot>
452451
@@ -475,7 +474,7 @@ class="primary-button justify-center"
475474
<script type="module">
476475
app.component('v-users-settings', {
477476
template: '#users-settings-template',
478-
477+
479478
data() {
480479
return {
481480
isProcessing: false,
@@ -491,23 +490,23 @@ class="primary-button justify-center"
491490
computed: {
492491
gridsCount() {
493492
let count = this.$refs.datagrid.available.columns.length;
494-
493+
495494
if (this.$refs.datagrid.available.actions.length) {
496495
++count;
497496
}
498-
497+
499498
if (this.$refs.datagrid.available.massActions.length) {
500499
++count;
501500
}
502-
501+
503502
return count;
504503
},
505504
506505
selectedType() {
507506
return this.user.id ? 'edit' : 'create';
508507
},
509508
},
510-
509+
511510
methods: {
512511
openModal() {
513512
this.user = {
@@ -516,36 +515,41 @@ class="primary-button justify-center"
516515
517516
this.$refs.userUpdateAndCreateModal.toggle();
518517
},
519-
518+
520519
updateOrCreate(params, {resetForm, setErrors}) {
521520
const userForm = new FormData(this.$refs.userForm);
522521
523522
userForm.append('_method', params.id ? 'put' : 'post');
524523
525524
this.isProcessing = true;
526525
527-
this.$axios.post(params.id ? `{{ route('admin.settings.users.update', '') }}/${params.id}` : "{{ route('admin.settings.users.store') }}", userForm).then(response => {
528-
this.isProcessing = false;
526+
this.$axios.post(
527+
params.id
528+
? `{{ route('admin.settings.users.update', '') }}/${params.id}`
529+
: "{{ route('admin.settings.users.store') }}", userForm
530+
)
531+
.then(response => {
532+
this.isProcessing = false;
529533
530-
this.$refs.userUpdateAndCreateModal.toggle();
534+
this.$refs.userUpdateAndCreateModal.toggle();
531535
532-
this.$emitter.emit('add-flash', { type: 'success', message: response.data.message });
536+
this.$emitter.emit('add-flash', { type: 'success', message: response.data.message });
533537
534-
this.$refs.datagrid.get();
538+
this.$refs.datagrid.get();
535539
536-
resetForm();
537-
}).catch(error => {
538-
this.isProcessing = false;
540+
resetForm();
541+
}).catch(error => {
542+
this.isProcessing = false;
539543
540-
if (error.response.status === 422) {
541-
setErrors(error.response.data.errors);
542-
}
543-
});
544+
if (error.response.status === 422) {
545+
setErrors(error.response.data.errors);
546+
}
547+
});
544548
},
545-
549+
546550
editModal(url) {
547551
this.$axios.get(url)
548-
.then(response => {
552+
.then(response => {
549553
this.user = response.data.data;
550554
551555
this.user.groups = this.user.groups.map(group => group.id);

packages/Webkul/User/src/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class User extends Authenticatable implements UserContract
2525
'api_token',
2626
'role_id',
2727
'status',
28+
'view_permission'
2829
];
2930

3031
/**

0 commit comments

Comments
 (0)